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/Event/PreUpdateEventArgs.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/Event/PreUpdateEventArgs.php')
| -rw-r--r-- | vendor/doctrine/orm/src/Event/PreUpdateEventArgs.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/vendor/doctrine/orm/src/Event/PreUpdateEventArgs.php b/vendor/doctrine/orm/src/Event/PreUpdateEventArgs.php new file mode 100644 index 0000000..090487b --- /dev/null +++ b/vendor/doctrine/orm/src/Event/PreUpdateEventArgs.php | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | declare(strict_types=1); | ||
| 4 | |||
| 5 | namespace Doctrine\ORM\Event; | ||
| 6 | |||
| 7 | use Doctrine\ORM\EntityManagerInterface; | ||
| 8 | use Doctrine\ORM\PersistentCollection; | ||
| 9 | use Doctrine\Persistence\Event\LifecycleEventArgs; | ||
| 10 | use InvalidArgumentException; | ||
| 11 | |||
| 12 | use function get_debug_type; | ||
| 13 | use function sprintf; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * Class that holds event arguments for a preUpdate event. | ||
| 17 | * | ||
| 18 | * @extends LifecycleEventArgs<EntityManagerInterface> | ||
| 19 | */ | ||
| 20 | class PreUpdateEventArgs extends LifecycleEventArgs | ||
| 21 | { | ||
| 22 | /** @var array<string, array{mixed, mixed}|PersistentCollection> */ | ||
| 23 | private array $entityChangeSet; | ||
| 24 | |||
| 25 | /** | ||
| 26 | * @param mixed[][] $changeSet | ||
| 27 | * @psalm-param array<string, array{mixed, mixed}|PersistentCollection> $changeSet | ||
| 28 | */ | ||
| 29 | public function __construct(object $entity, EntityManagerInterface $em, array &$changeSet) | ||
| 30 | { | ||
| 31 | parent::__construct($entity, $em); | ||
| 32 | |||
| 33 | $this->entityChangeSet = &$changeSet; | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Retrieves entity changeset. | ||
| 38 | * | ||
| 39 | * @return mixed[][] | ||
| 40 | * @psalm-return array<string, array{mixed, mixed}|PersistentCollection> | ||
| 41 | */ | ||
| 42 | public function getEntityChangeSet(): array | ||
| 43 | { | ||
| 44 | return $this->entityChangeSet; | ||
| 45 | } | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Checks if field has a changeset. | ||
| 49 | */ | ||
| 50 | public function hasChangedField(string $field): bool | ||
| 51 | { | ||
| 52 | return isset($this->entityChangeSet[$field]); | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Gets the old value of the changeset of the changed field. | ||
| 57 | */ | ||
| 58 | public function getOldValue(string $field): mixed | ||
| 59 | { | ||
| 60 | $this->assertValidField($field); | ||
| 61 | |||
| 62 | return $this->entityChangeSet[$field][0]; | ||
| 63 | } | ||
| 64 | |||
| 65 | /** | ||
| 66 | * Gets the new value of the changeset of the changed field. | ||
| 67 | */ | ||
| 68 | public function getNewValue(string $field): mixed | ||
| 69 | { | ||
| 70 | $this->assertValidField($field); | ||
| 71 | |||
| 72 | return $this->entityChangeSet[$field][1]; | ||
| 73 | } | ||
| 74 | |||
| 75 | /** | ||
| 76 | * Sets the new value of this field. | ||
| 77 | */ | ||
| 78 | public function setNewValue(string $field, mixed $value): void | ||
| 79 | { | ||
| 80 | $this->assertValidField($field); | ||
| 81 | |||
| 82 | $this->entityChangeSet[$field][1] = $value; | ||
| 83 | } | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Asserts the field exists in changeset. | ||
| 87 | * | ||
| 88 | * @throws InvalidArgumentException | ||
| 89 | */ | ||
| 90 | private function assertValidField(string $field): void | ||
| 91 | { | ||
| 92 | if (! isset($this->entityChangeSet[$field])) { | ||
| 93 | throw new InvalidArgumentException(sprintf( | ||
| 94 | 'Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.', | ||
| 95 | $field, | ||
| 96 | get_debug_type($this->getObject()), | ||
| 97 | )); | ||
| 98 | } | ||
| 99 | } | ||
| 100 | } | ||
