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


PHP EntityManager::getClassMetadata方法代码示例

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


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

示例1: setUp

 public function setUp()
 {
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setProxyDir(__DIR__ . '/_files');
     $config->setProxyNamespace('DoctrineExtensions\\LargeCollections\\Proxies');
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     #$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $this->em = \Doctrine\ORM\EntityManager::create($conn, $config);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->createSchema(array($this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Article'), $this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Tag'), $this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Comment')));
     $article = new Article();
     $tag1 = new Tag();
     $tag2 = new Tag();
     $comment1 = new Comment();
     $comment2 = new Comment();
     $article->addComment($comment1);
     $article->addComment($comment2);
     $article->addTag($tag1);
     $article->addTag($tag2);
     $this->em->persist($article);
     $this->em->persist($tag1);
     $this->em->persist($tag2);
     $this->em->persist($comment1);
     $this->em->persist($comment2);
     $this->em->flush();
     $this->articleId = $article->id();
     $this->em->clear();
 }
开发者ID:Credit-Jeeves,项目名称:DoctrineExtensions,代码行数:31,代码来源:LargeCollectionTest.php

示例2: testInvalidToOneJoinColumnSchema

 /**
  * @group DDC-1439
  */
 public function testInvalidToOneJoinColumnSchema()
 {
     $class1 = $this->em->getClassMetadata(__NAMESPACE__ . '\\InvalidEntity1');
     $class2 = $this->em->getClassMetadata(__NAMESPACE__ . '\\InvalidEntity2');
     $ce = $this->validator->validateClass($class2);
     $this->assertEquals(array("The referenced column name 'id' does not have a corresponding field with this column name on the class 'Doctrine\\Tests\\ORM\\Tools\\InvalidEntity1'.", "The join columns of the association 'assoc' have to match to ALL identifier columns of the source entity 'Doctrine\\Tests\\ORM\\Tools\\InvalidEntity2', however 'key3, key4' are missing."), $ce);
 }
开发者ID:ncking,项目名称:doctrine2,代码行数:10,代码来源:SchemaValidatorTest.php

示例3: testconfiguration

 public function testconfiguration()
 {
     $config = new Configuration();
     $config->setCurrentUser($this->ZfcUserMock);
     $prefix = "prefix";
     $config->setTablePrefix($prefix);
     $suffix = "suffix";
     $config->setTableSuffix($suffix);
     $fieldName = "fieldName";
     $config->setRevisionFieldName($fieldName);
     $revisionIdFieldType = "string";
     $config->setRevisionIdFieldType($revisionIdFieldType);
     $tableName = "tableName";
     $config->setRevisionTableName($tableName);
     $revisionTypeFieldName = "string";
     $config->setRevisionTypeFieldName($revisionTypeFieldName);
     $ipaddress = $config->getIpAddress();
     $config->setAuditedEntityClasses(array('ZF2EntityAuditTest\\Entity\\Article', 'ZF2EntityAuditTest\\Entity\\Writer'));
     $config->setNote("default note");
     $this->auditManager = new Manager($config);
     $this->auditManager->registerEvents($this->em->getEventManager());
     /// creating the tables
     $this->schemaTool = $this->getSchemaTool();
     $this->schemaTool->createSchema(array($this->em->getClassMetadata('ZF2EntityAuditTest\\Entity\\Article'), $this->em->getClassMetadata('ZF2EntityAuditTest\\Entity\\Writer')));
     $this->assertInstanceOf("ZfcUser\\Entity\\User", $this->ZfcUserMock);
     $this->assertEquals($prefix, $config->getTablePrefix());
     $this->assertEquals($suffix, $config->getTableSuffix());
     $this->assertEquals($fieldName, $config->getRevisionFieldName());
     $this->assertEquals($tableName, $config->getRevisionTableName());
     $this->assertEquals($revisionIdFieldType, $config->getRevisionIdFieldType());
     $this->assertEquals($revisionTypeFieldName, $config->getRevisionIdFieldType());
     $this->assertEquals($ipaddress, "1.1.1.9");
 }
开发者ID:tawfekov,项目名称:zf2entityaudit,代码行数:33,代码来源:ConfigurationTest.php

示例4: createSchema

 public function createSchema()
 {
     $metas = [];
     foreach (Deployment::instance()->models as $model) {
         $metas[] = $this->entityManager->getClassMetadata($model);
     }
     $this->schemaTool->createSchema($metas);
 }
开发者ID:BGCX261,项目名称:zool-php-framework-svn-to-git,代码行数:8,代码来源:DatabaseController.php

