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


PHP ClassMetadata::getFieldNames方法代码示例

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


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

示例1: 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:edwardricardo,项目名称:zenska,代码行数:57,代码来源:EntityPopulator.php

示例2: prepareSet

 /**
  * @param $entity
  * @return array
  */
 protected function prepareSet($entity)
 {
     $data = [];
     foreach ($this->metaData->getFieldNames() as $fieldName) {
         $columnName = $this->metaData->getColumnName($fieldName);
         $type = $this->metaData->getTypeOfField($fieldName);
         $fieldValue = $entity->{$fieldName};
         $type = \Doctrine\DBAL\Types\Type::getType($type);
         $value = $type->convertToDatabaseValue($fieldValue, $this->em->getConnection()->getDatabasePlatform());
         $data[$columnName] = $value;
     }
     return $data;
 }
开发者ID:lynx,项目名称:lynx,代码行数:17,代码来源:DBAL.php

示例3: 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

示例4: addDoctrineFields

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

示例5: getNameLabelField

 /**
  * @param ClassMetadata $meteData
  * @return string
  */
 public function getNameLabelField(ClassMetadata $meteData)
 {
     $fieldNames = $meteData->getFieldNames();
     if (in_array('label', $fieldNames)) {
         return 'label';
     }
     return 'name';
 }
开发者ID:northdakota,项目名称:platform,代码行数:12,代码来源:DictionaryHelper.php

示例6: 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

示例7: getRepresentationField

 /**
  * @param ClassMetadata  $doctrineMetadata
  * @param EntityMetadata $entityMetadata
  *
  * @return string|null
  */
 public function getRepresentationField(ClassMetadata $doctrineMetadata, EntityMetadata $entityMetadata)
 {
     $fieldNames = $doctrineMetadata->getFieldNames();
     if (isset($entityMetadata->defaultValues['dictionary']['representation_field'])) {
         $representationField = $entityMetadata->defaultValues['dictionary']['representation_field'];
         if (in_array($representationField, $fieldNames)) {
             return $representationField;
         }
     }
     return null;
 }
开发者ID:sagikazarmark,项目名称:platform,代码行数:17,代码来源:DictionaryHelper.php

示例8: addDoctrineFields

 /**
  * @param EntityMetadata $entityMetadata
  * @param ClassMetadata $classMetadata
  */
 protected function addDoctrineFields(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
 {
     $identifierFields = $classMetadata->getIdentifierFieldNames();
     foreach ($classMetadata->getFieldNames() as $fieldName) {
         if (in_array($fieldName, $identifierFields)) {
             continue;
         }
         $fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $classMetadata->getFieldMapping($fieldName));
         $entityMetadata->addFieldMetadata($fieldMetadata);
     }
 }
开发者ID:ramunasd,项目名称:platform,代码行数:15,代码来源:MetadataBuilder.php

示例9: process

 private function process(ClassMetadata $metadata, Builder $builder)
 {
     foreach ($metadata->getFieldNames() as $fname) {
         if ($metadata->isIdentifier($fname)) {
             $builder->none($fname);
         } elseif (!$builder->has($fname)) {
             $mapping = $metadata->fieldMappings[$fname];
             $this->makeField($mapping, $builder);
         }
     }
 }
开发者ID:bravesheep,项目名称:dogmatist,代码行数:11,代码来源:DoctrineGuesser.php

示例10: transport

 /**
  * Задает параметры для "получателя данных для ExtJS"
  *
  * @param ClassMetadata $classMetadata
  * @param ParamFetcherInterface $paramFetcher
  * @param GathererInterface $dataGatherer
  *
  * @throws \LogicException
  */
 public static function transport(ClassMetadata $classMetadata, ParamFetcherInterface $paramFetcher, GathererInterface &$dataGatherer)
 {
     $dataGatherer->setPage((int) $paramFetcher->get('page'));
     $dataGatherer->setStartIndex((int) $paramFetcher->get('start'));
     $dataGatherer->setLimit((int) $paramFetcher->get('limit'));
     $additionalFilters = self::getAdditionalFiltersFromJSONString($paramFetcher->get('additional_filter'));
     foreach ($additionalFilters as $additFilter) {
         if (!in_array($additFilter->getField(), $classMetadata->getFieldNames())) {
             throw new \LogicException("AdditionalFilter пытается фильтровать сущность '{$classMetadata->getName()}' по несуществующему полю '{$additFilter->getField()}'");
         }
     }
     $dataGatherer->addAdditionalFilters($additionalFilters);
     $sorters = self::getSortersFromJSONString($paramFetcher->get('sort'));
     foreach ($sorters as $sorter) {
         if (!in_array($sorter->getProperty(), $classMetadata->getFieldNames())) {
             throw new \LogicException("Sorter пытается сортировать сущность '{$classMetadata->getName()}' по несуществующему полю '{$sorter->getProperty()}'");
         }
     }
     $dataGatherer->addSorters($sorters);
     $dataGatherer->addFilters(self::getFiltersFromJSONString($paramFetcher->get('filter')));
 }
