getMetadataFactory() public method

Gets the metadata factory used to gather the metadata of classes.
public getMetadataFactory ( ) : Doctrine\ORM\Mapping\ClassMetadataFactory
return Doctrine\ORM\Mapping\ClassMetadataFactory
 public static function getMetadata()
 {
     /** @var EntityManagerInterface $em */
     static::$em = static::$kernel->getContainer()->get('doctrine')->getManager();
     $metadata = static::$em->getMetadataFactory()->getAllMetadata();
     return $metadata;
 }
 public function convert($cacheDir)
 {
     $fs = new Filesystem();
     $targetDir = $cacheDir . '/js_entities';
     $webDir = $this->kernel->getRootDir() . '/../web/js';
     $fs->mkdir($targetDir);
     $fs->mkdir($webDir);
     $namespaces = [];
     $metas = $this->entityManager->getMetadataFactory()->getAllMetadata();
     foreach ($metas as $metadata) {
         $meta = $this->convertMetadata($metadata);
         $directory = $targetDir . '/' . $meta->namespace;
         $fs->mkdir($directory);
         $meta->filename = $directory . '/' . $meta->functionName . '.js';
         $this->generator->generateEntity($meta);
         if (!isset($namespaces[$meta->namespace])) {
             $namespaces[$meta->namespace] = array();
         }
         $namespaces[$meta->namespace][] = $meta;
     }
     foreach ($namespaces as $namespace => $metas) {
         $targetFile = $targetDir . '/' . $namespace . '.js';
         $webFile = $webDir . '/' . $namespace . '.js';
         $this->generator->generateNamespace($namespace, $metas, $targetFile);
         $fs->copy($targetFile, $webFile);
     }
 }
 /**
  * @param LoadClassMetadataEventArgs $args
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $this->em = $args->getEntityManager();
     $this->meta = $args->getClassMetadata();
     if (!$this->em->getConnection()->getWrappedConnection() instanceof AbstractConnection) {
         return;
     }
     if ($this->meta->customPersisterClassName === null) {
         $this->meta->setCustomPersisterClass(EntityPersister::class);
     }
     $this->markIndex();
     foreach ($this->meta->fieldMappings as $property => &$mapping) {
         $this->remapIdentifier($property, $mapping);
         $this->remapVersion($property, $mapping);
         $this->markField($property, $mapping);
     }
     foreach ($this->meta->associationMappings as $property => &$mapping) {
         $this->remapAnyToOneAssociation($property, $mapping);
         $this->remapAnyToManyAssociation($property, $mapping);
         $this->remapManyToManyAssociation($property, $mapping);
     }
     if ($cache = $this->em->getMetadataFactory()->getCacheDriver()) {
         $cache->save($this->meta->name . '$CLASSMETADATA', $this->meta, null);
     }
 }
 /**
  * Reads extension metadata
  * 
  * @param ClassMetadataInfo $meta
  * @return array - the metatada configuration
  */
 public function getExtensionMetadata(ClassMetadataInfo $meta)
 {
     if ($meta->isMappedSuperclass) {
         return;
         // ignore mappedSuperclasses for now
     }
     $config = array();
     // collect metadata from inherited classes
     foreach (array_reverse(class_parents($meta->name)) as $parentClass) {
         // read only inherited mapped classes
         if ($this->_em->getMetadataFactory()->hasMetadataFor($parentClass)) {
             $this->_driver->readExtendedMetadata($this->_em->getClassMetadata($parentClass), $config);
         }
     }
     $this->_driver->readExtendedMetadata($meta, $config);
     $this->_driver->validateFullMetadata($meta, $config);
     if ($config) {
         // cache the metadata
         $cacheId = self::getCacheId($meta->name, $this->_extensionNamespace);
         if ($cacheDriver = $this->_em->getMetadataFactory()->getCacheDriver()) {
             $cacheDriver->save($cacheId, $config, null);
         }
     }
     return $config;
 }
 /**
  * @throws \Doctrine\ORM\ORMException
  */
 public function boot()
 {
     $this->serializer = SerializerBuilder::create()->setDebug($this->devMode)->build();
     $this->entityFolder->create();
     AnnotationRegistry::registerAutoloadNamespace('JMS\\Serializer\\Annotation', __DIR__ . '/../../../../vendor/jms/serializer/src');
     $proxyDoctrineFolder = new Folder(sys_get_temp_dir() . '/doctrine');
     $config = Setup::createAnnotationMetadataConfiguration([$this->entityFolder->absolute()], $this->isDevMode(), $proxyDoctrineFolder->absolute());
     if ($this->cache !== null) {
         $config->setQueryCacheImpl($this->getCache());
         $config->setResultCacheImpl($this->getCache());
     }
     $this->entityManager = $this->createEntityManager($config);
     $debugStack = new DebugStack();
     $this->entityManager->getConnection()->getConfiguration()->setSQLLogger($debugStack);
     if ($this->getFileCreation()->getContent() == 1) {
         return;
     }
     if ($proxyDoctrineFolder->isFolder()) {
         $proxyDoctrineFolder->removeFiles();
     }
     $tool = new SchemaTool($this->entityManager);
     $metadatas = $this->entityManager->getMetadataFactory()->getAllMetadata();
     $proxyDoctrineFolder->create();
     $this->entityManager->getProxyFactory()->generateProxyClasses($metadatas, $proxyDoctrineFolder->absolute());
     if ($this->cloudFoundryBoot->isInCloudFoundry()) {
         $tool->updateSchema($metadatas);
     } else {
         $tool->createSchema($metadatas);
     }
     $this->getFileCreation()->setContent(1);
 }