示例5: prepareDBALQuery

 /**
  * Replaces name of tables in DBAL queries
  *
  * @param EntityManager $em
  * @param string        $entityName
  * @param string        $sql
  *
  * @return string
  */
 public static function prepareDBALQuery($em, $entityName, $sql)
 {
     $productMetadata = $em->getClassMetadata($entityName);
     $categoryMapping = $productMetadata->getAssociationMapping('categories');
     $familyMapping = $productMetadata->getAssociationMapping('family');
     $valueMapping = $productMetadata->getAssociationMapping('values');
     $valueMetadata = $em->getClassMetadata($valueMapping['targetEntity']);
     $attributeMapping = $valueMetadata->getAssociationMapping('attribute');
     $attributeMetadata = $em->getClassMetadata($attributeMapping['targetEntity']);
     $familyMetadata = $em->getClassMetadata($familyMapping['targetEntity']);
     $attributeFamMapping = $familyMetadata->getAssociationMapping('attributes');
     return strtr($sql, ['%category_join_table%' => $categoryMapping['joinTable']['name'], '%product_table%' => $productMetadata->getTableName(), '%product_value_table%' => $valueMetadata->getTableName(), '%attribute_table%' => $attributeMetadata->getTableName(), '%family_table%' => $familyMetadata->getTableName(), '%family_attribute_table%' => $attributeFamMapping['joinTable']['name']]);
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:22,代码来源:QueryBuilderUtility.php

示例6: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->em = $this->createTestEntityManager();
     $schemaTool = new SchemaTool($this->em);
     $classes = array($this->em->getClassMetadata(self::SINGLE_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS));
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
 }
开发者ID:rooster,项目名称:symfony,代码行数:15,代码来源:EntityChoiceFieldTest.php

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->em = $this->createTestEntityManager();
     $schemaTool = new SchemaTool($this->em);
     $classes = array($this->em->getClassMetadata('Symfony\\Bundle\\DoctrineBundle\\Tests\\Form\\ValueTransformer\\Tag'));
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
 }
开发者ID:notbrain,项目名称:symfony,代码行数:15,代码来源:EntityToIDTransformerTest.php

示例8: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->em = $this->createTestEntityManager();
     $schemaTool = new SchemaTool($this->em);
     $classes = array($this->em->getClassMetadata(__NAMESPACE__ . '\\Article'));
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
 }
开发者ID:notbrain,项目名称:symfony,代码行数:15,代码来源:DoctrineConverterTest.php

示例9: walkInstanceOfExpression

 /**
  * Walks down an InstanceOfExpression AST node, thereby generating the appropriate SQL.
  *
  * @param InstanceOfExpression
  * @return string The SQL.
  */
 public function walkInstanceOfExpression($instanceOfExpr)
 {
     $sql = '';
     $dqlAlias = $instanceOfExpr->identificationVariable;
     $discrClass = $class = $this->_queryComponents[$dqlAlias]['metadata'];
     $fieldName = null;
     if ($class->discriminatorColumn) {
         $discrClass = $this->_em->getClassMetadata($class->rootEntityName);
     }
     if ($this->_useSqlTableAliases) {
         $sql .= $this->getSQLTableAlias($discrClass->table['name'], $dqlAlias) . '.';
     }
     $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' <> ' : ' = ');
     if ($instanceOfExpr->value instanceof AST\InputParameter) {
         // We need to modify the parameter value to be its correspondent mapped value
         $dqlParamKey = $instanceOfExpr->value->name;
         $paramValue = $this->_query->getParameter($dqlParamKey);
         if (!$paramValue instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
             throw QueryException::invalidParameterType('ClassMetadata', get_class($paramValue));
         }
         $entityClassName = $paramValue->name;
     } else {
         // Get name from ClassMetadata to resolve aliases.
         $entityClassName = $this->_em->getClassMetadata($instanceOfExpr->value)->name;
     }
     if ($entityClassName == $class->name) {
         $sql .= $this->_conn->quote($class->discriminatorValue);
     } else {
         $discrMap = array_flip($class->discriminatorMap);
         $sql .= $this->_conn->quote($discrMap[$entityClassName]);
     }
     return $sql;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:39,代码来源:SqlWalker.php

