当前位置: 首页>>代码示例>>PHP>>正文


PHP ClassMetadata::getAssociationMappings方法代码示例

本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::getAssociationMappings方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getAssociationMappings方法的具体用法?PHP ClassMetadata::getAssociationMappings怎么用?PHP ClassMetadata::getAssociationMappings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\ORM\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::getAssociationMappings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createAssociationFormatters

 public function createAssociationFormatters($columnTypeGuesser)
 {
     $formatters = array();
     // $getAssociationNames = $this->class->getAssociationNames();
     // foreach ($getAssociationNames AS $assocName) {
     // $relatedClass = $this->class->getAssociationTargetClass($assocName);
     $associationMappings = $this->class->getAssociationMappings();
     foreach ($associationMappings as $associationMapping) {
         if ($associationType = $this->getAssociationType($associationMapping)) {
             //echo "pola asocjacyjne: " . $associationMapping['fieldName'] . "\n";
             $formatter = $columnTypeGuesser->getAssociation($associationMapping['fieldName'], $associationMapping['targetEntity'], $associationType, $this->manager);
             if ($formatter) {
                 $formatters[$associationMapping['fieldName']] = $formatter;
             }
         }
     }
     $index = 0;
     /* $formatters[$assocName] = function($inserted) use ($relatedClass, &$index, $relation) {
               if ($unique && isset($inserted[$relatedClass])) {
               return $inserted[$relatedClass][$index++];
               } elseif (isset($inserted[$relatedClass])) {
               return $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)];
               }
     
               return null;
     
               }; */
     //}
     return $formatters;
 }
开发者ID:TMSolution,项目名称:GeneratorBundle,代码行数:30,代码来源:EntityPopulator.php