Beispiel #6
0
 public function resetDatabase()
 {
     $metadatas = $this->em->getMetadataFactory()->getAllMetadata();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $tool->dropDatabase();
     $tool->createSchema($metadatas);
 }
 public function __construct(EntityManager $em, $currencyClassName)
 {
     $this->em = $em;
     $this->currencyClassName = $currencyClassName;
     if (!$currencyClassName || !$this->em->getMetadataFactory()->hasMetadataFor($currencyClassName) && !$this->em->getClassMetadata($currencyClassName)) {
         throw new \Exception("Class for currency \"{$currencyClassName}\" not found");
     }
 }
Beispiel #8
0
 protected function init()
 {
     $this->em = $this->app['em'];
     $this->connection = $this->em->getConnection();
     $this->schemaManager = $this->em->getConnection()->getSchemaManager();
     $this->schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $this->validator = new \Doctrine\ORM\Tools\SchemaValidator($this->em);
     $this->metadatas = $this->em->getMetadataFactory()->getAllMetadata();
 }
 /**
  * @return null
  */
 protected function generateSchema()
 {
     $metadatas = $this->em->getMetadataFactory()->getAllMetadata();
     if (!empty($metadatas)) {
         $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
         $tool->dropSchema($metadatas);
         $tool->createSchema($metadatas);
     }
 }
 private function createSchema()
 {
     $this->getProvider()->deleteDatabase($this->getDatabaseName());
     $schemaTool = new SchemaTool($this->entityManager);
     $schemaTool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
     $this->loadFixtures();
     $this->getProvider()->backupDatabase($this->getDatabaseName());
     self::$schemaExists = true;
 }
Beispiel #11
0
 /**
  * @return array
  */
 protected function getEntityClassesFromEntityManager()
 {
     $entityClasses = [];
     $metaData = $this->entityManager->getMetadataFactory()->getAllMetadata();
     foreach ($metaData as $classMetaData) {
         $entityClasses[] = $classMetaData->getName();
     }
     return $entityClasses;
 }
 /**
  * @return ChoiceQuestion
  */
 protected function getManagedEntities()
 {
     $metadata = $this->em->getMetadataFactory()->getAllMetadata();
     $entities = [];
     /** @var ClassMetadata $meta */
     foreach ($metadata as $index => $meta) {
         $entities[$index] = $meta->getReflectionClass()->getName();
     }
     return $entities;
 }
Beispiel #13
0
 public function setUp()
 {
     $dbParams = array('dbname' => 'metamodel_test', 'memory' => 'true', 'driver' => 'pdo_sqlite');
     $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/Fixture"), true);
     $this->em = EntityManager::create($dbParams, $config);
     $tool = new SchemaTool($this->em);
     $tool->createSchema($this->em->getMetadataFactory()->getAllMetadata());
     $this->metaModel = new MetaModel();
     $this->metaModel->addObjectManager(new EntityManagerBridge($this->em));
 }
 /**
  * Returns a list of all registered entities, converted to the ExtJS naming scheme (. instead of \)
  *
  * @return array
  */
 public function getEntities()
 {
     $entities = array();
     $meta = $this->em->getMetadataFactory()->getAllMetadata();
     foreach ($meta as $m) {
         /** @var ClassMetadata $m */
         $entities[] = $this->convertPHPToExtJSClassName($m->getName());
     }
     return $entities;
 }
 protected function setUp()
 {
     parent::setUp();
     if (!isset(static::$_sharedConn)) {
         static::$_sharedConn = $this->_getDefaultConnection();
     }
     $this->_em = $this->_getTestEntityManager(static::$_sharedConn);
     $this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
     $this->_schemaTool->createSchema($this->_em->getMetadataFactory()->getAllMetadata());
 }
