/**
  * @return object
  */
 public function newInstance()
 {
     if ($this->instantiator === NULL) {
         $this->instantiator = new Doctrine\Instantiator\Instantiator();
     }
     return $this->instantiator->instantiate($this->name);
 }
Example #2
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();
 }
Example #3
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);
 }
Example #4
0
 /**
  * @param array $serializedObject
  *
  * @return object
  */
 private function deserializeObject(array $serializedObject)
 {
     list($name, $payload) = $this->dataFormatter->getNameAndPayload($serializedObject);
     $curatedPayload = [];
     foreach ($payload as $key => $value) {
         $curatedPayload[$key] = $this->recursiveDeserialize($value);
     }
     $objectFqcn = $this->classMapper->getClassName($name);
     foreach ($this->customSerializers as $customSerializer) {
         if ($customSerializer->canHandle($objectFqcn)) {
             return $customSerializer->deserialize($curatedPayload, $objectFqcn);
         }
     }
     $object = $this->instantiator->instantiate($objectFqcn);
     return $this->hydratorFactory->getHydrator($objectFqcn)->hydrate($curatedPayload, $object);
 }
Example #5
0
 /**
  * Creates a new instance of the mapped class, without invoking the constructor.
  *
  * @return object
  */
 public function newInstance()
 {
     if (!$this->instantiator instanceof InstantiatorInterface) {
         $this->instantiator = new Instantiator();
     }
     return $this->instantiator->instantiate($this->name);
 }
 /**
  * Creates a new instance of the mapped class, without invoking the constructor.
  *
  * @return object
  */
 public function newInstance()
 {
     return $this->instantiator->instantiate($this->name);
 }
 /**
  * @inheritdoc
  */
 public function objectFrom($className, array $data)
 {
     $object = $this->instantiator->instantiate($className);
     $this->hydrator->hydrate($data, $object);
     return $object;
 }