コード例 #1
0
 /**
  * @param ClassMetadata $classMetadata
  * @param string        $associationName
  *
  * @return AssociationMetadata
  */
 public function createAssociationMetadata(ClassMetadata $classMetadata, $associationName)
 {
     $targetClass = $classMetadata->getAssociationTargetClass($associationName);
     $associationMetadata = new AssociationMetadata();
     $associationMetadata->setName($associationName);
     $associationMetadata->setTargetClassName($targetClass);
     $associationMetadata->setIsCollection($classMetadata->isCollectionValuedAssociation($associationName));
     $targetMetadata = $this->doctrineHelper->getEntityMetadataForClass($targetClass);
     $targetIdFields = $targetMetadata->getIdentifierFieldNames();
     if (count($targetIdFields) === 1) {
         $associationMetadata->setDataType($targetMetadata->getTypeOfField(reset($targetIdFields)));
     } else {
         $associationMetadata->setDataType(DataType::STRING);
     }
     if ($targetMetadata->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) {
         $associationMetadata->setAcceptableTargetClassNames($targetMetadata->subClasses);
     } else {
         $associationMetadata->addAcceptableTargetClassName($targetClass);
     }
     return $associationMetadata;
 }
コード例 #2
0
 /**
  * @param ClassMetadata $classMetadata
  * @param string        $associationName
  *
  * @return AssociationMetadata
  */
 public function createAssociationMetadata(ClassMetadata $classMetadata, $associationName)
 {
     $targetClass = $classMetadata->getAssociationTargetClass($associationName);
     $associationMetadata = new AssociationMetadata();
     $associationMetadata->setName($associationName);
     $associationMetadata->setTargetClassName($targetClass);
     $associationMetadata->setIsCollection($classMetadata->isCollectionValuedAssociation($associationName));
     $targetMetadata = $this->doctrineHelper->getEntityMetadataForClass($targetClass);
     $targetIdFields = $targetMetadata->getIdentifierFieldNames();
     if (count($targetIdFields) === 1) {
         $associationMetadata->setDataType($targetMetadata->getTypeOfField(reset($targetIdFields)));
     } else {
         $associationMetadata->setDataType(DataType::STRING);
     }
     return $associationMetadata;
 }
コード例 #3
0
ファイル: EntityMetadata.php プロジェクト: Maksold/platform
 /**
  * Adds metadata of an association.
  *
  * @param AssociationMetadata $association
  */
 public function addAssociation(AssociationMetadata $association)
 {
     $this->associations[$association->getName()] = $association;
 }
コード例 #4
0
 /**
  * @param mixed               $object
  * @param AssociationMetadata $associationMetadata
  *
  * @return array The resource identifier
  */
 protected function processRelatedObject($object, AssociationMetadata $associationMetadata)
 {
     $targetMetadata = $associationMetadata->getTargetMetadata();
     $preparedValue = $this->prepareRelatedValue($object, $associationMetadata->getTargetClassName(), $targetMetadata);
     if ($preparedValue['idOnly']) {
         $resourceId = $this->getResourceIdObject($preparedValue['entityType'], $this->entityIdTransformer->transform($preparedValue['value']));
     } else {
         $resourceId = $this->getResourceIdObject($preparedValue['entityType'], $this->entityIdAccessor->getEntityId($preparedValue['value'], $targetMetadata));
         $this->addRelatedObject($preparedValue['value'], $targetMetadata);
     }
     return $resourceId;
 }