Beispiel #16
0
 public function getTargetAssociationMapping($target)
 {
     $className = get_class($className);
     $associations = $this->em->getMetadataFactory()->getMetadataFor($this->class);
     foreach ($associations as $name => $mapping) {
         if ($className === $mapping['targetEntity']) {
             return $mapping['targetEntity'];
         }
     }
     throw new \OutOfBoundsException("Could not find target entity association mapping for {$className}");
 }
 protected function getEntityManager()
 {
     if ($this->entityManager === null) {
         $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . '/../../../Entity/'), true, null, null, false);
         $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
         $this->entityManager = EntityManager::create($conn, $config);
         $schemaTool = new SchemaTool($this->entityManager);
         $schemaTool->createSchema($this->entityManager->getMetadataFactory()->getAllMetadata());
     }
     return $this->entityManager;
 }
 protected function setUp()
 {
     parent::setUp();
     $this->containerBuilder = new ContainerBuilder();
     $loader = new LexikFixturesMapperExtension();
     $loader->load(array(), $this->containerBuilder);
     $this->em = $this->getMockSqliteEntityManager();
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema($this->em->getMetadataFactory()->getAllMetadata());
 }
 /**
  * @return string[]
  */
 protected function getUpdateQueries()
 {
     $cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl();
     if ($cache instanceof ClearableCache) {
         $cache->deleteAll();
     }
     $schemaTool = new SchemaTool($this->entityManager);
     $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
     $queries = $schemaTool->getUpdateSchemaSql($metadata, TRUE);
     return $queries;
 }
 public function testYamlClosureMapping()
 {
     $meta = $this->em->getClassMetadata(self::YAML_CLOSURE_CATEGORY);
     $cacheId = ExtensionMetadataFactory::getCacheId(self::YAML_CLOSURE_CATEGORY, 'Gedmo\\Tree');
     $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
     $this->assertArrayHasKey('parent', $config);
     $this->assertEquals('parent', $config['parent']);
     $this->assertArrayHasKey('strategy', $config);
     $this->assertEquals('closure', $config['strategy']);
     $this->assertArrayHasKey('closure', $config);
     $this->assertEquals('Tree\\Fixture\\Closure\\CategoryClosure', $config['closure']);
 }
 protected function setUp()
 {
     $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../Entity/'], true, null, null, false);
     $this->manager = EntityManager::create(['driver' => 'pdo_sqlite', 'memory' => true], $config);
     (new SchemaTool($this->manager))->createSchema($this->manager->getMetadataFactory()->getAllMetadata());
     $this->manager->persist(new Person('john', 'John', 11, null));
     $this->manager->persist(new Person('jane', 'Jane', 21, '*****@*****.**'));
     $this->manager->persist(new Person('joey', 'Joey', 31, ''));
     $this->manager->flush();
     $this->manager->clear();
     $this->transformer = SQLTransformerBuilder::make()->build();
 }
 /**
  * @param Bundle $bundle
  * @return ClassMetadata[]
  */
 protected function getBundleMetadata(Bundle $bundle)
 {
     $bundleMetadata = [];
     $metadata = $this->em->getMetadataFactory()->getAllMetadata();
     /** @var ClassMetadata $meta */
     foreach ($metadata as $meta) {
         if (strpos($meta->getName(), $bundle->getNamespace()) !== false) {
             $bundleMetadata[] = $meta;
         }
     }
     return $bundleMetadata;
 }
Beispiel #23
0
 /**
  * @param string $itemClass
  * @return bool
  */
 public function supports($itemClass)
 {
     $itemClass = ltrim($itemClass, '\\');
     /** @var ClassMetadata[] $metadata */
     $metadata = $this->em->getMetadataFactory()->getAllMetadata();
     foreach ($metadata as $meta) {
         if ($meta->name == $itemClass) {
             return true;
         }
     }
     return false;
 }
