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


PHP ClassMetadata::getFieldNames方法代码示例

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


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

示例1: guessColumnFormatters

 public function guessColumnFormatters(\Faker\Generator $generator)
 {
     $formatters = array();
     $class = $this->class;
     $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;
         }
         if ($formatter = $nameGuesser->guessFormat($fieldName)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
         if ($formatter = $columnTypeGuesser->guessFormat($fieldName, $this->class)) {
             $formatters[$fieldName] = $formatter;
             continue;
         }
     }
     foreach ($this->class->getAssociationNames() as $assocName) {
         if (!$this->class->isIdentifier($assocName) || !$this->class->isCollectionValuedAssociation($assocName)) {
             continue;
         }
         $relatedClass = $this->class->getAssociationTargetClass($assocName);
         $formatters[$assocName] = function ($inserted) use($relatedClass) {
             return isset($inserted[$relatedClass]) ? $inserted[$relatedClass][mt_rand(0, count($inserted[$relatedClass]) - 1)] : null;
         };
     }
     return $formatters;
 }
开发者ID:nbremont,项目名称:Faker,代码行数:30,代码来源:EntityPopulator.php

示例2: getEntityFields

 protected function getEntityFields(ClassMetadata $metaData, array $data)
 {
     // change data keys to camelcase
     $result = array();
     foreach ($data as $key => $value) {
         // convert to camelcase if underscore is in name
         if (strpos($key, '_') !== false) {
             $key = implode('', array_map('ucfirst', explode('_', $key)));
         }
         $result[$key] = $value;
     }
     $data = $result;
     // get all fields
     $fieldNames = $metaData->getFieldNames();
     $fields = array();
     foreach ($fieldNames as $fieldName) {
         if (!isset($data[$fieldName])) {
             continue;
         }
         $type = $metaData->getTypeOfField($fieldName);
         $value = $this->getColumnTypeValue($type, $data[$fieldName]);
         $fields[$fieldName] = $value;
     }
     return $fields;
 }
开发者ID:seytar,项目名称:psx,代码行数:25,代码来源:Entity.php

示例3: fieldList

 public function fieldList(ClassMetadata $metadata)
 {
     $return = [];
     foreach ($metadata->getFieldNames() as $field) {
         if ($this->isSerializableField($field, $metadata)) {
             $return[] = $field;
         }
     }
     return $return;
 }
开发者ID:zoopcommerce,项目名称:shard,代码行数:10,代码来源:Serializer.php