示例10: walkInstanceOfExpression

 /**
  * Walks down an InstanceOfExpression AST node, thereby generating the appropriate SQL.
  *
  * @param InstanceOfExpression
  * @return string The SQL.
  */
 public function walkInstanceOfExpression($instanceOfExpr)
 {
     $sql = '';
     $dqlAlias = $instanceOfExpr->identificationVariable;
     $discrClass = $class = $this->queryComponents[$dqlAlias]['metadata'];
     if ($class->discriminatorColumn) {
         $discrClass = $this->em->getClassMetadata($class->rootEntityName);
     }
     if ($this->useSqlTableAliases) {
         $sql .= $this->getSQLTableAlias($discrClass->getTableName(), $dqlAlias) . '.';
     }
     $sql .= $class->discriminatorColumn['name'] . ($instanceOfExpr->not ? ' NOT IN ' : ' IN ');
     $sqlParameterList = array();
     foreach ($instanceOfExpr->value as $parameter) {
         if ($parameter instanceof AST\InputParameter) {
             $sqlParameterList[] = $this->walkInputParameter($parameter);
         } else {
             // Get name from ClassMetadata to resolve aliases.
             $entityClassName = $this->em->getClassMetadata($parameter)->name;
             if ($entityClassName == $class->name) {
                 $sqlParameterList[] = $this->conn->quote($class->discriminatorValue);
             } else {
                 $discrMap = array_flip($class->discriminatorMap);
                 if (!isset($discrMap[$entityClassName])) {
                     throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName);
                 }
                 $sqlParameterList[] = $this->conn->quote($discrMap[$entityClassName]);
             }
         }
     }
     $sql .= '(' . implode(', ', $sqlParameterList) . ')';
     return $sql;
 }
开发者ID:bardascat,项目名称:blogify,代码行数:39,代码来源:SqlWalker.php

示例11: getConnection

 public function getConnection()
 {
     $classMetadata = array();
     $this->em = $this->createEntityManager();
     $conn = $this->em->getConnection();
     $pdo = $conn->getWrappedConnection();
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     if (count($this->classes) > 0) {
         foreach ($this->classes as $class) {
             $classMetadata[] = $this->em->getClassMetadata($class);
         }
     } else {
         throw new \Doctrine\ORM\ORMException("No associated classes not yet implemented.");
     }
     $schemaTool->createSchema($classMetadata);
     return $this->createDefaultDBConnection($pdo, $conn->getDatabase());
 }
开发者ID:Edadeal,项目名称:YamlExportBundle,代码行数:17,代码来源:FunctionalTestCase.php

示例12: setUp

 public function setUp()
 {
     $this->Bootstrap = new Bootstrap();
     $this->em = $this->Bootstrap->getServiceManager()->get("doctrine.entitymanager.orm_default");
     /// echo sql logger
     //$this->em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());;
     /// let's create the default user
     $this->ZfcUserMock = $this->createUser();
     $auditConfig = new Configuration();
     $auditConfig->setCurrentUser($this->ZfcUserMock);
     $auditConfig->setAuditedEntityClasses(array('ZF2EntityAuditTest\\Entity\\Article', 'ZF2EntityAuditTest\\Entity\\Writer'));
     $auditConfig->setNote("default note");
     $this->auditManager = new Manager($auditConfig);
     $this->auditManager->registerEvents($this->em->getEventManager());
     /// creating the tables
     $this->schemaTool = $this->getSchemaTool();
     $this->schemaTool->createSchema(array($this->em->getClassMetadata('ZF2EntityAuditTest\\Entity\\Article'), $this->em->getClassMetadata('ZF2EntityAuditTest\\Entity\\Writer')));
 }
开发者ID:tawfekov,项目名称:zf2entityaudit,代码行数:18,代码来源:AuditTest.php

示例13: createBlock

 /**
  * TODO: refactor this
  *
  * @param integer      $ownerId
  * @param string       $type
  * @param integer      $parentId
  * @param integer      $placeholder
  * @param array        $sort
  * @param null|array   $data
  *
  * @throws \Exception
  *
  * @return BlockInterface
  */
 public function createBlock($ownerId, $type, $parentId, $placeholder, $sort, $data = null)
 {
     $owner = $this->find($ownerId);
     $version = $this->getNewVersion($owner);
     $className = $this->em->getClassMetadata($type)->getName();
     $block = new $className();
     $parent = $this->find($parentId ?: $ownerId);
     $block->setRootVersion($version);
     $block->setPosition($placeholder);
     $block->setSort(0);
     // < default, gets recalculated later for entire level
     $block->setSortParent(-1);
     // < need to be calculated when putting in the tree
     // Set owner
     $block->setOwner($owner);
     $owner->addOwning($block);
     $owner->setRootVersion($version);
     // This should replaced with a more hardened function
     if ($data) {
         foreach ($data as $attribute => $value) {
             $method = "set{$attribute}";
             $block->{$method}($value);
         }
     }
     $block->setParent($parent);
     $parent->setRootVersion($version);
     // Save now, rest will be in changeset. All we do is a create a stub entry anyway.
     $this->save($block);
     if (count($sort) > 1) {
         // Replace the zero value in the posted sort array
         // with the newly created id to perform sorting
         $id = $block->getId();
         $sort = array_map(function ($v) use($id) {
             return $v == "" || $v == "0" ? $id : $v;
         }, $sort);
         array_walk($sort, function (&$id) {
             $id = (int) $id;
         });
         $contained = $this->findById($sort, $version);
         if ($contained) {
             $contained = $this->setSortsByDirective($contained, $sort);
             foreach ($contained as $node) {
                 if ($node->getOwner()->getId() == $block->getOwner()->getId()) {
                     $node->setRootVersion($version);
                     $this->save($node);
                 }
             }
         }
     } else {
     }
     return $block;
 }
