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


PHP ClassMetadata::isIdentifier方法代码示例

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


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

 /**
  * {@inheritdoc}
  */
 public function get($key)
 {
     if (!$this->initialized && $this->association['fetch'] === ClassMetadata::FETCH_EXTRA_LAZY && isset($this->association['indexBy'])) {
         if (!$this->typeClass->isIdentifierComposite && $this->typeClass->isIdentifier($this->association['indexBy'])) {
             return $this->em->find($this->typeClass->name, $key);
         }
         return $this->em->getUnitOfWork()->getCollectionPersister($this->association)->get($this, $key);
     }
     return parent::get($key);
 }
开发者ID:karvannan-thi,项目名称:doctrine2,代码行数:13,代码来源:PersistentCollection.php

示例4: get

 /**
  * {@inheritdoc}
  */
 public function get($key)
 {
     if (!$this->initialized && $this->association['type'] === Mapping\ClassMetadataInfo::ONE_TO_MANY && $this->association['fetch'] === Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY && isset($this->association['indexBy'])) {
         if (!$this->typeClass->isIdentifierComposite && $this->typeClass->isIdentifier($this->association['indexBy'])) {
             return $this->em->find($this->typeClass->name, $key);
         }
         return $this->em->getUnitOfWork()->getCollectionPersister($this->association)->get($this, $key);
     }
     $this->initialize();
     return $this->coll->get($key);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:14,代码来源:PersistentCollection.php

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

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

示例7: getPropertyMeta

 /**
  * @return Psc\CMS\EntityPropertyMeta
  */
 public function getPropertyMeta($name, Labeler $labeler = NULL)
 {
     if (!array_key_exists($name, $this->properties)) {
         if (!isset($labeler)) {
             $labeler = new \Psc\CMS\Labeler();
         }
         try {
             $type = $this->getSetMeta()->getFieldType($name);
             // schmeiss exception wenns das property nicht gibt
         } catch (\Psc\Data\FieldNotDefinedException $e) {
             throw \Psc\Doctrine\FieldNotDefinedException::entityField($this->getClass(), $name);
         }
         $this->properties[$name] = $meta = new EntityPropertyMeta($name, $type, $labeler->getLabel($name));
         if ($this->classMetadata->isIdentifier($name) && $this->getClassMetadata()->usesIdGenerator()) {
             $meta->setAutogeneratedValue(TRUE);
         }
     } elseif (isset($labeler)) {
         // update
         $this->properties[$name]->setLabel($labeler->getLabel($name));
     }
     return $this->properties[$name];
 }
开发者ID:pscheit,项目名称:psc-cms,代码行数:25,代码来源:EntityMeta.php

示例8: saveRevisionEntityData

 /**
  * @param ClassMetadata $class
  * @param array $entityData
  * @param string $revType
  */
 private function saveRevisionEntityData($class, $entityData, $revType)
 {
     $params = array($this->getRevisionId(), $revType);
     $types = array(\PDO::PARAM_INT, \PDO::PARAM_STR);
     $fields = array();
     foreach ($class->associationMappings as $field => $assoc) {
         if ($class->isInheritanceTypeJoined() && $class->isInheritedAssociation($field)) {
             continue;
         }
         if (($assoc['type'] & ClassMetadata::TO_ONE) > 0 && $assoc['isOwningSide']) {
             $data = isset($entityData[$field]) ? $entityData[$field] : null;
             $relatedId = false;
             if ($data !== null && $this->uow->isInIdentityMap($data)) {
                 $relatedId = $this->uow->getEntityIdentifier($data);
             }
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) {
                 $fields[$sourceColumn] = true;
                 if ($data === null) {
                     $params[] = null;
                     $types[] = \PDO::PARAM_STR;
                 } else {
                     $params[] = $relatedId ? $relatedId[$targetClass->fieldNames[$targetColumn]] : null;
                     $types[] = $targetClass->getTypeOfColumn($targetColumn);
                 }
             }
         }
     }
     foreach ($class->fieldNames as $field) {
         if (array_key_exists($field, $fields)) {
             continue;
         }
         if ($class->isInheritanceTypeJoined() && $class->isInheritedField($field) && !$class->isIdentifier($field)) {
             continue;
         }
         $params[] = isset($entityData[$field]) ? $entityData[$field] : null;
         $types[] = $class->fieldMappings[$field]['type'];
     }
     if ($class->isInheritanceTypeSingleTable()) {
         $params[] = $class->discriminatorValue;
         $types[] = $class->discriminatorColumn['type'];
     } elseif ($class->isInheritanceTypeJoined() && $class->name == $class->rootEntityName) {
         $params[] = $entityData[$class->discriminatorColumn['name']];
         $types[] = $class->discriminatorColumn['type'];
     }
     if ($class->isInheritanceTypeJoined() && $class->name != $class->rootEntityName && count($class->parentClasses)) {
         if (!isset($entityData[$class->discriminatorColumn['name']])) {
             $entityData[$class->discriminatorColumn['name']] = $class->discriminatorValue;
         }
         $this->saveRevisionEntityData($this->em->getClassMetadata($class->parentClasses[0]), $entityData, $revType);
     }
     $this->conn->executeUpdate($this->getInsertRevisionSQL($class), $params, $types);
 }
