mailpoet
/
vendor-prefixed
/
doctrine
/
persistence
/
src
/
Persistence
/
Event
/
PreUpdateEventArgs.php
LifecycleEventArgs.php
9 months ago
LoadClassMetadataEventArgs.php
9 months ago
ManagerEventArgs.php
9 months ago
OnClearEventArgs.php
9 months ago
PreUpdateEventArgs.php
9 months ago
index.php
3 years ago
PreUpdateEventArgs.php
47 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\Persistence\Event; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\Persistence\ObjectManager; |
| 6 | use InvalidArgumentException; |
| 7 | use function get_class; |
| 8 | use function sprintf; |
| 9 | class PreUpdateEventArgs extends LifecycleEventArgs |
| 10 | { |
| 11 | private $entityChangeSet; |
| 12 | public function __construct(object $entity, ObjectManager $objectManager, array &$changeSet) |
| 13 | { |
| 14 | parent::__construct($entity, $objectManager); |
| 15 | $this->entityChangeSet =& $changeSet; |
| 16 | } |
| 17 | public function getEntityChangeSet() |
| 18 | { |
| 19 | return $this->entityChangeSet; |
| 20 | } |
| 21 | public function hasChangedField(string $field) |
| 22 | { |
| 23 | return isset($this->entityChangeSet[$field]); |
| 24 | } |
| 25 | public function getOldValue(string $field) |
| 26 | { |
| 27 | $this->assertValidField($field); |
| 28 | return $this->entityChangeSet[$field][0]; |
| 29 | } |
| 30 | public function getNewValue(string $field) |
| 31 | { |
| 32 | $this->assertValidField($field); |
| 33 | return $this->entityChangeSet[$field][1]; |
| 34 | } |
| 35 | public function setNewValue(string $field, $value) |
| 36 | { |
| 37 | $this->assertValidField($field); |
| 38 | $this->entityChangeSet[$field][1] = $value; |
| 39 | } |
| 40 | private function assertValidField(string $field) |
| 41 | { |
| 42 | if (!isset($this->entityChangeSet[$field])) { |
| 43 | throw new InvalidArgumentException(sprintf('Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.', $field, get_class($this->getObject()))); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 |