class PreUpdateEventArgs

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

drupal/core/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Event/PreUpdateEventArgs.php, line 33

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;
  }

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

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

  /**
   * Get 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];
  }

  /**
   * Get 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];
  }

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

  /**
   * Assert the field exists in changeset.
   *
   * @param string $field
   *
   * @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
EventArgs::getEmptyInstance public static function Gets the single, empty and immutable EventArgs instance.
LifecycleEventArgs::$entity private property
LifecycleEventArgs::$objectManager private property
LifecycleEventArgs::getEntity public function Retrieve associated Entity.
LifecycleEventArgs::getObjectManager public function Retrieve associated ObjectManager.
PreUpdateEventArgs::$entityChangeSet private property
PreUpdateEventArgs::assertValidField private function Assert the field exists in changeset.
PreUpdateEventArgs::getEntityChangeSet public function Retrieve entity changeset.
PreUpdateEventArgs::getNewValue public function Get the new value of the changeset of the changed field.
PreUpdateEventArgs::getOldValue public function Get the old value of the changeset of the changed field.
PreUpdateEventArgs::hasChangedField public function Check if field has a changeset.
PreUpdateEventArgs::setNewValue public function Set the new value of this field.
PreUpdateEventArgs::__construct public function Constructor. Overrides LifecycleEventArgs::__construct