Doctrine\ORM\UnitOfWork::getEntityChangeSet PHP Method

getEntityChangeSet() public method

Gets the changeset for an entity.
public getEntityChangeSet ( $entity ) : array
return array
    public function getEntityChangeSet($entity)
    {
        $oid = spl_object_hash($entity);
        if (isset($this->entityChangeSets[$oid])) {
            return $this->entityChangeSets[$oid];
        }
        return array();
    }

Usage Example

 /**
  * Flush for update
  *
  * @param object $entity
  * @param \Doctrine\ORM\EntityManager $entityManager
  * @param \Doctrine\ORM\UnitOfWork $unitOfWork
  */
 protected function onFlushForUpdates(&$entity, EntityManager &$entityManager, UnitOfWork &$unitOfWork)
 {
     $className = get_class($entity);
     $this->initializeAnnotationsForEntity($className);
     if (count(self::$storedProperties[$className]['annotations']) > 0) {
         foreach (self::$storedProperties[$className]['annotations'] as $propertyName => &$annotations) {
             /* @var $annotation Traceable */
             foreach ($annotations as $annotation) {
                 $run = $annotation->on === 'update';
                 if ($annotation->on === 'change') {
                     $changeSet = $unitOfWork->getEntityChangeSet($entity);
                     if (isset($changeSet[$annotation->field])) {
                         $type = $this->getPropertyType($className, $annotation->field);
                         $values = $annotation->getFieldValues($type, $entity);
                         $run = count($values) === 0 || in_array($changeSet[$annotation->field][1], $values);
                     }
                 }
                 if ($run) {
                     list($oldValue, $value) = $this->updateEntityPropertyValue($entity, $className, $propertyName, $annotation);
                     $entityManager->persist($entity);
                     $unitOfWork->propertyChanged($entity, $propertyName, $oldValue, $value);
                     $unitOfWork->scheduleExtraUpdate($entity, array($propertyName => array($oldValue, $value)));
                     break;
                 }
             }
         }
     }
 }
All Usage Examples Of Doctrine\ORM\UnitOfWork::getEntityChangeSet