示例2: addDoctrineAssociations

 /**
  * @param EntityMetadata $entityMetadata
  * @param ClassMetadata $classMetadata
  */
 protected function addDoctrineAssociations(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
 {
     foreach ($classMetadata->getAssociationMappings() as $fieldName => $associationMapping) {
         $fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $associationMapping);
         $entityMetadata->addFieldMetadata($fieldMetadata);
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:11,代码来源:MetadataBuilder.php

示例3: processNode

 /**
  * Process the node metadata.
  *
  * @param LoadClassMetadataEventArgs $eventArgs
  * @param ClassMetadata $metadata
  * @param Node $annotation
  */
 protected function processNode(LoadClassMetadataEventArgs $eventArgs, ClassMetadata $metadata, Node $annotation)
 {
     $className = $metadata->name;
     // Holds the closure tree data
     $closureTreeData = array();
     // Check if we should either use the default entity or prepend the node namespace
     if (!$annotation->treeEntity) {
         $closureTreeData['treeEntity'] = $className . 'Tree';
     } elseif (strpos($annotation->treeEntity, '\\') === false) {
         $closureTreeData['treeEntity'] = $metadata->namespace . '\\' . $annotation->treeEntity;
     }
     // Loop through the properties and find the parent column
     foreach ($metadata->getAssociationMappings() as $propertyName => $propertyData) {
         $propertyAnnotations = $this->reader->getPropertyAnnotations(new \ReflectionProperty($className, $propertyName));
         // Check if this property has the node parent annotation
         foreach ($propertyAnnotations as $propertyAnnotation) {
             if ($propertyAnnotation instanceof NodeParent) {
                 // Set the parent data
                 $closureTreeData['parent'] = $propertyData;
                 break 2;
             }
         }
     }
     // Make sure a parent was specified
     if (!isset($closureTreeData['parent'])) {
         throw new \Exception('You must define a parent column for the closure tree entity ' . $className . '.');
     }
     // Set the closure tree data
     $metadata->closureTree = $closureTreeData;
 }
开发者ID:theartoflogic,项目名称:doctrine-tree-extension,代码行数:37,代码来源:EventSubscriber.php

示例4: guessColumnFormatters

 /**
  * @param \Faker\Generator $generator
  * @return array
  */
 public function guessColumnFormatters(\Faker\Generator $generator)
 {
     $formatters = array();
     $nameGuesser = new \Faker\Guesser\Name($generator);
     $columnTypeGuesser = new ColumnTypeGuesser($generator);
     foreach ($this->class->getFieldNames() as $fieldName) {
         if ($this->class->isIdentifier($fieldName) || !$this->class->hasField($fieldName)) {
             continue;
         }
         $size = isset($this->class->fieldMappings[$fieldName]['length']) ? $this->class->fieldMappings[$fieldName]['length'] : null;
         if ($formatter = $nameGuesser->guessFormat($fieldName, $size)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     foreach ($this->class->getAssociationNames() as $assocName) {
         if ($this->class->isCollectionValuedAssociation($assocName)) {
             continue;
         }
         $relatedClass = $this->class->getAssociationTargetClass($assocName);
         $unique = $optional = false;
         $mappings = $this->class->getAssociationMappings();
         foreach ($mappings as $mapping) {
             if ($mapping['targetEntity'] == $relatedClass) {
                 if ($mapping['type'] == ClassMetadata::ONE_TO_ONE) {
                     $unique = true;
                     $optional = isset($mapping['joinColumns'][0]['nullable']) ? $mapping['joinColumns'][0]['nullable'] : false;
                     break;
                 }
             }
         }
         $index = 0;
         $formatters[$assocName] = function ($inserted) use($relatedClass, &$index, $unique, $optional) {
             if (isset($inserted[$relatedClass])) {
                 if ($unique) {
                     $related = null;
                     if (isset($inserted[$relatedClass][$index]) || !$optional) {
                         $related = $inserted[$relatedClass][$index];
                     }
                     $index++;
                     return $related;
                 }
                 return $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)];
             }
             return null;
         };
     }
     return $formatters;
 }
开发者ID:drickferreira,项目名称:rastreador,代码行数:57,代码来源:EntityPopulator.php

示例5: getDatabaseAssociationMappings

 /**
  * Returns association mapping for a given entity.
  *
  * @param ClassMetadata $cm
  * @param bool|false    $bTree
  *
  * @return array
  */
 protected function getDatabaseAssociationMappings(ClassMetadata $cm, $bTree = false)
 {
     $associations = $cm->getAssociationMappings();
     $byReferenceMappings = $this->getByReferenceMappings($cm);
     $associationMappings = [];
     foreach ($associations as $association) {
         $getterPlural = false;
         $associationType = $association['type'];
         switch ($association['type']) {
             case ClassMetadataInfo::MANY_TO_MANY:
                 $associationType = 'MANY_TO_MANY';
                 $getterPlural = true;
                 break;
             case ClassMetadataInfo::MANY_TO_ONE:
                 $associationType = 'MANY_TO_ONE';
                 $getterPlural = false;
                 break;
             case ClassMetadataInfo::ONE_TO_MANY:
                 $associationType = 'ONE_TO_MANY';
                 $getterPlural = true;
                 break;
             case ClassMetadataInfo::ONE_TO_ONE:
                 $associationType = 'ONE_TO_ONE';
                 $getterPlural = false;
                 break;
         }
         $getter = 'get' . ucfirst($association['fieldName']);
         $getterField = lcfirst($cm->getReflectionClass()->getShortName()) . str_replace('.', '', $this->convertPHPToExtJSClassName($association['targetEntity']));
         if ($getterPlural) {
             $getterField .= 's';
         }
         $propertyAnnotations = $this->reader->getPropertyAnnotations($cm->getReflectionProperty($association['fieldName']));
         $nullable = true;
         foreach ($propertyAnnotations as $propertyAnnotation) {
             $filter = "Symfony\\Component\\Validator\\Constraints\\NotNull";
             if (substr(get_class($propertyAnnotation), 0, strlen($filter)) === $filter) {
                 $nullable = false;
             }
         }
         // The self-referencing association may not be written for trees, because ExtJS can't load all nodes
         // in one go.
         if (!($bTree && $association['targetEntity'] == $cm->getName())) {
             $byReference = false;
             if (in_array($association['fieldName'], $byReferenceMappings)) {
                 $byReference = true;
             }
             $associationMappings[$associationType][] = ['name' => $association['fieldName'], 'nullable' => $nullable, 'target' => $this->convertPHPToExtJSClassName($association['targetEntity']), 'byReference' => $byReference, 'getter' => $getter, 'getterField' => $getterField];
         }
     }
     return $associationMappings;
 }
开发者ID:partkeepr,项目名称:PartKeepr,代码行数:59,代码来源:ReflectionService.php

示例6: loadAssociationObjectsToEntity

 /**
  * Add the associated objects in case the item have for persist its relation
  *
  * @param array  $item
  * @param object $entity
  */
 protected function loadAssociationObjectsToEntity(array $item, $entity)
 {
     foreach ($this->entityMetadata->getAssociationMappings() as $associationMapping) {
         $value = null;
         if (isset($item[$associationMapping['fieldName']]) && !is_object($item[$associationMapping['fieldName']])) {
             $value = $this->entityManager->getReference($associationMapping['targetEntity'], $item[$associationMapping['fieldName']]);
         }
         if (null === $value) {
             continue;
         }
         $setter = 'set' . ucfirst($associationMapping['fieldName']);
         $this->setValue($entity, $value, $setter);
     }
 }
开发者ID:megamanhxh,项目名称:data-import,代码行数:20,代码来源:DoctrineWriter.php

示例7: processRelation

 /**
  * @param ClassMetadata $metadata
  * @param object $relation
  * @param mixed $value
  */
 protected function processRelation($metadata, $relation, $value)
 {
     foreach ($metadata->getAssociationMappings() as $mapping) {
         if (!is_array($mapping) || !isset($mapping['targetEntity'], $mapping['type'], $mapping['mappedBy'])) {
             continue;
         }
         if ($mapping['targetEntity'] !== ClassUtils::getClass($relation)) {
             continue;
         }
         if ($mapping['type'] !== ClassMetadata::ONE_TO_MANY) {
             continue;
         }
         $mappedBy = $mapping['mappedBy'];
         $setter = $this->getSetterName($mappedBy);
         $relation->{$setter}($value);
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:22,代码来源:MultipleEntitySubscriber.php

示例8: getAssociations

 /**
  * {@inheritdoc}
  */
 protected function getAssociations(array $definition, ClassMetadata $metadata, $version, array $requestType, array $extras)
 {
     $associations = $metadata->getAssociationMappings();
     foreach ($associations as $fieldName => $mapping) {
         if (!$this->isAssociationCompletionRequired($fieldName, $definition)) {
             continue;
         }
         $config = $this->relationConfigProvider->getRelationConfig($mapping['targetEntity'], $version, $requestType, $extras);
         if (isset($definition[$fieldName]) && is_array($definition[$fieldName])) {
             $config = array_merge_recursive($config, [ConfigUtil::DEFINITION => $definition[$fieldName]]);
         }
         if ($this->exclusionProvider->isIgnoredRelation($metadata, $fieldName)) {
             $config[ConfigUtil::DEFINITION][ConfigUtil::EXCLUDE] = true;
         }
         $definition[$fieldName] = $config;
     }
     return $definition;
 }
开发者ID:Maksold,项目名称:platform,代码行数:21,代码来源:CompleteDefinitionByConfig.php

示例9: getDatabaseAssociationMappings

 /**
  * Returns association mapping for a given entity
  *
  * @param ClassMetadata $cm
  * @param bool|false    $bTree
  *
  * @return array
  */
 protected function getDatabaseAssociationMappings(ClassMetadata $cm, $bTree = false)
 {
     $associations = $cm->getAssociationMappings();
     $associationMappings = array();
     foreach ($associations as $association) {
         $getterPlural = false;
         $associationType = $association["type"];
         switch ($association["type"]) {
             case ClassMetadataInfo::MANY_TO_MANY:
                 $associationType = "MANY_TO_MANY";
                 $getterPlural = true;
                 break;
             case ClassMetadataInfo::MANY_TO_ONE:
                 $associationType = "MANY_TO_ONE";
                 $getterPlural = false;
                 break;
             case ClassMetadataInfo::ONE_TO_MANY:
                 $associationType = "ONE_TO_MANY";
                 $getterPlural = true;
                 break;
             case ClassMetadataInfo::ONE_TO_ONE:
                 $associationType = "ONE_TO_ONE";
                 $getterPlural = false;
                 break;
         }
         $getter = "get" . ucfirst($association["fieldName"]);
         $getterField = lcfirst($cm->getReflectionClass()->getShortName()) . str_replace(".", "", $this->convertPHPToExtJSClassName($association["targetEntity"]));
         if ($getterPlural) {
             $getterField .= "s";
         }
         // The self-referencing association may not be written for trees, because ExtJS can't load all nodes
         // in one go.
         if (!($bTree && $association["targetEntity"] == $cm->getName())) {
             $associationMappings[$associationType][] = array("name" => $association["fieldName"], "target" => $this->convertPHPToExtJSClassName($association["targetEntity"]), "getter" => $getter, "getterField" => $getterField);
         }
     }
     return $associationMappings;
 }
开发者ID:fulcrum3d,项目名称:PartKeepr,代码行数:46,代码来源:ReflectionService.php

示例10: collectNestedDataTags

 /**
  * @param mixed         $data
  * @param ClassMetadata $metadata
  *
  * @return array
  */
 protected function collectNestedDataTags($data, ClassMetadata $metadata)
 {
     $tags = [];
     foreach ($metadata->getAssociationMappings() as $fieldName => $mapping) {
         $value = $metadata->reflFields[$fieldName]->getValue($data);
         if (null !== $value) {
             // skip DoctrineTagGenerator#supports() call due to doctrine association mapping always contain entities
             $unwrappedValue = $mapping['type'] & ClassMetadata::TO_ONE ? [$value] : $value->unwrap();
             foreach ($unwrappedValue as $entity) {
                 // allowed one nested level
                 $tags = array_merge($tags, $this->generate($entity));
             }
         }
     }
     return $tags;
 }
开发者ID:Maksold,项目名称:platform,代码行数:22,代码来源:DoctrineTagGenerator.php

示例11: registerExpose

 /**
  * A recursive function to process the specified expose fields for a fetch request (GET)
  * @param  array                     $fields         - expose fields to process
  * @param  ORM\QueryBuilder $qb
  * @param  ORM\Mapping\ClassMetadata $classMetaData
  * @param $rootAlias - table alias to be used on SQL query
  * @param  array                     $addedKeyFields
  * @return ORM\QueryBuilder
  */
 protected function registerExpose($fields, ORM\QueryBuilder $qb, ORM\Mapping\ClassMetadata $classMetaData, $rootAlias = null, &$addedKeyFields = [])
 {
     if (empty($fields)) {
         return $qb;
     }
     $rootAlias = is_null($rootAlias) ? self::getAlias($classMetaData->getName()) : $rootAlias;
     $addedKeyFields = (array) $addedKeyFields;
     $ormAssociationMappings = $classMetaData->getAssociationMappings();
     // Process single fields into a partial set - Filter fields not available on class meta data
     $selectFields = $this->getFilteredAssociations($fields, $classMetaData, 'fields');
     // merge required identifier fields with select fields
     $keyFieldDiff = array_diff($classMetaData->getIdentifierFieldNames(), $selectFields);
     if (!empty($keyFieldDiff)) {
         $addedKeyFields = $keyFieldDiff;
         $selectFields = array_merge($selectFields, $keyFieldDiff);
     }
     if (!empty($selectFields)) {
         $qb->addSelect('partial ' . $rootAlias . '.{' . implode(', ', $selectFields) . '}');
     }
     // Process relational field with no deeper expose restrictions
     foreach ($this->getFilteredAssociations($fields, $classMetaData, 'association') as $relationalField) {
         $alias = self::getAlias($ormAssociationMappings[$relationalField]['targetEntity'], $relationalField);
         $qb->leftJoin($rootAlias . '.' . $relationalField, $alias);
         $qb->addSelect($alias);
     }
     foreach ($fields as $key => $value) {
         if (is_array($value) && isset($ormAssociationMappings[$key])) {
             $alias = self::getAlias($ormAssociationMappings[$key]['targetEntity'], $key);
             $qb->leftJoin($rootAlias . '.' . $key, $alias);
             $qb = $this->registerExpose($value, $qb, $this->getEntityManager()->getClassMetadata($ormAssociationMappings[$key]['targetEntity']), $alias, $addedKeyFields[$key]);
         }
     }
     $this->addedKeyFields = $addedKeyFields;
     return $qb;
 }
开发者ID:jdrich,项目名称:drest,代码行数:44,代码来源:AbstractAction.php

示例12: getAssociationFields

 /**
  * @param ClassMetadata $classMetadata
  * @return ForestField[]
  */
 public function getAssociationFields(ClassMetadata $classMetadata)
 {
     $fields = array();
     if (count($classMetadata->getAssociationMappings())) {
         foreach ($classMetadata->getAssociationMappings() as $associationMapping) {
             $association = $this->getFieldForAssociation($associationMapping);
             $fields = array_merge($fields, $association);
         }
     }
     return $fields;
 }
开发者ID:forestadmin,项目名称:forest-php,代码行数:15,代码来源:DoctrineAnalyzer.php

示例13: getAssociations

 /**
  * @param array         $definition
  * @param ClassMetadata $metadata
  * @param string        $version
  * @param string[]      $requestType
  * @param array         $extras
  *
  * @return array
  */
 protected function getAssociations(array $definition, ClassMetadata $metadata, $version, array $requestType, array $extras)
 {
     $associations = $metadata->getAssociationMappings();
     foreach ($associations as $fieldName => $mapping) {
         if (!$this->isAssociationCompletionRequired($fieldName, $definition)) {
             continue;
         }
         $identifierFieldNames = $this->doctrineHelper->getEntityIdentifierFieldNamesForClass($mapping['targetEntity']);
         $config = [ConfigUtil::DEFINITION => [ConfigUtil::EXCLUSION_POLICY => ConfigUtil::EXCLUSION_POLICY_ALL, ConfigUtil::FIELDS => count($identifierFieldNames) === 1 ? reset($identifierFieldNames) : array_fill_keys($identifierFieldNames, null)]];
         if (isset($definition[$fieldName]) && is_array($definition[$fieldName])) {
             $config = array_merge_recursive($config, [ConfigUtil::DEFINITION => $definition[$fieldName]]);
         }
         if ($this->exclusionProvider->isIgnoredRelation($metadata, $fieldName)) {
             $config[ConfigUtil::DEFINITION][ConfigUtil::EXCLUDE] = true;
         }
         $definition[$fieldName] = $config;
     }
     return $definition;
 }
开发者ID:startupz,项目名称:platform-1,代码行数:28,代码来源:CompleteDefinition.php

示例14: createProxyFile

 private function createProxyFile(ClassMetadata $classMetadata)
 {
     $fileName = str_replace('\\', '_', $classMetadata->getName());
     $reflection = $classMetadata->getReflectionClass();
     $filecontent = $this->getFileContent($classMetadata->getName());
     foreach ($reflection->getProperties() as $property) {
         /* @var $property \ReflectionProperty */
         $annotation = $this->getPropertyAnnotation($property);
         if (!is_null($annotation)) {
             $filecontent .= '        $obj->' . $property->getName() . ' = ' . $annotation->getFixture() . "\n";
         }
     }
     foreach ($classMetadata->getAssociationMappings() as $association) {
         $filecontent .= '        $obj->' . $association['fieldName'] . ' = array_key_exists("' . $association['fieldName'] . '", $dpdc) ? $dpdc["' . $association['fieldName'] . '"] : null;' . "\n";
     }
     $filecontent .= '        return $obj;' . "\n" . '    }' . "\n" . '}';
     file_put_contents($this->_cacheDir . DIRECTORY_SEPARATOR . $fileName, $filecontent);
 }
开发者ID:mickaelsteinberg,项目名称:BackBee,代码行数:18,代码来源:Fixture.php

示例15: buildSelectForUpdateQuery

 /**
  * @param EntityRepository $repository
  * @param ORMMetadata $class
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function buildSelectForUpdateQuery(EntityRepository $repository, ORMMetadata $class)
 {
     $qb = $repository->createQueryBuilder('e', 'e.id');
     $i = 0;
     foreach ($class->getAssociationMappings() as $assocMapping) {
         if (!$class->isSingleValuedAssociation($assocMapping['fieldName'])) {
             continue;
         }
         $targetClass = $this->entityManager->getClassMetadata($assocMapping['targetEntity']);
         $alias = substr($assocMapping['fieldName'], 0, 1) . $i++;
         $qb->leftJoin('e.' . $assocMapping['fieldName'], $alias)->addSelect($alias);
         // todo: deeper!
     }
     return $qb;
 }
开发者ID:rohlikcz,项目名称:DoctrineSearch,代码行数:20,代码来源:DefaultEntityRiver.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadata::getAssociationMappings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。