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


PHP ClassMetadata::getAssociationNames方法代码示例

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


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

示例1: guessColumnFormatters

 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 ($unique && isset($inserted[$relatedClass])) {
                 $related = null;
                 if (isset($inserted[$relatedClass][$index]) || !$optional) {
                     $related = $inserted[$relatedClass][$index];
                 }
                 $index++;
                 return $related;
             } elseif (isset($inserted[$relatedClass])) {
                 return $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)];
             }
             return null;
         };
     }
     return $formatters;
 }
开发者ID:leloulight,项目名称:ProjectManager,代码行数:52,代码来源:EntityPopulator.php

示例2: convertMetadata

 /**
  * @param ClassMetadata $metadata
  * @return JavaScript\Metadata
  */
 private function convertMetadata(ClassMetadata $metadata)
 {
     $meta = new JavaScript\Metadata();
     $meta->originalName = $metadata->getName();
     $meta->namespace = str_replace('\\', '_', $metadata->getReflectionClass()->getNamespaceName());
     $meta->functionName = $metadata->getReflectionClass()->getShortName();
     $parent = $metadata->getReflectionClass()->getParentClass();
     $meta->superFunctionName = $parent ? $parent->getShortName() : 'DBEntity';
     // Convert fields.
     foreach ($metadata->getFieldNames() as $fieldName) {
         $field = new JavaScript\Field();
         $field->name = $fieldName;
         $field->methodName = ucfirst($fieldName);
         $field->type = $this->convertDoctrineType($metadata->getTypeOfField($fieldName));
         $field->isIdentifier = $metadata->isIdentifier($fieldName);
         $meta->fields[] = $field;
     }
     // Convert associations.
     foreach ($metadata->getAssociationNames() as $assocName) {
         $assoc = new JavaScript\Association();
         $assoc->name = $assocName;
         $assoc->methodName = ucfirst($assocName);
         $assoc->isCollection = $metadata->isCollectionValuedAssociation($assocName);
         $assoc->isSingle = $metadata->isSingleValuedAssociation($assocName);
         $assoc->singleName = Inflector::singularize($assoc->methodName);
         $assoc->invertedField = $metadata->getAssociationMappedByTargetField($assocName);
         $targetClass = new \ReflectionClass($metadata->getAssociationTargetClass($assocName));
         $assoc->singleType = $targetClass->getShortName();
         $assoc->type = $assoc->singleType . ($assoc->isCollection ? '[]' : '');
         $meta->associations[] = $assoc;
     }
     return $meta;
 }
开发者ID:CornyPhoenix,项目名称:JsEntitiesBundle,代码行数:37,代码来源:JsEntityConverter.php

示例3: defaultDefsFromMetadata

 private function defaultDefsFromMetadata()
 {
     $defaultEntity = $this->getEntityMetadata()->newInstance();
     $allFields = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
     foreach ($allFields as $fieldName) {
         if (!isset($this->fieldDefs[$fieldName])) {
             $defaultFieldValue = $this->metadata->getFieldValue($defaultEntity, $fieldName);
             if ($defaultFieldValue !== null) {
                 $this->fieldDefs[$fieldName] = function () use($defaultFieldValue) {
                     return $defaultFieldValue;
                 };
             } else {
                 $this->fieldDefs[$fieldName] = function () {
                     return null;
                 };
             }
         }
     }
 }
开发者ID:breerly,项目名称:factory-girl-php,代码行数:19,代码来源:EntityDef.php

示例4: addExcept

 /**
  * @param string[]|array list of field and association names
  * @param array of pairs [name=>options]. Optional options for non-excluded field/associations
  * @return IBuilder[]
  */
 public function addExcept($excluded, $options = [])
 {
     $names = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
     $names = array_diff($names, $excluded);
     $names = array_filter($names, function ($name) {
         return !$this->shouldSkip($name);
     });
     $builders = [];
     foreach ($names as $name) {
         $builders[$name] = $this->add($name, isset($options[$name]) ? $options[$name] : []);
     }
     return $builders;
 }
开发者ID:librette,项目名称:doctrine-forms,代码行数:18,代码来源:ContainerBuilder.php

示例5: writeItem

 /**
  * {@inheritdoc}
  */
 public function writeItem(array $item)
 {
     $this->counter++;
     $entity = null;
     // If the table was not truncated to begin with, find current entities
     // first
     if (false === $this->truncate) {
         if ($this->index) {
             // If the table has a composite key
             if (!empty($this->compositeKey) && is_array($this->compositeKey)) {
                 $composite = '';
                 foreach ($this->compositeKey as $key => $index) {
                     $composite .= $item[$index];
                 }
                 $value = $composite;
             } else {
                 $value = $item[$this->index];
             }
             $entity = $this->entityRepository->findOneBy(array($this->index => $value));
         } else {
             $entity = $this->entityRepository->find(current($item));
         }
     }
     if (!$entity) {
         $entity = $this->getNewInstance();
     }
     $fieldNames = array_merge($this->entityMetadata->getFieldNames(), $this->entityMetadata->getAssociationNames());
     foreach ($fieldNames as $fieldName) {
         $value = null;
         if (isset($item[$fieldName])) {
             $value = $item[$fieldName];
         } elseif (method_exists($item, 'get' . ucfirst($fieldName))) {
             $value = $item->{'get' . ucfirst($fieldName)};
         }
         if (null === $value) {
             continue;
         }
         if (!$value instanceof \DateTime || $value != $this->entityMetadata->getFieldValue($entity, $fieldName)) {
             $setter = 'set' . ucfirst($fieldName);
             $this->setValue($entity, $value, $setter);
         }
     }
     $this->entityManager->persist($entity);
     if ($this->counter % $this->batchSize == 0) {
         $this->entityManager->flush();
         $this->entityManager->clear($this->entityName);
     }
     return $this;
 }
