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.
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>.
20 namespace Doctrine\Common\Persistence\Event
;
22 use Doctrine\Common\Persistence\ObjectManager
;
25 * Class that holds event arguments for a preUpdate event.
27 * @author Guilherme Blanco <guilehrmeblanco@hotmail.com>
28 * @author Roman Borschel <roman@code-factory.org>
29 * @author Benjamin Eberlei <kontakt@beberlei.de>
32 class PreUpdateEventArgs
extends LifecycleEventArgs
37 private $entityChangeSet;
42 * @param object $entity
43 * @param ObjectManager $objectManager
44 * @param array $changeSet
46 public function __construct($entity, ObjectManager
$objectManager, array &$changeSet)
48 parent
::__construct($entity, $objectManager);
50 $this->entityChangeSet
= &$changeSet;
54 * Retrieves the entity changeset.
58 public function getEntityChangeSet()
60 return $this->entityChangeSet
;
64 * Checks if field has a changeset.
66 * @param string $field
70 public function hasChangedField($field)
72 return isset($this->entityChangeSet
[$field]);
76 * Gets the old value of the changeset of the changed field.
78 * @param string $field
82 public function getOldValue($field)
84 $this->assertValidField($field);
86 return $this->entityChangeSet
[$field][0];
90 * Gets the new value of the changeset of the changed field.
92 * @param string $field
96 public function getNewValue($field)
98 $this->assertValidField($field);
100 return $this->entityChangeSet
[$field][1];
104 * Sets the new value of this field.
106 * @param string $field
107 * @param mixed $value
111 public function setNewValue($field, $value)
113 $this->assertValidField($field);
115 $this->entityChangeSet
[$field][1] = $value;
119 * Asserts the field exists in changeset.
121 * @param string $field
125 * @throws \InvalidArgumentException
127 private function assertValidField($field)
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.',
133 get_class($this->getObject())