コード例 #1
0
 private function getAssociationString(ClassMetadata $class1, $association)
 {
     $targetClassName = $class1->getAssociationTargetClass($association);
     $class2 = $this->getClassByName($targetClassName);
     $isInverse = $class1->isAssociationInverseSide($association);
     $class1Count = $class1->isCollectionValuedAssociation($association) ? 2 : 1;
     if (null === $class2) {
         return $this->getClassString($class1) . ($isInverse ? '<' : '<>') . '-' . $association . ' ' . ($class1Count > 1 ? '*' : ($class1Count ? '1' : '')) . ($isInverse ? '<>' : '>') . '[' . str_replace('\\', '.', $targetClassName) . ']';
     }
     $class1SideName = $association;
     $class2SideName = '';
     $class2Count = 0;
     $bidirectional = false;
     if ($isInverse) {
         $class2SideName = (string) $class1->getAssociationMappedByTargetField($association);
         if ($class2SideName) {
             $class2Count = $class2->isCollectionValuedAssociation($class2SideName) ? 2 : 1;
             $bidirectional = true;
         }
     } else {
         foreach ($class2->getAssociationNames() as $class2Side) {
             if ($class2->isAssociationInverseSide($class2Side) && $class2->getAssociationMappedByTargetField($class2Side) === $association) {
                 $class2SideName = $class2Side;
                 $class2Count = $class2->isCollectionValuedAssociation($class2SideName) ? 2 : 1;
                 $bidirectional = true;
                 break;
             }
         }
     }
     $this->visitAssociation($targetClassName, $class2SideName);
     return $this->getClassString($class1) . ($bidirectional ? $isInverse ? '<' : '<>' : '') . ($class2SideName ? $class2SideName . ' ' : '') . ($class2Count > 1 ? '*' : ($class2Count ? '1' : '')) . '-' . $class1SideName . ' ' . ($class1Count > 1 ? '*' : ($class1Count ? '1' : '')) . ($bidirectional && $isInverse ? '<>' : '>') . $this->getClassString($class2);
 }
コード例 #2
0
 /**
  * If this is an inverse side association, completes the owning side.
  *
  * @param string        $field
  * @param ClassMetadata $targetClass
  * @param object        $targetObject
  *
  * @return void
  */
 private function completeOwningSide($field, $targetClass, $targetObject)
 {
     // add this object on the owning side as well, for obvious infinite recursion
     // reasons this is only done when called on the inverse side.
     if ($this->cm->isAssociationInverseSide($field)) {
         $mappedByField = $this->cm->getAssociationMappedByTargetField($field);
         $targetMetadata = self::$objectManager->getClassMetadata($targetClass);
         $setter = ($targetMetadata->isCollectionValuedAssociation($mappedByField) ? "add" : "set") . $mappedByField;
         $targetObject->{$setter}($this);
     }
 }
コード例 #3
0
ファイル: DoctrineInfo.php プロジェクト: a2lix/AutoFormBundle
 /**
  * @param ClassMetadata $metadata
  * @param array         $assocNames
  *
  * @return array
  */
 private function getAssocsConfig(ClassMetadata $metadata, $assocNames)
 {
     $assocsConfigs = [];
     foreach ($assocNames as $assocName) {
         if (!$metadata->isAssociationInverseSide($assocName)) {
             continue;
         }
         $class = $metadata->getAssociationTargetClass($assocName);
         if ($metadata->isSingleValuedAssociation($assocName)) {
             $nullable = $metadata instanceof ClassMetadataInfo && isset($metadata->discriminatorColumn['nullable']) && $metadata->discriminatorColumn['nullable'];
             $assocsConfigs[$assocName] = ['field_type' => 'A2lix\\AutoFormBundle\\Form\\Type\\AutoFormType', 'data_class' => $class, 'required' => !$nullable];
             continue;
         }
         $assocsConfigs[$assocName] = ['field_type' => 'Symfony\\Component\\Form\\Extension\\Core\\Type\\CollectionType', 'entry_type' => 'A2lix\\AutoFormBundle\\Form\\Type\\AutoFormType', 'entry_options' => ['data_class' => $class], 'allow_add' => true, 'by_reference' => false];
     }
     return $assocsConfigs;
 }
コード例 #4
0
 /**
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata
  * @param                                                    $model
  *
  * @return array
  */
 protected function processAssociationNames(ClassMetadata $metadata, $model)
 {
     $data = array();
     foreach ($metadata->getAssociationNames() as $assocName) {
         $propertyValue = $this->readProperty($model, $assocName);
         if (null === $propertyValue || $metadata->isAssociationInverseSide($assocName)) {
             continue;
         }
         if ($metadata->isSingleValuedAssociation($assocName)) {
             $assocValue = $this->namingStrategy->modelName($propertyValue, $this->getManager()->getClassMetadata(get_class($propertyValue)));
             $assocValue = $this->navigator->accept($this->getVisitor(), $assocValue, 'reference');
             $data[$assocName] = $assocValue;
         } else {
             $data[$assocName] = array();
             foreach ($propertyValue as $value) {
                 $assocValue = $this->namingStrategy->modelName($value, $this->getManager()->getClassMetadata(get_class($value)));
                 $assocValue = $this->navigator->accept($this->getVisitor(), $assocValue, 'reference');
                 $data[$assocName][] = $assocValue;
             }
         }
     }
     return $data;
 }