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


PHP ClassMetadata::getTypeOfField方法代码示例

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


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

示例1: setPropertyType

 protected function setPropertyType(DoctrineClassMetadata $doctrineMetadata, PropertyMetadata $propertyMetadata)
 {
     /** @var \Doctrine\ODM\PHPCR\Mapping\ClassMetadata $doctrineMetadata */
     $propertyName = $propertyMetadata->name;
     if ($doctrineMetadata->hasField($propertyName) && ($fieldType = $this->normalizeFieldType($doctrineMetadata->getTypeOfField($propertyName)))) {
         $field = $doctrineMetadata->getFieldMapping($propertyName);
         if (!empty($field['multivalue'])) {
             $fieldType = 'array';
         }
         $propertyMetadata->setType($fieldType);
     } elseif ($doctrineMetadata->hasAssociation($propertyName)) {
         try {
             $targetEntity = $doctrineMetadata->getAssociationTargetClass($propertyName);
         } catch (\Exception $e) {
             return;
         }
         if (null === $this->tryLoadingDoctrineMetadata($targetEntity)) {
             return;
         }
         if (!$doctrineMetadata->isSingleValuedAssociation($propertyName)) {
             $targetEntity = "ArrayCollection<{$targetEntity}>";
         }
         $propertyMetadata->setType($targetEntity);
     }
 }
开发者ID:alekitto,项目名称:serializer,代码行数:25,代码来源:DoctrinePHPCRTypeLoader.php

示例2: hydrate

 /**
  * Hydrate $object with the provided $data.
  *
  * @param  array  $data
  * @param  object $object
  * @throws \Exception
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     $this->metadata = $this->objectManager->getClassMetadata(get_class($object));
     $object = $this->tryConvertArrayToObject($data, $object);
     foreach ($data as $field => &$value) {
         $value = $this->hydrateValue($field, $value);
         if ($value === null) {
             continue;
         }
         // @todo DateTime (and other types) conversion should be handled by doctrine itself in future
         if (in_array($this->metadata->getTypeOfField($field), array('datetime', 'time', 'date'))) {
             if (is_int($value)) {
                 $dt = new DateTime();
                 $dt->setTimestamp($value);
                 $value = $dt;
             } elseif (is_string($value)) {
                 $value = new DateTime($value);
             }
         }
         if ($this->metadata->hasAssociation($field)) {
             $target = $this->metadata->getAssociationTargetClass($field);
             if ($this->metadata->isSingleValuedAssociation($field)) {
                 $value = $this->toOne($value, $target);
             } elseif ($this->metadata->isCollectionValuedAssociation($field)) {
                 $value = $this->toMany($value, $target);
                 // Automatically merge collections using helper utility
                 $propertyRefl = $this->metadata->getReflectionClass()->getProperty($field);
                 $propertyRefl->setAccessible(true);
                 $previousValue = $propertyRefl->getValue($object);
                 $value = CollectionUtils::intersectUnion($previousValue, $value);
             }
         }
     }
     return $this->hydrator->hydrate($data, $object);
 }
开发者ID:rrmodi88,项目名称:DoctrineModule,代码行数:43,代码来源:DoctrineObject.php

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

示例4: getTransformerInfo

 /**
  * {@inheritdoc}
  */
 public function getTransformerInfo(ColumnInfoInterface $columnInfo, ClassMetadata $metadata)
 {
     if (!$metadata->hasField($columnInfo->getPropertyPath()) || $this->type != $metadata->getTypeOfField($columnInfo->getPropertyPath())) {
         return;
     }
     return array($this->transformer, array());
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:10,代码来源:TypeGuesser.php

示例5: __construct

 /**
  * Creates a new entity choice list.
  *
  * @param ObjectManager         $manager      An EntityManager instance
  * @param string                $class        The class name
  * @param string                $labelPath    The property path used for the label
  * @param EntityLoaderInterface $entityLoader An optional query builder
  * @param array                 $entities     An array of choices
  * @param string                $groupPath    A property path pointing to the property used
  *                                            to group the choices. Only allowed if
  *                                            the choices are given as flat array.
  */
 public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, $groupPath = null)
 {
     $this->em = $manager;
     $this->entityLoader = $entityLoader;
     $this->classMetadata = $manager->getClassMetadata($class);
     $this->class = $this->classMetadata->getName();
     $this->loaded = is_array($entities) || $entities instanceof \Traversable;
     $identifier = $this->classMetadata->getIdentifierFieldNames();
     if (1 === count($identifier)) {
         $this->idField = $identifier[0];
         $this->idAsValue = true;
         if ('integer' === $this->classMetadata->getTypeOfField($this->idField)) {
             $this->idAsIndex = true;
         }
     }
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $entities = array();
     }
     if (version_compare(Kernel::VERSION, '2.1') <= 0) {
         $this->labelPath = $labelPath ? new DepPropertyPath($labelPath) : null;
         $this->groupPath = $groupPath ? new DepPropertyPath($groupPath) : null;
     } else {
         $this->labelPath = $labelPath ? new PropertyPath($labelPath) : null;
         $this->groupPath = $groupPath ? new PropertyPath($groupPath) : null;
     }
     parent::__construct($entities, array(), array());
 }
