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\EventArgs,
23 Doctrine\Common\Persistence\ObjectManager;
26 * Class that holds event arguments for a preUpdate event.
28 * @author Guilherme Blanco <guilehrmeblanco@hotmail.com>
29 * @author Roman Borschel <roman@code-factory.org>
30 * @author Benjamin Eberlei <kontakt@beberlei.de>
33 class PreUpdateEventArgs extends LifecycleEventArgs
38 private $entityChangeSet;
43 * @param object $entity
44 * @param ObjectManager $objectManager
45 * @param array $changeSet
47 public function __construct($entity, ObjectManager $objectManager, array &$changeSet)
49 parent::__construct($entity, $objectManager);
51 $this->entityChangeSet = &$changeSet;
55 * Retrieve entity changeset.
59 public function getEntityChangeSet()
61 return $this->entityChangeSet;
65 * Check if field has a changeset.
67 * @param string $field
71 public function hasChangedField($field)
73 return isset($this->entityChangeSet[$field]);
77 * Get the old value of the changeset of the changed field.
79 * @param string $field
82 public function getOldValue($field)
84 $this->assertValidField($field);
86 return $this->entityChangeSet[$field][0];
90 * Get the new value of the changeset of the changed field.
92 * @param string $field
95 public function getNewValue($field)
97 $this->assertValidField($field);
99 return $this->entityChangeSet[$field][1];
103 * Set the new value of this field.
105 * @param string $field
106 * @param mixed $value
108 public function setNewValue($field, $value)
110 $this->assertValidField($field);
112 $this->entityChangeSet[$field][1] = $value;
116 * Assert the field exists in changeset.
118 * @param string $field
120 * @throws \InvalidArgumentException
122 private function assertValidField($field)
124 if ( ! isset($this->entityChangeSet[$field])) {
125 throw new \InvalidArgumentException(sprintf(
126 'Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.',
128 get_class($this->getEntity())