Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function persist(ConnectionInterface $connection, Container $container)
 {
     $entities = $container->state(Container::STATE_TO_BE_REMOVED)->foreach(function (IdentityInterface $identity, $object) {
         $this->dispatcher->dispatch(Events::PRE_REMOVE, new RemoveEvent($identity, $object));
     });
     if ($entities->size() === 0) {
         return;
     }
     $connection->execute($this->queryFor($entities));
     $entities->foreach(function (IdentityInterface $identity, $object) use($container) {
         $container->push($identity, $object, Container::STATE_REMOVED);
         $this->changeset->use($identity, new Collection([]));
         //in case the identity is reused later on
         $this->dispatcher->dispatch(Events::POST_REMOVE, new RemoveEvent($identity, $object));
     });
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function persist(ConnectionInterface $connection, Container $container)
 {
     $entities = $container->state(Container::STATE_NEW);
     if ($entities->size() === 0) {
         return;
     }
     $entities->foreach(function (IdentityInterface $identity, $entity) {
         $this->dispatcher->dispatch(Events::PRE_PERSIST, new PersistEvent($identity, $entity));
     });
     $connection->execute($this->queryFor($entities));
     $entities->foreach(function (IdentityInterface $identity, $entity) use($container) {
         $container->push($identity, $entity, Container::STATE_MANAGED);
         $this->changeset->use($identity, $this->extractor->extract($entity));
         $this->dispatcher->dispatch(Events::POST_PERSIST, new PersistEvent($identity, $entity));
     });
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function persist(ConnectionInterface $connection, Container $container)
 {
     $changesets = new Map(IdentityInterface::class, CollectionInterface::class);
     $entities = $container->state(Container::STATE_MANAGED)->foreach(function (IdentityInterface $identity, $entity) use(&$changesets) {
         $data = $this->extractor->extract($entity);
         $changeset = $this->changeset->compute($identity, $data);
         if ($changeset->count() > 0) {
             $changesets = $changesets->put($identity, $changeset);
         }
     });
     if ($changesets->size() === 0) {
         return;
     }
     $changesets->foreach(function (IdentityInterface $identity, CollectionInterface $changeset) use($entities) {
         $this->dispatcher->dispatch(Events::PRE_UPDATE, new UpdateEvent($identity, $entities->get($identity), $changeset));
     });
     $connection->execute($this->queryFor($changesets, $entities));
     $changesets->foreach(function (IdentityInterface $identity, CollectionInterface $changeset) use($entities) {
         $entity = $entities->get($identity);
         $this->changeset->use($identity, $this->extractor->extract($entity));
         $this->dispatcher->dispatch(Events::POST_UPDATE, new UpdateEvent($identity, $entity, $changeset));
     });
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function execute($sql)
 {
     return $this->conn->execute($sql);
 }