annotate vendor/doctrine/common/lib/Doctrine/Common/Persistence/Event/PreUpdateEventArgs.php @ 19:fa3358dc1485 tip

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