开发者ID:pclaitte,项目名称:data-import,代码行数:52,代码来源:DoctrineWriter.php

示例6: updateEntity

 /**
  * @param array  $item
  * @param object $entity
  */
 protected function updateEntity(array $item, $entity)
 {
     $fieldNames = array_merge($this->entityMetadata->getFieldNames(), $this->entityMetadata->getAssociationNames());
     foreach ($fieldNames as $fieldName) {
         $value = null;
         if (isset($item[$fieldName])) {
             $value = $item[$fieldName];
         } elseif (method_exists($item, 'get' . ucfirst($fieldName))) {
             $value = $item->{'get' . ucfirst($fieldName)};
         }
         if (null === $value) {
             continue;
         }
         if (!$value instanceof \DateTime || $value != $this->entityMetadata->getFieldValue($entity, $fieldName)) {
             $setter = 'set' . ucfirst($fieldName);
             $this->setValue($entity, $value, $setter);
         }
     }
 }
开发者ID:megamanhxh,项目名称:data-import,代码行数:23,代码来源:DoctrineWriter.php

示例7: getFilteredAssociations

 /**
  * Get filtered associations
  * @param array $fields
  * @param ORM\Mapping\ClassMetadata $classMetaData
  * @param string $type 'fields' or 'association
  * @return array
  */
 protected function getFilteredAssociations(array $fields, ORM\Mapping\ClassMetadata $classMetaData, $type = 'fields')
 {
     // Process relational fields / association with no deeper expose restrictions
     if ($type !== 'fields' && $type !== 'associations') {
         return [];
     }
     $names = $type === 'fields' ? $classMetaData->getFieldNames() : $classMetaData->getAssociationNames();
     return array_filter($fields, function ($offset) use($names) {
         if (!is_array($offset) && in_array($offset, $names)) {
             return true;
         }
         return false;
     });
 }
开发者ID:jdrich,项目名称:drest,代码行数:21,代码来源:AbstractAction.php

示例8: getAssociationNames

 /**
  * Returns entity association names
  *
  * @return string[]
  */
 public function getAssociationNames()
 {
     return $this->metadata->getAssociationNames();
 }
开发者ID:nmallare,项目名称:platform,代码行数:9,代码来源:EntityMetadata.php

示例9: 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 = array())
 {
     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 = array_filter($fields, function ($offset) use($classMetaData) {
         if (!is_array($offset) && in_array($offset, $classMetaData->getFieldNames())) {
             return true;
         }
         return false;
     });
     // 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
     $relationalFields = array_filter($fields, function ($offset) use($classMetaData) {
         if (!is_array($offset) && in_array($offset, $classMetaData->getAssociationNames())) {
             return true;
         }
         return false;
     });
     foreach ($relationalFields 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:steve-todorov,项目名称:drest,代码行数:55,代码来源:AbstractAction.php

示例10: addDoctrineAssociations

 /**
  * @param EntityMetadata $entityMetadata
  * @param ClassMetadata $classMetadata
  */
 protected function addDoctrineAssociations(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
 {
     $associations = array_diff($classMetadata->getAssociationNames(), $this->getDeletedFields($classMetadata->name));
     foreach ($associations as $fieldName) {
         $fieldMetadata = $this->metadataFactory->createFieldMetadata(['field_name' => $fieldName], $classMetadata->getAssociationMapping($fieldName));
         $entityMetadata->addFieldMetadata($fieldMetadata);
     }
 }
开发者ID:startupz,项目名称:platform-1,代码行数:12,代码来源:MetadataBuilder.php

示例11: getIndexedAssociations

 /**
  * Gets a list of all indexed associations
  *
  * @param ClassMetadata $metadata
  *
  * @return array [field name => target field data-type, ...]
  */
 public function getIndexedAssociations(ClassMetadata $metadata)
 {
     $relations = [];
     $fieldNames = $metadata->getAssociationNames();
     foreach ($fieldNames as $fieldName) {
         $mapping = $metadata->getAssociationMapping($fieldName);
         if ($mapping['type'] & ClassMetadata::TO_ONE) {
             $targetMetadata = $this->getEntityMetadataForClass($mapping['targetEntity']);
             $targetIdFieldNames = $targetMetadata->getIdentifierFieldNames();
             if (count($targetIdFieldNames) === 1) {
                 $relations[$fieldName] = $targetMetadata->getTypeOfField(reset($targetIdFieldNames));
             }
         }
     }
     return $relations;
 }
开发者ID:Maksold,项目名称:platform,代码行数:23,代码来源:DoctrineHelper.php


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