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


PHP ClassMetadata::setIdentifier方法代码示例

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


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

示例1: setModelReference

 /**
  * @param ClassMetadata $class
  * @param array         $reference
  */
 protected function setModelReference(ClassMetadata $class, array $reference)
 {
     $class->setIdentifier($reference['manager'], $reference['field']);
     foreach ($reference['config'] as $name => $config) {
         switch ($name) {
             case 'reference':
                 $class->addRefenceIdentifier($config['manager'], isset($config['referenceField']) ? $config['referenceField'] : $reference['field'], $config['field']);
                 break;
             case 'idGenerator':
                 $class->setManagerReferenceGenerator($config['target-manager']);
                 break;
         }
     }
 }
开发者ID:pokap,项目名称:pool-dbm,代码行数:18,代码来源:YmlDriver.php

示例2: loadMetadataForClass

 /**
  * Load the metadata for the specified class into the provided container.
  *
  * @param string        $className
  * @param ClassMetadata $metadata
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $metadataFactory = $this->getObjectManager()->getMetadataFactory();
     $builder = new ClassMetadataBuilder($metadata);
     $identifiers = array();
     // Get the entity this entity audits
     $metadataClassName = $metadata->getName();
     $metadataClass = new $metadataClassName();
     $auditedClassMetadata = $metadataFactory->getMetadataFor($metadataClass->getAuditedEntityClass());
     $builder->addManyToOne('revisionEntity', 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity');
     $identifiers[] = 'revisionEntity';
     // Add fields from target to audit entity
     foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
         $builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), array('columnName' => $auditedClassMetadata->getColumnName($fieldName), 'nullable' => true, 'quoted' => true));
         if ($auditedClassMetadata->isIdentifier($fieldName)) {
             $identifiers[] = $fieldName;
         }
     }
     foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
         if (!$mapping['isOwningSide'] || isset($mapping['joinTable'])) {
             continue;
         }
         if (isset($mapping['joinTableColumns'])) {
             foreach ($mapping['joinTableColumns'] as $field) {
                 // FIXME:  set data type correct for mapping info
                 $builder->addField($mapping['fieldName'], 'bigint', array('nullable' => true, 'columnName' => $field));
             }
         } elseif (isset($mapping['joinColumnFieldNames'])) {
             foreach ($mapping['joinColumnFieldNames'] as $field) {
                 // FIXME:  set data type correct for mapping info
                 $builder->addField($mapping['fieldName'], 'bigint', array('nullable' => true, 'columnName' => $field));
             }
         } else {
             throw new Exception('Unhandled association mapping');
         }
     }
     $metadata->setTableName($this->getAuditOptions()['audit_table_name_prefix'] . $auditedClassMetadata->getTableName() . $this->getAuditOptions()['audit_table_name_suffix']);
     $metadata->setIdentifier($identifiers);
     return;
 }
开发者ID:api-skeletons,项目名称:zf-doctrine-audit,代码行数:46,代码来源:AuditDriver.php

示例3: extractPropertiesAnnotations

 /**
  * Extract the property annotations.
  *
  * @param \ReflectionProperty[] $reflProperties
  * @param ClassMetadata|\Revinate\SearchBundle\Lib\Search\Mapping\ClassMetadata $metadata
  *
  * @return ClassMetadata|\Revinate\SearchBundle\Lib\Search\Mapping\ClassMetadata
  */
 private function extractPropertiesAnnotations(array $reflProperties, ClassMetadata $metadata)
 {
     foreach ($reflProperties as $reflProperty) {
         foreach ($this->reader->getPropertyAnnotations($reflProperty) as $annotation) {
             foreach ($this->entityFieldAnnotationClasses as $fieldAnnotationClass) {
                 if ($annotation instanceof $fieldAnnotationClass) {
                     if ($annotation instanceof $this->entityIdAnnotationClass) {
                         $metadata->setIdentifier($reflProperty->name);
                     } elseif ($annotation instanceof $this->entityTimeSeriesFieldAnnotationClass) {
                         $metadata->setTimeSeriesField($reflProperty->name);
                     } elseif ($annotation instanceof $this->entityParamAnnotationClass) {
                         $metadata->addParameterMapping($reflProperty, $annotation);
                     } elseif ($annotation instanceof $this->entityParentFieldAnnotationClass) {
                         $metadata->setParentField($reflProperty->name);
                     } elseif ($annotation instanceof $this->entityVersionFieldAnnotationClass) {
                         /** @var Search\VersionField $annotation */
                         $metadata->setVersionField($reflProperty->name);
                         $metadata->setVersionType($annotation->versionType);
                     } else {
                         $metadata->addFieldMapping($reflProperty, $annotation);
                     }
                     continue 2;
                 }
             }
         }
     }
     $id = $metadata->getIdentifier();
     if (empty($id)) {
         throw new \Exception(__METHOD__ . ': Id field must be defined!');
     }
     if ($metadata->timeSeriesScale && !$metadata->getTimeSeriesField()) {
         throw new \Exception(__METHOD__ . ': TimeSeriesField must be defined for a time series index!');
     }
     return $metadata;
 }
