Ejemplo n.º 1
0
 /** {@inheritdoc} */
 public function count(RpcClientInterface $client, ApiMetadata $metadata, array $parameters)
 {
     call_user_func_array([$this, 'configure'], $parameters);
     $parameters = $this->getSearchRequestParams();
     $request = new RpcRequest($metadata->getMethodContainer()->getMethod('count'), $parameters);
     return (int) $client->invoke($request)->getResponse($request)->getBody();
 }
Ejemplo n.º 2
0
 /**
  * Do the initialization logic
  *
  * @return void
  * @throws RpcExceptionInterface
  */
 protected function doInitialize()
 {
     $persister = $this->manager->getUnitOfWork()->getEntityPersister($this->metadata->getName());
     /** @var Collection $collection */
     $collection = call_user_func_array([$persister, 'loadAll'], $this->searchArgs);
     if ($collection instanceof AbstractLazyCollection && $this->owner) {
         $collection = $persister->loadOneToManyCollection($this->association, $this->owner, $collection);
     }
     $this->collection = $collection;
 }
 /**
  * @param array|mixed $id
  *
  * @return array
  * @throws MappingException
  */
 protected function fixScalarId($id, ApiMetadata $metadata)
 {
     if (is_array($id)) {
         return $id;
     }
     $id = (array) $id;
     $identifiers = $metadata->getIdentifierFieldNames();
     if (count($id) !== count($identifiers)) {
         throw MappingException::invalidIdentifierStructure();
     }
     return array_combine($identifiers, (array) $id);
 }
 /**
  * convert foreign identifiers into scalar foreign key values to avoid object to string conversion failures.
  *
  * @param ApiMetadata $class
  * @param array       $id
  *
  * @return array
  */
 public function flattenIdentifier(ApiMetadata $class, array $id)
 {
     $flatId = [];
     foreach ($class->getIdentifierFieldNames() as $field) {
         if ($class->hasAssociation($field) && array_key_exists($field, $id) && is_object($id[$field])) {
             /* @var EntityMetadata $targetClassMetadata */
             $targetClassMetadata = $this->manager->getClassMetadata($class->getAssociationMapping($field)['target']);
             if ($this->unitOfWork->isInIdentityMap($id[$field])) {
                 $associatedId = $this->flattenIdentifier($targetClassMetadata, $this->unitOfWork->getEntityIdentifier($id[$field]));
             } else {
                 $associatedId = $this->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($id[$field]));
             }
             $flatId[$field] = implode(' ', $associatedId);
         } else {
             $flatId[$field] = $id[$field];
         }
     }
     return $flatId;
 }
Ejemplo n.º 5
0
 /**
  * Creates a closure capable of finalizing state a cloned proxy
  *
  * @param ApiMetadata  $classMetadata
  * @param ApiPersister $persister
  *
  * @return \Closure
  * @throws FetchException
  */
 private function createCloner(ApiMetadata $classMetadata, ApiPersister $persister)
 {
     return function (Proxy $proxy) use($classMetadata, $persister) {
         if ($proxy->__isInitialized()) {
             return;
         }
         $proxy->__setInitialized(true);
         $proxy->__setInitializer(null);
         /** @var EntityMetadata $class */
         $class = $persister->getClassMetadata();
         $identifier = $classMetadata->getIdentifierValues($proxy);
         $original = $persister->loadById($identifier);
         if (null === $original) {
             throw FetchException::notFound();
         }
         foreach ($class->getReflectionClass()->getProperties() as $property) {
             if (!$class->hasField($property->name) && !$class->hasAssociation($property->name)) {
                 continue;
             }
             $property->setAccessible(true);
             $property->setValue($proxy, $property->getValue($original));
         }
     };
 }
Ejemplo n.º 6
0
 /**
  * @param ApiMetadata $class
  *
  * @return \Doctrine\Common\Persistence\ObjectManagerAware|object
  */
 private function newInstance(ApiMetadata $class)
 {
     $entity = $class->newInstance();
     if ($entity instanceof ObjectManagerAware) {
         $entity->injectObjectManager($this->manager, $class);
     }
     return $entity;
 }
 /**
  * @return RpcClientInterface
  */
 protected function getClient()
 {
     return $this->manager->getConfiguration()->getRegistry()->get($this->metadata->getClientName());
 }
Ejemplo n.º 8
0
 /**
  * ApiPersister constructor.
  *
  * @param EntityManager $manager
  * @param ApiMetadata   $metadata
  */
 public function __construct(EntityManager $manager, ApiMetadata $metadata)
 {
     $this->manager = $manager;
     $this->client = $manager->getConfiguration()->getRegistry()->get($metadata->getClientName());
     $this->metadata = $metadata;
 }