开发者ID:hayloft,项目名称:EntityAudit,代码行数:58,代码来源:LogRevisionsListener.php

示例9: testIsIdentifierMappedSuperClass

 /**
  * @group DDC-2700
  */
 public function testIsIdentifierMappedSuperClass()
 {
     $class = new ClassMetadata(__NAMESPACE__ . '\\DDC2700MappedSuperClass');
     $this->assertFalse($class->isIdentifier('foo'));
 }
开发者ID:annProg,项目名称:yourCMDB,代码行数:8,代码来源:ClassMetadataTest.php

示例10: getInsertRevisionSQL

 /**
  * @param ClassMetadata $class
  * @return string
  * @throws \Doctrine\DBAL\DBALException
  */
 private function getInsertRevisionSQL($class)
 {
     if (!isset($this->insertRevisionSQL[$class->name])) {
         $placeholders = array('?', '?');
         $tableName = $this->config->getTablePrefix() . $class->table['name'] . $this->config->getTableSuffix();
         $sql = "INSERT INTO " . $tableName . " (" . $this->config->getRevisionFieldName() . ", " . $this->config->getRevisionTypeFieldName();
         $fields = array();
         foreach ($class->associationMappings as $field => $assoc) {
             if ($class->isInheritanceTypeJoined() && $class->isInheritedAssociation($field)) {
                 continue;
             }
             if (($assoc['type'] & ClassMetadata::TO_ONE) > 0 && $assoc['isOwningSide']) {
                 foreach ($assoc['targetToSourceKeyColumns'] as $sourceCol) {
                     $fields[$sourceCol] = true;
                     $sql .= ', ' . $sourceCol;
                     $placeholders[] = '?';
                 }
             }
         }
         foreach ($class->fieldNames as $field) {
             if (array_key_exists($field, $fields)) {
                 continue;
             }
             if ($class->isInheritanceTypeJoined() && $class->isInheritedField($field) && !$class->isIdentifier($field)) {
                 continue;
             }
             $type = Type::getType($class->fieldMappings[$field]['type']);
             $placeholders[] = !empty($class->fieldMappings[$field]['requireSQLConversion']) ? $type->convertToDatabaseValueSQL('?', $this->platform) : '?';
             $sql .= ', ' . $class->getQuotedColumnName($field, $this->platform);
         }
         if ($class->isInheritanceTypeJoined() && $class->rootEntityName == $class->name || $class->isInheritanceTypeSingleTable()) {
             $sql .= ', ' . $class->discriminatorColumn['name'];
             $placeholders[] = '?';
         }
         $sql .= ") VALUES (" . implode(", ", $placeholders) . ")";
         $this->insertRevisionSQL[$class->name] = $sql;
     }
     return $this->insertRevisionSQL[$class->name];
 }
开发者ID:fatihkahveci,项目名称:EntityAudit,代码行数:44,代码来源:LogRevisionsListener.php

示例11: setProperty

 /**
  * Set entity property value according to meta.
  *
  * @param ClassMetadata $meta
  * @param Entity        $entity
  * @param string        $name
  * @param string        $value
  *
  * @return Entity
  */
 private function setProperty(ClassMetadata $meta, Entity &$entity, $name, $value)
 {
     if ($meta->hasField($name) && !$meta->isIdentifier($name)) {
         $meta->setFieldValue($entity, $name, $value);
     } elseif ($meta->hasAssociation($name)) {
         // We have a single value and there is only one column in association
         if (!is_array($value) && !is_object($value) && $meta->isAssociationWithSingleJoinColumn($name)) {
             $id = [$meta->associationMappings[$name]['joinColumns'][0]['referencedColumnName'] => $value];
             $di = Di::getInstance();
             $linkedEntity = $di->em->find($meta->getAssociationTargetClass($name), $id);
             if (is_null($linkedEntity)) {
                 throw new ClientException('Entity not found for nested entity ' . json_encode(['name' => $name]), ClientException::CODE_NOT_FOUND);
             } else {
                 $meta->setFieldValue($entity, $name, $linkedEntity);
             }
         } else {
             throw new ServerException('Unhandled association type for field ' . $name . ' on ' . $meta->name, ServerException::CODE_NOT_IMPLEMENTED);
         }
     }
 }
开发者ID:petitchevalroux,项目名称:newswatcher-api,代码行数:30,代码来源:JsonApiController.php

示例12: isAutoGeneratedIdField

 /**
  * @param ClassMetadata $meta
  * @param $mapping
  * @return bool
  */
 private function isAutoGeneratedIdField(ClassMetadata $meta, $mapping)
 {
     $isIdentifierField = $meta->isIdentifier($mapping['fieldName']);
     $isAutoGenerated = $meta->generatorType !== ClassMetadata::GENERATOR_TYPE_NONE;
     return $isIdentifierField && $isAutoGenerated;
 }
开发者ID:bitecodes,项目名称:factrine-bundle,代码行数:11,代码来源:ConfigGenerator.php


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