示例4: extractByReference

 /**
  * Extract values from an object using a by-reference logic (this means that values are
  * directly fetched without using the public API of the entity, in this case, getters)
  *
  * @param  object $object
  * @return array
  */
 protected function extractByReference($object)
 {
     $fieldNames = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
     $refl = $this->metadata->getReflectionClass();
     $data = array();
     foreach ($fieldNames as $fieldName) {
         $reflProperty = $refl->getProperty($fieldName);
         $reflProperty->setAccessible(true);
         $data[$fieldName] = $this->extractValue($fieldName, $reflProperty->getValue($object));
     }
     return $data;
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:19,代码来源:DoctrineObject.php

示例5: generateConstructor

 /**
  * @param $entity
  * @param ClassMetadata $classMetadata
  * @return array
  */
 private function generateConstructor($entity, $classMetadata)
 {
     $fields = [];
     $fields[] = sprintf("\t\tfunction %s(data) {\n", $entity);
     $fields[] = "\t\t\tif (angular.isDefined(data)) {\n";
     foreach ($classMetadata->getFieldNames() as $item) {
         $item = $this->handleField($item, $classMetadata->getName(), true);
         if ($item !== null) {
             $fields[] = $item;
         }
     }
     $fields[] = "\t\t\t} else {\n";
     foreach ($classMetadata->getFieldNames() as $item) {
         $item = $this->handleField($item, $classMetadata->getName(), false);
         if ($item !== null) {
             $fields[] = $item;
         }
     }
     $fields[] = "\t\t\t}\n";
     $fields[] = "\t\t}\n\n";
     return $fields;
 }
开发者ID:riki343,项目名称:SymfonyAngularEntitiesBundle,代码行数:27,代码来源:EntityConvertCommand.php

示例6: fieldList

 public function fieldList(ClassMetadata $metadata, $includeId = true)
 {
     $return = [];
     $serializerMetadata = $metadata->getSerializer();
     foreach ($metadata->getFieldNames() as $field) {
         if (isset($serializerMetadata['fields'][$field]['unserializeIgnore']) && $serializerMetadata['fields'][$field]['unserializeIgnore']) {
             continue;
         }
         $return[] = $field;
     }
     if (!$includeId) {
         unset($return[$metadata->getIdentifier()]);
     }
     return $return;
 }
开发者ID:zoopcommerce,项目名称:shard,代码行数:15,代码来源:Unserializer.php

示例7: extractByReference

 /**
  * Extract values from an object using a by-reference logic (this means that values are
  * directly fetched without using the public API of the entity, in this case, getters)
  *
  * @param  object $object
  * @return array
  */
 protected function extractByReference($object)
 {
     $fieldNames = array_merge($this->metadata->getFieldNames(), $this->metadata->getAssociationNames());
     $refl = $this->metadata->getReflectionClass();
     $filter = $object instanceof FilterProviderInterface ? $object->getFilter() : $this->filterComposite;
     $data = array();
     foreach ($fieldNames as $fieldName) {
         if ($filter && !$filter->filter($fieldName)) {
             continue;
         }
         $reflProperty = $refl->getProperty($fieldName);
         $reflProperty->setAccessible(true);
         $data[$fieldName] = $this->extractValue($fieldName, $reflProperty->getValue($object), $object);
     }
     return $data;
 }
开发者ID:gstearmit,项目名称:EshopVegeTable,代码行数:23,代码来源:DoctrineObject.php

示例8: getFieldsFromMetadata

 /**
  * Returns an array of fields. Fields can be both column fields and
  * association fields.
  *
  * @param ClassMetadata $metadata
  *
  * @return array $fields
  */
 private function getFieldsFromMetadata(ClassMetadata $metadata)
 {
     $fields = (array) $metadata->getFieldNames();
     if (!$this->isIdentifierNatural($metadata)) {
         $fields = array_diff($fields, $metadata->getIdentifier());
     }
     $fieldsMapping = array();
     foreach ($fields as $field) {
         $fieldsMapping[$field] = $metadata->getTypeOfField($field);
     }
     foreach ($metadata->associationMappings as $fieldName => $relation) {
         if ($relation['type'] !== ORMClassMetadataInfo::ONE_TO_MANY) {
             $fieldsMapping[$fieldName] = 'relation';
         }
     }
     return $fieldsMapping;
 }
开发者ID:malukenho,项目名称:Sylius,代码行数:25,代码来源:DefaultFormFactory.php

示例9: createEntityHydrator

 /**
  * Get the default hydrator
  *
  * @param ClassMetadata     $metadata
  * @param HydratorInterface $hydrator
  *
  * @return HydratorInterface
  */
 private function createEntityHydrator(ClassMetadata $metadata, HydratorInterface $hydrator = null)
 {
     $hydrator = $hydrator ?: new ClassMethods();
     foreach ($metadata->getFieldNames() as $field) {
         switch ($metadata->getTypeOfField($field)) {
             case Type::DATETIME:
                 $hydrator->addStrategy($field, new DateTimeStrategy());
                 break;
             case Type::SIMPLE_ARRAY:
                 $hydrator->addStrategy($field, new SimpleArrayStrategy());
                 break;
             case Type::BOOLEAN:
                 $hydrator->addStrategy($field, new BooleanStrategy());
                 break;
         }
     }
     return $hydrator;
 }
开发者ID:interactive-solutions,项目名称:zf-behat,代码行数:26,代码来源:EntityHydratorTrait.php

示例10: processFieldNames

 /**
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata
  * @param                                                    $model
  *
  * @return array
  */
 protected function processFieldNames(ClassMetadata $metadata, $model)
 {
     $data = array();
     foreach ($metadata->getFieldNames() as $fieldName) {
         if ($metadata->isIdentifier($fieldName) && $metadata->usesIdGenerator()) {
             continue;
         }
         $data[$fieldName] = $this->navigator->accept($this->getVisitor(), $this->readProperty($model, $fieldName));
     }
     return $data;
 }
开发者ID:xijia37,项目名称:fixture-dumper,代码行数:17,代码来源:AbstractGenerator.php

示例11: getEntityEmbeddables

 /**
  * Returns the entity embeddable fields
  *
  * @param ClassMetadata $metadata
  *
  * @return array
  */
 protected function getEntityEmbeddables(ClassMetadata $metadata)
 {
     $entityFields = $metadata->getFieldNames();
     $embeddables = [];
     foreach ($entityFields as $embeddableField) {
         if (false !== strpos($embeddableField, '.')) {
             list($embeddablePropertyName, ) = explode('.', $embeddableField);
             $embeddables[$embeddablePropertyName] = $embeddablePropertyName;
         }
     }
     return $embeddables;
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:19,代码来源:AbstractSerializer.php

示例12: prepareMetadataFields

 protected function prepareMetadataFields(ClassMetadata $metadata)
 {
     $fields = [];
     foreach ($metadata->getFieldNames() as $fieldName) {
         $groups = [];
         list($realName, ) = explode('.', $fieldName);
         if (!in_array($realName, $this->hiddenFields)) {
             $groups = ['default', Inflector::tableize($metadata->getReflectionClass()->getShortName())];
         }
         $fields[$realName]['groups'] = $groups;
     }
     return $fields;
 }
开发者ID:WellCommerce,项目名称:ApiBundle,代码行数:13,代码来源:GenerateSerializationMetadataCommand.php

示例13: buildPhoneFields

 /**
  * @param Common\Persistence\Mapping\ClassMetadata $class
  *
  * @return array
  *
  * @throws ORM\Mapping\MappingException
  */
 private function buildPhoneFields(Common\Persistence\Mapping\ClassMetadata $class)
 {
     $phoneFields = [];
     foreach ($class->getFieldNames() as $fieldName) {
         $mapping = $class->getFieldMapping($fieldName);
         if ($mapping['type'] !== Types\Phone::PHONE) {
             continue;
         }
         $classReflection = $class->isInheritedField($fieldName) ? new \ReflectionClass($mapping['declared']) : $class->getReflectionClass();
         $phoneFields[$fieldName] = ['phoneFieldClass' => $classReflection->getName()];
     }
     return $phoneFields;
 }
开发者ID:iPublikuj,项目名称:doctrine-phone,代码行数:20,代码来源:PhoneObjectSubscriber.php

示例14: 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;
         if ($this->class instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
             $mappings = $this->class->getAssociationMappings();
             foreach ($mappings as $mapping) {
                 if ($mapping['targetEntity'] == $relatedClass) {
                     if ($mapping['type'] == \Doctrine\ORM\Mapping\ClassMetadata::ONE_TO_ONE) {
                         $unique = true;
                         $optional = isset($mapping['joinColumns'][0]['nullable']) ? $mapping['joinColumns'][0]['nullable'] : false;
                         break;
                     }
                 }
             }
         } elseif ($this->class instanceof \Doctrine\ODM\MongoDB\Mapping\ClassMetadata) {
             $mappings = $this->class->associationMappings;
             foreach ($mappings as $mapping) {
                 if ($mapping['targetDocument'] == $relatedClass) {
                     if ($mapping['type'] == \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::ONE && $mapping['association'] == \Doctrine\ODM\MongoDB\Mapping\ClassMetadata::REFERENCE_ONE) {
                         $unique = true;
                         $optional = isset($mapping['nullable']) ? $mapping['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:brainrepo,项目名称:Faker,代码行数:70,代码来源:EntityPopulator.php


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