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