當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ClassMetadata::setTableName方法代碼示例

本文整理匯總了PHP中Doctrine\Common\Persistence\Mapping\ClassMetadata::setTableName方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassMetadata::setTableName方法的具體用法?PHP ClassMetadata::setTableName怎麽用?PHP ClassMetadata::setTableName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\Common\Persistence\Mapping\ClassMetadata的用法示例。


在下文中一共展示了ClassMetadata::setTableName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

示例2: loadMetadataForClass

 /**
  * Loads the metadata for the specified class into the provided container.
  *
  * @param string $className
  * @param ClassMetadata $metadata
  */
 function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $moduleOptions = \SoliantEntityAudit\Module::getModuleOptions();
     $entityManager = $moduleOptions->getEntityManager();
     $metadataFactory = $entityManager->getMetadataFactory();
     $builder = new ClassMetadataBuilder($metadata);
     if ($className == 'SoliantEntityAudit\\Entity\\RevisionEntity') {
         $builder->createField('id', 'integer')->isPrimaryKey()->generatedValue()->build();
         $builder->addManyToOne('revision', 'SoliantEntityAudit\\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 == '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);
//.........這裏部分代碼省略.........
開發者ID:VOONWerbeagentur,項目名稱:SoliantEntityAudit,代碼行數:101,代碼來源:AuditDriver.php

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


注:本文中的Doctrine\Common\Persistence\Mapping\ClassMetadata::setTableName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。