开发者ID:dzoke,项目名称:Cms,代码行数:66,代码来源:BlockManager.php

示例14: dumpIdentityMap

 /**
  * Dump the contents of the identity map into a stream.
  *
  * @param EntityManager $em
  * @return void
  */
 public function dumpIdentityMap(EntityManager $em)
 {
     $uow = $em->getUnitOfWork();
     $identityMap = $uow->getIdentityMap();
     $fh = fopen($this->file, "x+");
     if (count($identityMap) == 0) {
         fwrite($fh, "Flush Operation [" . $this->context . "] - Empty identity map.\n");
         return;
     }
     fwrite($fh, "Flush Operation [" . $this->context . "] - Dumping identity map:\n");
     foreach ($identityMap as $className => $map) {
         fwrite($fh, "Class: " . $className . "\n");
         foreach ($map as $idHash => $entity) {
             fwrite($fh, " Entity: " . $this->getIdString($entity, $uow) . " " . spl_object_hash($entity) . "\n");
             fwrite($fh, "  Associations:\n");
             $cm = $em->getClassMetadata($className);
             foreach ($cm->associationMappings as $field => $assoc) {
                 fwrite($fh, "   " . $field . " ");
                 $value = $cm->reflFields[$field]->getValue($entity);
                 if ($assoc['type'] & ClassMetadata::TO_ONE) {
                     if ($value === null) {
                         fwrite($fh, " NULL\n");
                     } else {
                         if ($value instanceof Proxy && !$value->__isInitialized__) {
                             fwrite($fh, "[PROXY] ");
                         }
                         fwrite($fh, $this->getIdString($value, $uow) . " " . spl_object_hash($value) . "\n");
                     }
                 } else {
                     $initialized = !$value instanceof PersistentCollection || $value->isInitialized();
                     if ($value === null) {
                         fwrite($fh, " NULL\n");
                     } else {
                         if ($initialized) {
                             fwrite($fh, "[INITIALIZED] " . $this->getType($value) . " " . count($value) . " elements\n");
                             foreach ($value as $obj) {
                                 fwrite($fh, "    " . $this->getIdString($obj, $uow) . " " . spl_object_hash($obj) . "\n");
                             }
                         } else {
                             fwrite($fh, "[PROXY] " . $this->getType($value) . " unknown element size\n");
                             foreach ($value->unwrap() as $obj) {
                                 fwrite($fh, "    " . $this->getIdString($obj, $uow) . " " . spl_object_hash($obj) . "\n");
                             }
                         }
                     }
                 }
             }
         }
     }
     fclose($fh);
 }
开发者ID:pollux1er,项目名称:dlawebdev2,代码行数:57,代码来源:DebugUnitOfWorkListener.php

示例15: setUp

 public function setUp()
 {
     $reader = new \Doctrine\Common\Annotations\AnnotationReader();
     $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setProxyDir(sys_get_temp_dir());
     $config->setProxyNamespace('SimpleThings\\EntityAudit\\Tests\\Proxies');
     $config->setMetadataDriverImpl($driver);
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     $auditConfig = new AuditConfiguration();
     $auditConfig->setCurrentUsername("beberlei");
     $auditConfig->setAuditedEntityClasses(array('SimpleThings\\EntityAudit\\Tests\\ArticleAudit', 'SimpleThings\\EntityAudit\\Tests\\UserAudit'));
     $this->auditManager = new AuditManager($auditConfig);
     $this->auditManager->registerEvents($evm = new EventManager());
     #$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->createSchema(array($this->em->getClassMetadata('SimpleThings\\EntityAudit\\Tests\\ArticleAudit'), $this->em->getClassMetadata('SimpleThings\\EntityAudit\\Tests\\UserAudit')));
 }
开发者ID:CrisMenjivar,项目名称:TesisSIIGv1,代码行数:21,代码来源:FunctionalTest.php


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