Example #1
0
 public function commit()
 {
     foreach ($this->registry->all() as $entity) {
         switch ($this->getEntityState($entity)) {
             case EntityStates::NEW_ENTITY:
                 $this->commandBus->dispatch(new NewCommand($entity));
                 break;
             case EntityStates::EDITED_ENTITY:
                 $changeSet = $this->changeBuilder->buildChanges($this->registry->getSnapshot($entity), $entity);
                 $this->commandBus->dispatch(new EditCommand($entity, $changeSet));
                 break;
             case EntityStates::REMOVED_ENTITY:
                 $this->commandBus->dispatch(new RemoveCommand($entity));
                 break;
         }
     }
     $this->registry->cleanRemoved();
     $this->registry->makeNewSnapshots();
 }