开发者ID:geoffreytran,项目名称:zym,代码行数:41,代码来源:MenuChoiceList.php

示例6: __construct

 public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
 {
     $ids = $classMetadata->getIdentifierFieldNames();
     $idType = $classMetadata->getTypeOfField(current($ids));
     $this->om = $om;
     $this->classMetadata = $classMetadata;
     $this->singleId = 1 === count($ids);
     $this->intId = $this->singleId && in_array($idType, array('integer', 'smallint', 'bigint'));
     $this->idField = current($ids);
 }
开发者ID:neteasy-work,项目名称:hkgbf_crm,代码行数:10,代码来源:IdReader.php

示例7: guessFormat

 public function guessFormat($fieldName, ClassMetadata $class)
 {
     //echo "wybrany typ:"  . "\n";
     $generator = $this->generator;
     $type = $class->getTypeOfField($fieldName);
     switch ($type) {
         case 'boolean':
             return function () use($generator) {
                 return $generator->boolean;
             };
         case 'decimal':
             $size = isset($class->fieldMappings[$fieldName]['precision']) ? $class->fieldMappings[$fieldName]['precision'] : 2;
             return function () use($generator, $size) {
                 return $generator->randomNumber($size + 2) / 100;
             };
         case 'smallint':
             return function () {
                 return mt_rand(0, 65535);
             };
         case 'integer':
             return function () {
                 return mt_rand(0, intval('2147483647'));
             };
         case 'bigint':
             return function () {
                 return mt_rand(0, intval('18446744073709551615'));
             };
         case 'float':
             return function () {
                 return mt_rand(0, intval('4294967295')) / mt_rand(1, intval('4294967295'));
             };
         case 'array':
             return array();
         case 'string':
             $size = isset($class->fieldMappings[$fieldName]['length']) ? $class->fieldMappings[$fieldName]['length'] : 255;
             return function () use($generator, $size) {
                 return $generator->text($size);
             };
         case 'text':
             return function () use($generator) {
                 return $generator->text;
             };
         case 'datetime':
         case 'date':
         case 'time':
             return function () use($generator) {
                 return $generator->datetime;
             };
         default:
             // //echo "null ! ".$type."\n";
             // no smart way to guess what the user expects here
             return null;
     }
 }
开发者ID:TMSolution,项目名称:GeneratorBundle,代码行数:54,代码来源:ColumnTypeGuesser.php

示例8: guessFormat

 public function guessFormat($fieldName, ClassMetadata $class)
 {
     $generator = $this->generator;
     $type = $class->getTypeOfField($fieldName);
     switch ($type) {
         case 'boolean':
             return function () use($generator) {
                 return $generator->boolean;
             };
         case 'decimal':
             $size = isset($class->fieldMappings[$fieldName]['precision']) ? $class->fieldMappings[$fieldName]['precision'] : 2;
             return function () use($generator, $size) {
                 return $generator->randomNumber($size + 2) / 100;
             };
         case 'smallint':
             return function () {
                 return mt_rand(0, 65535);
             };
         case 'integer':
             return function () {
                 return mt_rand(0, 4294967295.0);
             };
         case 'bigint':
             return function () {
                 return mt_rand(0, 1.8446744073709552E+19);
             };
         case 'float':
             return function () {
                 return mt_rand(0, 4294967295.0) / mt_rand(1, 4294967295.0);
             };
         case 'string':
             $size = isset($class->fieldMappings[$fieldName]['length']) ? $class->fieldMappings[$fieldName]['length'] : 255;
             return function () use($generator, $size) {
                 return $generator->text($size);
             };
         case 'text':
             return function () use($generator) {
                 return $generator->text;
             };
         case 'datetime':
         case 'date':
         case 'time':
             return function () use($generator) {
                 return $generator->datetime;
             };
         default:
             // no smart way to guess what the user expects here
             return null;
     }
 }
