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\ORM\Event;
22 use Doctrine\Common\EventArgs,
23 Doctrine\ORM\EntityManager;
26 * Class that holds event arguments for a preInsert/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 \Doctrine\ORM\EntityManager $em
45 * @param array $changeSet
47 public function __construct($entity, EntityManager $em, array &$changeSet)
49 parent::__construct($entity, $em);
51 $this->entityChangeSet = &$changeSet;
55 * Retrieve entity changeset.
59 public function getEntityChangeSet()
61 return $this->entityChangeSet;
65 * Check if field has a changeset.
69 public function hasChangedField($field)
71 return isset($this->entityChangeSet[$field]);
75 * Get the old value of the changeset of the changed field.
77 * @param string $field
80 public function getOldValue($field)
82 $this->assertValidField($field);
84 return $this->entityChangeSet[$field][0];
88 * Get the new value of the changeset of the changed field.
90 * @param string $field
93 public function getNewValue($field)
95 $this->assertValidField($field);
97 return $this->entityChangeSet[$field][1];
101 * Set the new value of this field.
103 * @param string $field
104 * @param mixed $value
106 public function setNewValue($field, $value)
108 $this->assertValidField($field);
110 $this->entityChangeSet[$field][1] = $value;
114 * Assert the field exists in changeset.
116 * @param string $field
118 private function assertValidField($field)
120 if ( ! isset($this->entityChangeSet[$field])) {
121 throw new \InvalidArgumentException(sprintf(
122 'Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.',
124 get_class($this->getEntity())