You are here

class PreUpdateEventArgs in Plug 7

Class that holds event arguments for a preUpdate event.

@author Guilherme Blanco <guilehrmeblanco@hotmail.com> @author Roman Borschel <roman@code-factory.org> @author Benjamin Eberlei <kontakt@beberlei.de> @since 2.2

Hierarchy

Expanded class hierarchy of PreUpdateEventArgs

File

lib/doctrine/common/lib/Doctrine/Common/Persistence/Event/PreUpdateEventArgs.php, line 32

Namespace

Doctrine\Common\Persistence\Event
View source
class PreUpdateEventArgs extends LifecycleEventArgs {

  /**
   * @var array
   */
  private $entityChangeSet;

  /**
   * Constructor.
   *
   * @param object        $entity
   * @param ObjectManager $objectManager
   * @param array         $changeSet
   */
  public function __construct($entity, ObjectManager $objectManager, array &$changeSet) {
    parent::__construct($entity, $objectManager);
    $this->entityChangeSet =& $changeSet;
  }

  /**
   * Retrieves the entity changeset.
   *
   * @return array
   */
  public function getEntityChangeSet() {
    return $this->entityChangeSet;
  }

  /**
   * Checks if field has a changeset.
   *
   * @param string $field
   *
   * @return boolean
   */
  public function hasChangedField($field) {
    return isset($this->entityChangeSet[$field]);
  }

  /**
   * Gets the old value of the changeset of the changed field.
   *
   * @param string $field
   *
   * @return mixed
   */
  public function getOldValue($field) {
    $this
      ->assertValidField($field);
    return $this->entityChangeSet[$field][0];
  }

  /**
   * Gets the new value of the changeset of the changed field.
   *
   * @param string $field
   *
   * @return mixed
   */
  public function getNewValue($field) {
    $this
      ->assertValidField($field);
    return $this->entityChangeSet[$field][1];
  }

  /**
   * Sets the new value of this field.
   *
   * @param string $field
   * @param mixed  $value
   *
   * @return void
   */
  public function setNewValue($field, $value) {
    $this
      ->assertValidField($field);
    $this->entityChangeSet[$field][1] = $value;
  }

  /**
   * Asserts the field exists in changeset.
   *
   * @param string $field
   *
   * @return void
   *
   * @throws \InvalidArgumentException
   */
  private function assertValidField($field) {
    if (!isset($this->entityChangeSet[$field])) {
      throw new \InvalidArgumentException(sprintf('Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.', $field, get_class($this
        ->getEntity())));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventArgs::$_emptyEventArgsInstance private static property Single instance of EventArgs.
EventArgs::getEmptyInstance public static function Gets the single, empty and immutable EventArgs instance.
LifecycleEventArgs::$object private property
LifecycleEventArgs::$objectManager private property
LifecycleEventArgs::getEntity public function Retrieves the associated entity.
LifecycleEventArgs::getObject public function Retrieves the associated object.
LifecycleEventArgs::getObjectManager public function Retrieves the associated ObjectManager.
PreUpdateEventArgs::$entityChangeSet private property
PreUpdateEventArgs::assertValidField private function Asserts the field exists in changeset.
PreUpdateEventArgs::getEntityChangeSet public function Retrieves the entity changeset.
PreUpdateEventArgs::getNewValue public function Gets the new value of the changeset of the changed field.
PreUpdateEventArgs::getOldValue public function Gets the old value of the changeset of the changed field.
PreUpdateEventArgs::hasChangedField public function Checks if field has a changeset.
PreUpdateEventArgs::setNewValue public function Sets the new value of this field.
PreUpdateEventArgs::__construct public function Constructor. Overrides LifecycleEventArgs::__construct