开发者ID:natxet,项目名称:Faker,代码行数:50,代码来源:ColumnTypeGuesser.php

示例9: getEntityColumns

 protected function getEntityColumns(ClassMetadata $metaData)
 {
     $columns = $metaData->getColumnNames();
     $result = array();
     foreach ($columns as $columnName) {
         $type = $this->getColumnTypeValue($metaData->getTypeOfField($columnName));
         if ($metaData->isIdentifier($metaData->getFieldName($columnName))) {
             $type |= TableInterface::PRIMARY_KEY;
             if ($metaData->isIdGeneratorIdentity() || $metaData->isIdGeneratorSequence()) {
                 $type |= TableInterface::AUTO_INCREMENT;
             }
         }
         $result[$columnName] = $type;
     }
     return $result;
 }
开发者ID:seytar,项目名称:psx,代码行数:16,代码来源:EntityAnnotation.php

示例10: __construct

 public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
 {
     $ids = $classMetadata->getIdentifierFieldNames();
     $idType = $classMetadata->getTypeOfField(current($ids));
     $this->om = $om;
     $this->classMetadata = $classMetadata;
     $this->singleId = 1 === count($ids);
     $this->intId = $this->singleId && in_array($idType, array('integer', 'smallint', 'bigint'));
     $this->idField = current($ids);
     // single field association are resolved, since the schema column could be an int
     if ($this->singleId && $classMetadata->hasAssociation($this->idField)) {
         $this->associationIdReader = new self($om, $om->getClassMetadata($classMetadata->getAssociationTargetClass($this->idField)));
         $this->singleId = $this->associationIdReader->isSingleId();
         $this->intId = $this->associationIdReader->isIntId();
     }
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:16,代码来源:IdReader.php

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

示例12: setPropertyType

 protected function setPropertyType(DoctrineClassMetadata $doctrineMetadata, PropertyMetadata $propertyMetadata)
 {
     $propertyName = $propertyMetadata->name;
     if ($doctrineMetadata->hasField($propertyName) && ($fieldType = $this->normalizeFieldType($doctrineMetadata->getTypeOfField($propertyName)))) {
         $propertyMetadata->setType($fieldType);
     } elseif ($doctrineMetadata->hasAssociation($propertyName)) {
         $targetEntity = $doctrineMetadata->getAssociationTargetClass($propertyName);
         if (null === ($targetMetadata = $this->tryLoadingDoctrineMetadata($targetEntity))) {
             return;
         }
         // For inheritance schemes, we cannot add any type as we would only add the super-type of the hierarchy.
         // On serialization, this would lead to only the supertype being serialized, and properties of subtypes
         // being ignored.
         if ($targetMetadata instanceof DoctrineClassMetadata && !$targetMetadata->isInheritanceTypeNone()) {
             return;
         }
         if (!$doctrineMetadata->isSingleValuedAssociation($propertyName)) {
             $targetEntity = "ArrayCollection<{$targetEntity}>";
         }
         $propertyMetadata->setType($targetEntity);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:22,代码来源:DoctrineTypeDriver.php

示例13: __construct

 /**
  * Creates a new entity choice list.
  *
  * @param ObjectManager             $manager           An EntityManager instance
  * @param string                    $class             The class name
  * @param string                    $labelPath         The property path used for the label
  * @param EntityLoaderInterface     $entityLoader      An optional query builder
  * @param array                     $entities          An array of choices
  * @param array                     $preferredEntities An array of preferred choices
  * @param string                    $groupPath         A property path pointing to the property used
  *                                                     to group the choices. Only allowed if
  *                                                     the choices are given as flat array.
  * @param PropertyAccessorInterface $propertyAccessor  The reflection graph for reading property paths.
  */
 public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, array $preferredEntities = array(), $groupPath = null, PropertyAccessorInterface $propertyAccessor = null)
 {
     $this->em = $manager;
     $this->entityLoader = $entityLoader;
     $this->classMetadata = $manager->getClassMetadata($class);
     $this->class = $this->classMetadata->getName();
     $this->loaded = is_array($entities) || $entities instanceof \Traversable;
     $this->preferredEntities = $preferredEntities;
     $identifier = $this->classMetadata->getIdentifierFieldNames();
     if (1 === count($identifier)) {
         $this->idField = $identifier[0];
         $this->idAsValue = true;
         if (in_array($this->classMetadata->getTypeOfField($this->idField), array('integer', 'smallint', 'bigint'))) {
             $this->idAsIndex = true;
         }
     }
     if (!$this->loaded) {
         // Make sure the constraints of the parent constructor are
         // fulfilled
         $entities = array();
     }
     parent::__construct($entities, $labelPath, $preferredEntities, $groupPath, null, $propertyAccessor);
 }
开发者ID:ronaldlunaramos,项目名称:webstore,代码行数:37,代码来源:EntityChoiceList.php

示例14: readMetadata

 /**
  * {@inheritdoc}
  */
 public function readMetadata(ClassMetadata $doctrineMeta, array &$meta)
 {
     if (!isset($meta['updated_at'])) {
         $meta['updatedAt'] = null;
     }
     foreach ($doctrineMeta->getReflectionClass()->getProperties() as $property) {
         $annotation = $this->reader->getPropertyAnnotation($property, UpdatedAt::ANNOTATION);
         if (!$annotation instanceof UpdatedAt) {
             continue;
         }
         if (!empty($meta['updatedAt'])) {
             if ($meta['updatedAt'] === $property->getName()) {
                 continue;
             }
             throw $this->createPropertyAnnotationInvalidException(UpdatedAt::ANNOTATION, $doctrineMeta->getName(), $property->getName(), sprintf('property "%s" is already annotated with this annotation', $meta['updatedAt']));
         }
         $fieldType = $doctrineMeta->getTypeOfField($property->getName());
         if (Type::DATETIME !== $fieldType) {
             throw $this->createPropertyAnnotationInvalidException(UpdatedAt::ANNOTATION, $doctrineMeta->getName(), $property->getName(), sprintf('field must be of type "%s", "%s" provided', Type::DATETIME, $fieldType));
         }
         $meta['updatedAt'] = $property->getName();
     }
 }
开发者ID:darvinstudio,项目名称:darvin-utils,代码行数:26,代码来源:UpdatedAtDriver.php

示例15: guessAttributeParametersScalarField

 /**
  * Return "false" if can't find config for field, "null" if field type is unknown for given field
  * or array with config data for given field
  *
  * @param ClassMetadata $metadata
  * @param $field
  * @return array|bool
  */
 protected function guessAttributeParametersScalarField(ClassMetadata $metadata, $field)
 {
     if ($metadata->hasField($field)) {
         $doctrineType = $metadata->getTypeOfField($field);
         if (!isset($this->doctrineTypeMapping[$doctrineType])) {
             return null;
         }
         return $this->formatResult($this->getLabel($metadata->getName(), $field), $this->doctrineTypeMapping[$doctrineType]['type'], $this->doctrineTypeMapping[$doctrineType]['options']);
     } elseif ($this->entityConfigProvider->hasConfig($metadata->getName(), $field)) {
         $entityConfig = $this->entityConfigProvider->getConfig($metadata->getName(), $field);
         $fieldType = $entityConfig->getId()->getFieldType();
         if (!$metadata->hasAssociation($field)) {
             return $this->formatResult($entityConfig->get('label'), $this->doctrineTypeMapping[$fieldType]['type'], $this->doctrineTypeMapping[$fieldType]['options']);
         }
     }
     return false;
 }
开发者ID:Maksold,项目名称:platform,代码行数:25,代码来源:AttributeGuesser.php


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