Doctrine\Search\UnitOfWork::persist PHP Method

persist() public method

Persists an entity as part of the current unit of work.
public persist ( object $entity )
$entity object The entity to persist.
    public function persist($entity)
    {
        if ($this->evm->hasListeners(Events::prePersist)) {
            $this->evm->dispatchEvent(Events::prePersist, new Event\LifecycleEventArgs($entity, $this->sm));
        }
        $oid = spl_object_hash($entity);
        $this->scheduledForPersist[$oid] = $entity;
        if ($this->evm->hasListeners(Events::postPersist)) {
            $this->evm->dispatchEvent(Events::postPersist, new Event\LifecycleEventArgs($entity, $this->sm));
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Adds the object to the index
  *
  * @param array|object $objects
  *
  * @throws UnexpectedTypeException
  */
 public function persist($objects)
 {
     if (!is_array($objects) && !$objects instanceof \Traversable) {
         $objects = array($objects);
     }
     foreach ($objects as $object) {
         if (!is_object($object)) {
             throw new UnexpectedTypeException($object, 'object');
         }
         $this->unitOfWork->persist($object);
     }
 }