LifecycleEventArgs.php
9 months ago
ListenersInvoker.php
9 months ago
LoadClassMetadataEventArgs.php
9 months ago
OnClassMetadataNotFoundEventArgs.php
9 months ago
OnClearEventArgs.php
9 months ago
OnFlushEventArgs.php
9 months ago
PostFlushEventArgs.php
9 months ago
PostLoadEventArgs.php
9 months ago
PostPersistEventArgs.php
9 months ago
PostRemoveEventArgs.php
9 months ago
PostUpdateEventArgs.php
9 months ago
PreFlushEventArgs.php
9 months ago
PrePersistEventArgs.php
9 months ago
PreRemoveEventArgs.php
9 months ago
PreUpdateEventArgs.php
9 months ago
index.php
9 months ago
PreUpdateEventArgs.php
49 lines
| 1 | <?php |
| 2 | declare (strict_types=1); |
| 3 | namespace MailPoetVendor\Doctrine\ORM\Event; |
| 4 | if (!defined('ABSPATH')) exit; |
| 5 | use MailPoetVendor\Doctrine\ORM\EntityManagerInterface; |
| 6 | use MailPoetVendor\Doctrine\ORM\PersistentCollection; |
| 7 | use InvalidArgumentException; |
| 8 | use function get_debug_type; |
| 9 | use function sprintf; |
| 10 | class PreUpdateEventArgs extends LifecycleEventArgs |
| 11 | { |
| 12 | private $entityChangeSet; |
| 13 | public function __construct($entity, EntityManagerInterface $em, array &$changeSet) |
| 14 | { |
| 15 | // @phpstan-ignore method.deprecatedClass |
| 16 | parent::__construct($entity, $em); |
| 17 | $this->entityChangeSet =& $changeSet; |
| 18 | } |
| 19 | public function getEntityChangeSet() |
| 20 | { |
| 21 | return $this->entityChangeSet; |
| 22 | } |
| 23 | public function hasChangedField($field) |
| 24 | { |
| 25 | return isset($this->entityChangeSet[$field]); |
| 26 | } |
| 27 | public function getOldValue($field) |
| 28 | { |
| 29 | $this->assertValidField($field); |
| 30 | return $this->entityChangeSet[$field][0]; |
| 31 | } |
| 32 | public function getNewValue($field) |
| 33 | { |
| 34 | $this->assertValidField($field); |
| 35 | return $this->entityChangeSet[$field][1]; |
| 36 | } |
| 37 | public function setNewValue($field, $value) |
| 38 | { |
| 39 | $this->assertValidField($field); |
| 40 | $this->entityChangeSet[$field][1] = $value; |
| 41 | } |
| 42 | private function assertValidField(string $field) : void |
| 43 | { |
| 44 | if (!isset($this->entityChangeSet[$field])) { |
| 45 | throw new InvalidArgumentException(sprintf('Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.', $field, get_debug_type($this->getObject()))); |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 |