/** * {@inheritdoc} */ public function hydrate($object, array $data) { if ($object instanceof Hydratable) { $object->hydrate($data); return; } $this->hydrator->hydrate($object, $data); }
/** * 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(); }
/** * 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(); }
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); }
function it_calls_the_hydrator_during_hydration(Hydrator $hydrator, \stdClass $object) { $hydrator->hydrate($object, [])->shouldBeCalled(); $this->hydrate($object, []); }