开发者ID:revinate,项目名称:search-bundle,代码行数:43,代码来源:AnnotationDriver.php

示例4: loadMetadataForClass


//.........这里部分代码省略.........
         $builder->addField('targetEntityClass', 'string');
         $builder->addField('revisionType', 'string');
         $builder->addField('title', 'string', array('nullable' => true));
         $metadata->setTableName($moduleOptions->getRevisionEntityTableName());
         return;
     }
     // Revision is managed here rather than a separate namespace and driver
     if ($className == 'SoliantEntityAudit\\Entity\\Revision') {
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         $builder->addField('comment', 'text', array('nullable' => true));
         $builder->addField('timestamp', 'datetime');
         // Add association between RevisionEntity and Revision
         $builder->addOneToMany('revisionEntities', 'SoliantEntityAudit\\Entity\\RevisionEntity', 'revision');
         // Add assoication between User and Revision
         $userMetadata = $metadataFactory->getMetadataFor($moduleOptions->getUserEntityClassName());
         $builder->createManyToOne('user', $userMetadata->getName())->addJoinColumn('user_id', $userMetadata->getSingleIdentifierColumnName())->build();
         $metadata->setTableName($moduleOptions->getRevisionTableName());
         return;
     }
     #        $builder->createField('audit_id', 'integer')->isPrimaryKey()->generatedValue()->build();
     $identifiers = array();
     #        $metadata->setIdentifier(array('audit_id'));
     //  Build a discovered many to many join class
     $joinClasses = $moduleOptions->getJoinClasses();
     if (in_array($className, array_keys($joinClasses))) {
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         $builder->addManyToOne('targetRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');
         $builder->addManyToOne('sourceRevisionEntity', 'SoliantEntityAudit\\Entity\\RevisionEntity');
         $metadata->setTableName($moduleOptions->getTableNamePrefix() . $joinClasses[$className]['joinTable']['name'] . $moduleOptions->getTableNameSuffix());
         //            $metadata->setIdentifier($identifiers);
         return;
     }
     // Get the entity this entity audits
     $metadataClassName = $metadata->getName();
     $metadataClass = new $metadataClassName();
     $auditedClassMetadata = $metadataFactory->getMetadataFor($metadataClass->getAuditedEntityClass());
     try {
         $builder->addManyToOne($moduleOptions->getRevisionEntityFieldName(), 'SoliantEntityAudit\\Entity\\RevisionEntity');
     } catch (MappingException $e) {
         // do nothing
     }
     // Compound keys removed in favor of auditId (audit_id)
     $identifiers[] = $moduleOptions->getRevisionEntityFieldName();
     // Add fields from target to audit entity
     foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
         $fieldMapping = $auditedClassMetadata->getFieldMapping($fieldName);
         if (!isset($fieldMapping['inherited']) && !isset($fieldMapping['declared'])) {
             $fieldMapping['nullable'] = true;
             $fieldMapping['quoted'] = true;
             $builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), $fieldMapping);
         }
         if ($auditedClassMetadata->isIdentifier($fieldName)) {
             $identifiers[] = $fieldName;
         }
     }
     foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
         if (!isset($mapping['inherited']) && !isset($mapping['declared'])) {
             if (!$mapping['isOwningSide']) {
                 continue;
             }
             if (isset($mapping['joinTable'])) {
                 continue;
             }
             if (isset($mapping['joinTableColumns'])) {
                 foreach ($mapping['joinTableColumns'] as $field) {
                     $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
                 }
             } elseif (isset($mapping['joinColumnFieldNames'])) {
                 foreach ($mapping['joinColumnFieldNames'] as $field) {
                     $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
                 }
             } else {
                 throw new \Exception('Unhandled association mapping');
             }
         }
     }
     if ($auditedClassMetadata->isInheritanceTypeJoined() || $auditedClassMetadata->isInheritanceTypeSingleTable()) {
         $metadata->setInheritanceType($auditedClassMetadata->inheritanceType);
         $metadata->setDiscriminatorColumn($auditedClassMetadata->discriminatorColumn);
         $parentAuditClasses = array();
         $subAuditClasses = array();
         foreach ($auditedClassMetadata->parentClasses as $idx => $parentClass) {
             $parentAuditClass = 'SoliantEntityAudit\\Entity\\' . str_replace('\\', '_', $parentClass);
             $parentAuditClasses[$idx] = $parentAuditClass;
         }
         $metadata->setParentClasses($parentAuditClasses);
         foreach ($auditedClassMetadata->subClasses as $idx => $subClass) {
             $subAuditClass = 'SoliantEntityAudit\\Entity\\' . str_replace('\\', '_', $subClass);
             $subAuditClasses[$idx] = $subAuditClass;
         }
         $metadata->setSubClasses($subAuditClasses);
         foreach ($auditedClassMetadata->discriminatorMap as $mapName => $mapClass) {
             $mapAuditClass = 'SoliantEntityAudit\\Entity\\' . str_replace('\\', '_', $mapClass);
             $metadata->addDiscriminatorMapClass($mapName, $mapAuditClass);
         }
     }
     $metadata->setPrimaryTable(array('name' => $moduleOptions->getTableNamePrefix() . $auditedClassMetadata->getTableName() . $moduleOptions->getTableNameSuffix()));
     $metadata->setIdentifier($identifiers);
     return;
 }
