comparison vendor/doctrine/common/lib/Doctrine/Common/Persistence/Event/PreUpdateEventArgs.php @ 0:c75dbcec494b

Initial commit from drush-created site
author Chris Cannam
date Thu, 05 Jul 2018 14:24:15 +0000
parents
children 5311817fb629
comparison
equal deleted inserted replaced
-1:000000000000 0:c75dbcec494b
1 <?php
2 /*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 *
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the MIT license. For more information, see
17 * <http://www.doctrine-project.org>.
18 */
19
20 namespace Doctrine\Common\Persistence\Event;
21
22 use Doctrine\Common\Persistence\ObjectManager;
23
24 /**
25 * Class that holds event arguments for a preUpdate event.
26 *
27 * @author Guilherme Blanco <guilehrmeblanco@hotmail.com>
28 * @author Roman Borschel <roman@code-factory.org>
29 * @author Benjamin Eberlei <kontakt@beberlei.de>
30 * @since 2.2
31 */
32 class PreUpdateEventArgs extends LifecycleEventArgs
33 {
34 /**
35 * @var array
36 */
37 private $entityChangeSet;
38
39 /**
40 * Constructor.
41 *
42 * @param object $entity
43 * @param ObjectManager $objectManager
44 * @param array $changeSet
45 */
46 public function __construct($entity, ObjectManager $objectManager, array &$changeSet)
47 {
48 parent::__construct($entity, $objectManager);
49
50 $this->entityChangeSet = &$changeSet;
51 }
52
53 /**
54 * Retrieves the entity changeset.
55 *
56 * @return array
57 */
58 public function getEntityChangeSet()
59 {
60 return $this->entityChangeSet;
61 }
62
63 /**
64 * Checks if field has a changeset.
65 *
66 * @param string $field
67 *
68 * @return boolean
69 */
70 public function hasChangedField($field)
71 {
72 return isset($this->entityChangeSet[$field]);
73 }
74
75 /**
76 * Gets the old value of the changeset of the changed field.
77 *
78 * @param string $field
79 *
80 * @return mixed
81 */
82 public function getOldValue($field)
83 {
84 $this->assertValidField($field);
85
86 return $this->entityChangeSet[$field][0];
87 }
88
89 /**
90 * Gets the new value of the changeset of the changed field.
91 *
92 * @param string $field
93 *
94 * @return mixed
95 */
96 public function getNewValue($field)
97 {
98 $this->assertValidField($field);
99
100 return $this->entityChangeSet[$field][1];
101 }
102
103 /**
104 * Sets the new value of this field.
105 *
106 * @param string $field
107 * @param mixed $value
108 *
109 * @return void
110 */
111 public function setNewValue($field, $value)
112 {
113 $this->assertValidField($field);
114
115 $this->entityChangeSet[$field][1] = $value;
116 }
117
118 /**
119 * Asserts the field exists in changeset.
120 *
121 * @param string $field
122 *
123 * @return void
124 *
125 * @throws \InvalidArgumentException
126 */
127 private function assertValidField($field)
128 {
129 if ( ! isset($this->entityChangeSet[$field])) {
130 throw new \InvalidArgumentException(sprintf(
131 'Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.',
132 $field,
133 get_class($this->getEntity())
134 ));
135 }
136 }
137 }