Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function extract($object)
 {
     if ($object instanceof Hydratable) {
         return $object->extract();
     }
     return $this->hydrator->extract($object);
 }
Ejemplo n.º 2
0
 /**
  * Returns an entity's data
  *
  * @param Load $query
  *
  * @return array|null
  */
 public function handle(Load $query)
 {
     $entityClass = $query->getEntityClass();
     $id = $query->getId();
     $entity = $this->em->getRepository($entityClass)->find($id);
     if ($entity) {
         return $this->hydrator->extract($entity);
     }
 }
Ejemplo n.º 3
0
 /**
  * Updates an entity
  *
  * @param Update $command
  */
 public function handle(Update $command)
 {
     $entity = $command->getEntity();
     $data = $command->getData();
     // UGLY WORKAROUND BEGINS
     $data = array_merge($this->hydrator->extract($entity), $data);
     // UGLY WORKAROUND ENDS
     $this->hydrator->hydrate($entity, $data);
     $this->em->flush();
 }
Ejemplo n.º 4
0
 function it_handles_a_load_query(Entity $entity, Load $query, EntityRepository $repository, EntityManagerInterface $em, Hydrator $hydra)
 {
     $data = ['data' => 'atad'];
     $query->getEntityClass()->willReturn('Indigo\\Crud\\Stub\\Entity');
     $query->getId()->willReturn(1);
     $repository->find(1)->willReturn($entity);
     $em->getRepository('Indigo\\Crud\\Stub\\Entity')->willReturn($repository);
     $hydra->extract($entity)->willReturn($data);
     $this->handle($query)->shouldReturn($data);
 }
Ejemplo n.º 5
0
 /**
  * Creates a new entity
  *
  * @param Create $command
  */
 public function handle(Create $command)
 {
     $entityClass = $command->getEntityClass();
     $entity = $this->instantiator->instantiate($entityClass);
     $data = $command->getData();
     // UGLY WORKAROUND BEGINS
     $data = array_merge($this->hydrator->extract($entity), $data);
     // UGLY WORKAROUND ENDS
     $this->hydrator->hydrate($entity, $data);
     $this->em->persist($entity);
     $this->em->flush();
 }
Ejemplo n.º 6
0
 function it_handles_a_create_command(Entity $entity, Create $command, InstantiatorInterface $instantiator, Hydrator $hydra, EntityManagerInterface $em)
 {
     $entityClass = 'Indigo\\Crud\\Stub\\Entity';
     $data = ['estimatedEnd' => 'now'];
     $command->getEntityClass()->willReturn($entityClass);
     $command->getData()->willReturn($data);
     $instantiator->instantiate($entityClass)->willReturn($entity);
     $hydra->extract($entity)->willReturn([]);
     $hydra->hydrate($entity, $data)->shouldBeCalled();
     $em->persist($entity)->shouldBeCalled();
     $em->flush()->shouldBeCalled();
     $this->handle($command);
 }
Ejemplo n.º 7
0
 function it_calls_the_hydrator_during_extraction(Hydrator $hydrator, \stdClass $object)
 {
     $hydrator->extract($object)->shouldBeCalled();
     $this->extract($object);
 }