Beispiel #24
0
 /**
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\Tools\ToolsException
  * @author Andreas Glaser
  */
 protected function setUp()
 {
     $conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'dbname' => ':memory:', 'memory' => true]);
     $config = ORM\Tools\Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../Entity'], true, null, null, false);
     $this->em = EntityManager::create($conn, $config);
     $schemaTools = new ORM\Tools\SchemaTool($this->em);
     $schemaTools->createSchema($this->em->getMetadataFactory()->getAllMetadata());
     $loader = new DataFixtures\Loader();
     $loader->addFixture(new Fixtures\ORM());
     $executor = new DataFixtures\Executor\ORMExecutor($this->em, new DataFixtures\Purger\ORMPurger());
     $executor->execute($loader->getFixtures());
 }
 protected function getConnection()
 {
     if (is_null($this->app)) {
         $this->app = $this->getApplication();
     }
     $this->em = EntityManagerFactory::initializeTestEntityManager($this->app);
     $pdo = $this->em->getConnection()->getWrappedConnection();
     $this->em->clear();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $classes = $this->em->getMetadataFactory()->getAllMetadata();
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     return $this->createDefaultDBConnection($pdo, 'fcms_test');
 }
 /**
  * @param string $className
  * @return array
  */
 public function getResultByClassName($className)
 {
     $catalogNumberByClassName = [];
     $metadata = $this->em->getMetadataFactory()->getMetadataFor($this->getFullClassName($className));
     $identifier = strtoupper(key(array_flip($metadata->getIdentifier())));
     if (count($this->resultSet)) {
         foreach ($this->resultSet as $item) {
             if (!is_null($item[$identifier])) {
                 $catalogNumberByClassName[] = $item['CATALOGNUMBER'];
             }
         }
     }
     return array_unique($catalogNumberByClassName);
 }
 /**
  * Set up test env
  *
  * @return void
  */
 public function setUp()
 {
     $this->eventDispatcher = new EventDispatcher();
     $this->params = new CollectorParamBag();
     $setup = Setup::createAnnotationMetadataConfiguration([ENTITIES], true);
     $this->em = EntityManager::create(['driver' => 'pdo_mysql', 'user' => 'user', 'password' => '', 'dbname' => 'warden'], $setup);
     // Setup Param Bag
     $this->params->add('query_limit', ['type' => 'integer', 'default' => 5, 'limit' => 5, 'value' => null, 'expression' => 'value >= limit']);
     // Sync the schema
     $this->schema = new SchemaTool($this->em);
     $this->schema->updateSchema($this->em->getMetadataFactory()->getAllMetadata(), true);
     // Events
     $this->start = new StartEvent();
     $this->stop = new StopEvent($this->params);
 }
Beispiel #28
0
 /**
  * @return array
  * @throws \Exception
  */
 public function getEntityList()
 {
     $entityList = array();
     /** @var ClassMetadata $entityMetadata */
     foreach ($this->_entityManager->getMetadataFactory()->getAllMetadata() as $entityMetadata) {
         $entityClass = $entityMetadata->getName();
         if (!$this->getEntityHasAdmin($entityClass)) {
             $entityList[] = $entityClass;
         }
     }
     if (!$entityList) {
         throw new \Exception("There is no doctrine entities without admin class in the system");
     }
     return $entityList;
 }
Beispiel #29
0
 public function testYamlClosureMapping()
 {
     if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) {
         $this->markTestSkipped('APC extension is not loaded.');
     }
     $meta = $this->em->getClassMetadata(self::YAML_CLOSURE_CATEGORY);
     $cacheId = ExtensionMetadataFactory::getCacheId(self::YAML_CLOSURE_CATEGORY, 'Gedmo\\Tree');
     $config = $this->em->getMetadataFactory()->getCacheDriver()->fetch($cacheId);
     $this->assertArrayHasKey('parent', $config);
     $this->assertEquals('parent', $config['parent']);
     $this->assertArrayHasKey('strategy', $config);
     $this->assertEquals('closure', $config['strategy']);
     $this->assertArrayHasKey('closure', $config);
     $this->assertEquals('Tree\\Fixture\\Closure\\CategoryClosure', $config['closure']);
 }
 /**
  * {@inheritdoc}
  */
 public function purge()
 {
     $classes = array();
     $metadatas = $this->em->getMetadataFactory()->getAllMetadata();
     foreach ($metadatas as $metadata) {
         if (!$metadata->isMappedSuperclass) {
             $classes[] = $metadata;
         }
     }
     $commitOrder = $this->getCommitOrder($this->em, $classes);
     // Drop association tables first
     $orderedTables = $this->getAssociationTables($commitOrder);
     // Get platform parameters
     $platform = $this->em->getConnection()->getDatabasePlatform();
     // Drop tables in reverse commit order
     for ($i = count($commitOrder) - 1; $i >= 0; --$i) {
         $class = $commitOrder[$i];
         if ($class->isInheritanceTypeSingleTable() && $class->name != $class->rootEntityName || $class->isMappedSuperclass) {
             continue;
         }
         $orderedTables[] = $class->getQuotedTableName($platform);
     }
     $orderedTables = array_diff($orderedTables, $this->excludedTables);
     foreach ($orderedTables as $tbl) {
         if ($this->purgeMode === self::PURGE_MODE_DELETE) {
             $this->em->getConnection()->executeUpdate("DELETE FROM " . $tbl);
         } else {
             $this->em->getConnection()->executeUpdate($platform->getTruncateTableSQL($tbl, true));
         }
     }
 }