开发者ID:VOONWerbeagentur,项目名称:SoliantEntityAudit,代码行数:101,代码来源:AuditDriver.php

示例5: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param ClassMetadata $metadata
  */
 function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $moduleOptions = \ZF\Doctrine\Audit\Module::getModuleOptions();
     $entityManager = $moduleOptions->getEntityManager();
     $metadataFactory = $entityManager->getMetadataFactory();
     $builder = new ClassMetadataBuilder($metadata);
     if ($className == 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity') {
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         $builder->addManyToOne('revision', 'ZF\\Doctrine\\Audit\\Entity\\Revision', 'revisionEntities');
         $builder->addField('entityKeys', 'string');
         $builder->addField('auditEntityClass', 'string');
         $builder->addField('targetEntityClass', 'string');
         $builder->addField('revisionType', 'string');
         $builder->addField('title', 'string', array('nullable' => true));
         $metadata->setTableName($moduleOptions->getRevisionEntityTableName());
         return;
     }
     // Revision is managed here rather than a separate namespace and driver
     if ($className == 'ZF\\Doctrine\\Audit\\Entity\\Revision') {
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         $builder->addField('comment', 'text', array('nullable' => true));
         $builder->addField('timestamp', 'datetime');
         // Add association between RevisionEntity and Revision
         $builder->addOneToMany('revisionEntities', 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity', 'revision');
         // Add assoication between User and Revision
         $userMetadata = $metadataFactory->getMetadataFor($moduleOptions->getUserEntityClassName());
         $builder->createManyToOne('user', $userMetadata->getName())->addJoinColumn('user_id', $userMetadata->getSingleIdentifierColumnName())->build();
         $metadata->setTableName($moduleOptions->getRevisionTableName());
         return;
     }
     #        $builder->createField('audit_id', 'integer')->isPrimaryKey()->generatedValue()->build();
     $identifiers = array();
     #        $metadata->setIdentifier(array('audit_id'));
     //  Build a discovered many to many join class
     $joinClasses = $moduleOptions->getJoinClasses();
     if (in_array($className, array_keys($joinClasses))) {
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         $builder->addManyToOne('targetRevisionEntity', 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity');
         $builder->addManyToOne('sourceRevisionEntity', 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity');
         $metadata->setTableName($moduleOptions->getTableNamePrefix() . $joinClasses[$className]['joinTable']['name'] . $moduleOptions->getTableNameSuffix());
         //            $metadata->setIdentifier($identifiers);
         return;
     }
     // Get the entity this entity audits
     $metadataClassName = $metadata->getName();
     $metadataClass = new $metadataClassName();
     $auditedClassMetadata = $metadataFactory->getMetadataFor($metadataClass->getAuditedEntityClass());
     $builder->addManyToOne($moduleOptions->getRevisionEntityFieldName(), 'ZF\\Doctrine\\Audit\\Entity\\RevisionEntity');
     # Compound keys removed in favor of auditId (audit_id)
     $identifiers[] = $moduleOptions->getRevisionEntityFieldName();
     // Add fields from target to audit entity
     foreach ($auditedClassMetadata->getFieldNames() as $fieldName) {
         $builder->addField($fieldName, $auditedClassMetadata->getTypeOfField($fieldName), array('nullable' => true, 'quoted' => true));
         if ($auditedClassMetadata->isIdentifier($fieldName)) {
             $identifiers[] = $fieldName;
         }
     }
     foreach ($auditedClassMetadata->getAssociationMappings() as $mapping) {
         if (!$mapping['isOwningSide']) {
             continue;
         }
         if (isset($mapping['joinTable'])) {
             continue;
         }
         if (isset($mapping['joinTableColumns'])) {
             foreach ($mapping['joinTableColumns'] as $field) {
                 $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
             }
         } elseif (isset($mapping['joinColumnFieldNames'])) {
             foreach ($mapping['joinColumnFieldNames'] as $field) {
                 $builder->addField($mapping['fieldName'], 'integer', array('nullable' => true, 'columnName' => $field));
             }
         } else {
             throw new \Exception('Unhandled association mapping');
         }
     }
     $metadata->setTableName($moduleOptions->getTableNamePrefix() . $auditedClassMetadata->getTableName() . $moduleOptions->getTableNameSuffix());
     $metadata->setIdentifier($identifiers);
     return;
 }
开发者ID:TomHAnderson,项目名称:SoliantEntityAudit,代码行数:86,代码来源:AuditDriver.php

示例6: extractPropertiesAnnotations

 /**
  * Extract the property annotations.
  *
  * @param \ReflectionProperty[] $reflProperties
  * @param ClassMetadata|\Doctrine\Search\Mapping\ClassMetadata         $metadata
  *
  * @return ClassMetadata|\Doctrine\Search\Mapping\ClassMetadata
  */
 private function extractPropertiesAnnotations(array $reflProperties, ClassMetadata $metadata)
 {
     $documentsFieldAnnotations = array();
     foreach ($reflProperties as $reflProperty) {
         foreach ($this->reader->getPropertyAnnotations($reflProperty) as $annotation) {
             foreach ($this->entityFieldAnnotationClasses as $fieldAnnotationClass) {
                 if ($annotation instanceof $fieldAnnotationClass) {
                     if ($annotation instanceof $this->entityIdAnnotationClass) {
                         $metadata->setIdentifier($reflProperty->name);
                     } elseif ($annotation instanceof $this->entityParamAnnotationClass) {
                         $metadata->addParameterMapping($reflProperty, $annotation);
                     } else {
                         $metadata->addFieldMapping($reflProperty, $annotation);
                     }
                     continue 2;
                 }
             }
         }
     }
     return $metadata;
 }
开发者ID:akleiber,项目名称:search,代码行数:29,代码来源:AnnotationDriver.php

示例7: addFieldMapping

 private function addFieldMapping(ClassMetadataInterface $class, ClassMetadataInterface $parent)
 {
     foreach ($parent->reflFields as $name => $field) {
         $class->reflFields[$name] = $field;
     }
     foreach ($parent->fieldMappings as $name => $field) {
         $class->fieldMappings[$name] = $field;
     }
     foreach ($parent->jsonNames as $name => $field) {
         $class->jsonNames[$name] = $field;
     }
     if ($parent->identifier) {
         $class->setIdentifier($parent->identifier);
     }
 }
开发者ID:doctrine,项目名称:couchdb-odm,代码行数:15,代码来源:ClassMetadataFactory.php


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