diff options
| author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
| commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
| tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/orm/src/OptimisticLockException.php | |
| parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
| download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.gz AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.tar.bz2 AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip | |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/orm/src/OptimisticLockException.php')
| -rw-r--r-- | vendor/doctrine/orm/src/OptimisticLockException.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/OptimisticLockException.php b/vendor/doctrine/orm/src/OptimisticLockException.php new file mode 100644 index 0000000..f84e134 --- /dev/null +++ b/vendor/doctrine/orm/src/OptimisticLockException.php | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM; | ||
| 6 | |||
| 7 | use DateTimeInterface; | ||
| 8 | use Doctrine\ORM\Exception\ORMException; | ||
| 9 | use Exception; | ||
| 10 | use Throwable; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * An OptimisticLockException is thrown when a version check on an object | ||
| 14 | * that uses optimistic locking through a version field fails. | ||
| 15 | */ | ||
| 16 | class OptimisticLockException extends Exception implements ORMException | ||
| 17 | { | ||
| 18 | public function __construct( | ||
| 19 | string $msg, | ||
| 20 | private readonly object|string|null $entity, | ||
| 21 | Throwable|null $previous = null, | ||
| 22 | ) { | ||
| 23 | parent::__construct($msg, 0, $previous); | ||
| 24 | } | ||
| 25 | |||
| 26 | /** | ||
| 27 | * Gets the entity that caused the exception. | ||
| 28 | */ | ||
| 29 | public function getEntity(): object|string|null | ||
| 30 | { | ||
| 31 | return $this->entity; | ||
| 32 | } | ||
| 33 | |||
| 34 | /** @param object|class-string $entity */ | ||
| 35 | public static function lockFailed(object|string $entity): self | ||
| 36 | { | ||
| 37 | return new self('The optimistic lock on an entity failed.', $entity); | ||
| 38 | } | ||
| 39 | |||
| 40 | public static function lockFailedVersionMismatch( | ||
| 41 | object $entity, | ||
| 42 | int|string|DateTimeInterface $expectedLockVersion, | ||
| 43 | int|string|DateTimeInterface $actualLockVersion, | ||
| 44 | ): self { | ||
| 45 | $expectedLockVersion = $expectedLockVersion instanceof DateTimeInterface ? $expectedLockVersion->getTimestamp() : $expectedLockVersion; | ||
| 46 | $actualLockVersion = $actualLockVersion instanceof DateTimeInterface ? $actualLockVersion->getTimestamp() : $actualLockVersion; | ||
| 47 | |||
| 48 | return new self('The optimistic lock failed, version ' . $expectedLockVersion . ' was expected, but is actually ' . $actualLockVersion, $entity); | ||
| 49 | } | ||
| 50 | |||
| 51 | public static function notVersioned(string $entityName): self | ||
| 52 | { | ||
| 53 | return new self('Cannot obtain optimistic lock on unversioned entity ' . $entityName, null); | ||
| 54 | } | ||
| 55 | } | ||