开发者ID:amstaffix,项目名称:extjs-rest-common-bundle,代码行数:30,代码来源:ParamFetcherToEntityGathererTransporter.php

示例11: 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

示例12: createFieldsFormatters

 public function createFieldsFormatters($columnTypeGuesser, $generator)
 {
     $formatters = array();
     $nameGuesser = new Name($generator);
     foreach ($this->class->getFieldNames() as $fieldName) {
         //echo "pola standardowe: " . $fieldName . "\n";
         if ($this->class->isIdentifier($fieldName) || !$this->class->hasField($fieldName)) {
             //echo "pola standardowe kończę: " . $fieldName . "\n";
             continue;
         }
         //echo "pola standardowe dalej: " . $fieldName . "\n";
         if ($formatter = $nameGuesser->guessFormat($fieldName)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     return $formatters;
 }
开发者ID:TMSolution,项目名称:GeneratorBundle,代码行数:22,代码来源:EntityPopulator.php

示例13: 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

示例14: getFields

 /**
  * @param array         $definition
  * @param ClassMetadata $metadata
  * @param string        $version
  * @param string[]      $requestType
  * @param array         $extras
  *
  * @return array
  */
 protected function getFields(array $definition, ClassMetadata $metadata, $version, array $requestType, array $extras)
 {
     $fieldNames = $metadata->getFieldNames();
     foreach ($fieldNames as $fieldName) {
         if (array_key_exists($fieldName, $definition)) {
             // already defined
             continue;
         }
         $config = $this->fieldConfigProvider->getFieldConfig($metadata->name, $fieldName, $version, $requestType, $extras);
         if ($this->exclusionProvider->isIgnoredField($metadata, $fieldName)) {
             $config[ConfigUtil::DEFINITION][ConfigUtil::EXCLUDE] = true;
         }
         $definition[$fieldName] = $config;
     }
     return $definition;
 }
开发者ID:startupz,项目名称:platform-1,代码行数:25,代码来源:CompleteDefinition.php

示例15: getFieldsMetadata

 public function getFieldsMetadata($class, $group = 'default')
 {
     $result = array();
     foreach ($this->ormMetadata->getFieldNames() as $name) {
         $mapping = $this->ormMetadata->getFieldMapping($name);
         //  $mapping['isAssociation']=false;
         $values = array('title' => $name, 'source' => true);
         if (isset($mapping['fieldName'])) {
             $values['field'] = $mapping['fieldName'];
             $values['id'] = $mapping['fieldName'];
         }
         if (isset($mapping['id']) && $mapping['id'] == 'id') {
             $values['primary'] = true;
         }
         switch ($mapping['type']) {
             case 'string':
             case 'text':
                 $values['type'] = 'text';
                 break;
             case 'integer':
             case 'smallint':
             case 'bigint':
             case 'float':
             case 'decimal':
                 $values['type'] = 'number';
                 break;
             case 'boolean':
                 $values['type'] = 'boolean';
                 break;
             case 'date':
                 $values['type'] = 'date';
                 break;
             case 'datetime':
                 $values['type'] = 'datetime';
                 break;
             case 'time':
                 $values['type'] = 'time';
                 break;
             case 'array':
             case 'object':
                 $values['type'] = 'array';
                 break;
         }
         $result[$name] = $values;
     }
     return $result;
 }
开发者ID:TMSolution,项目名称:DataGridBundle,代码行数:47,代码来源:Entity.php


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