コード例 #1
0
 /**
  * @param string $className
  *
  * @return ProxyDefinition
  * @throws FetchException
  */
 protected function createProxyDefinition($className)
 {
     /** @var EntityMetadata $classMetadata */
     $classMetadata = $this->manager->getClassMetadata($className);
     /** @var ApiPersister $persister */
     $persister = $this->uow->getEntityPersister($className);
     return new ProxyDefinition(ClassUtils::generateProxyClassName($className, $this->manager->getConfiguration()->getProxyNamespace()), $classMetadata->getIdentifierFieldNames(), $classMetadata->getReflectionProperties(), $this->createInitializer($classMetadata, $persister), $this->createCloner($classMetadata, $persister));
 }
コード例 #2
0
 /**
  * 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;
 }