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
Expanded class hierarchy of PreUpdateEventArgs
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())));
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EventArgs:: |
private static | property | ||
EventArgs:: |
public static | function | Gets the single, empty and immutable EventArgs instance. | |
LifecycleEventArgs:: |
private | property | ||
LifecycleEventArgs:: |
private | property | ||
LifecycleEventArgs:: |
public | function | Retrieve associated Entity. | |
LifecycleEventArgs:: |
public | function | Retrieve associated ObjectManager. | |
PreUpdateEventArgs:: |
private | property | ||
PreUpdateEventArgs:: |
private | function | Assert the field exists in changeset. | |
PreUpdateEventArgs:: |
public | function | Retrieve entity changeset. | |
PreUpdateEventArgs:: |
public | function | Get the new value of the changeset of the changed field. | |
PreUpdateEventArgs:: |
public | function | Get the old value of the changeset of the changed field. | |
PreUpdateEventArgs:: |
public | function | Check if field has a changeset. | |
PreUpdateEventArgs:: |
public | function | Set the new value of this field. | |
PreUpdateEventArgs:: |
public | function |
Constructor. Overrides LifecycleEventArgs:: |