forked from doctrine/mongodb-odm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLockException.php
53 lines (43 loc) · 1.43 KB
/
LockException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace Doctrine\ODM\MongoDB;
/**
* LockException
*/
class LockException extends MongoDBException
{
/** @var object|null */
private $document;
public function __construct(string $msg, ?object $document = null)
{
parent::__construct($msg);
$this->document = $document;
}
/**
* Gets the document that caused the exception.
*/
public function getDocument() : ?object
{
return $this->document;
}
public static function lockFailed(?object $document) : self
{
return new self('A lock failed on a document.', $document);
}
public static function lockFailedVersionMissmatch(object $document, int $expectedLockVersion, int $actualLockVersion) : self
{
return new self('The optimistic lock failed, version ' . $expectedLockVersion . ' was expected, but is actually ' . $actualLockVersion, $document);
}
public static function notVersioned(string $documentName) : self
{
return new self('Document ' . $documentName . ' is not versioned.');
}
public static function invalidLockFieldType(string $type) : self
{
return new self('Invalid lock field type ' . $type . '. Lock field must be int.');
}
public static function invalidVersionFieldType(string $type) : self
{
return new self('Invalid version field type ' . $type . '. Version field must be int or date.');
}
}