public function fire() { $this->info('Starting proxy generation....'); // flush all generated and cached entities, etc \D2Cache::flushAll(); try { $metadata = $this->d2em->getMetadataFactory()->getAllMetadata(); } catch (\Doctrine\Common\Persistence\Mapping\MappingException $e) { if ($this->option('verbose') == 3) { throw $e; } $this->error("Caught Doctrine\\Common\\Persistence\\Mapping\\MappingException: " . $e->getMessage()); $this->info("Re-optimizing:"); $this->call('optimize'); $this->comment("*** You must now rerun this artisan command ***"); exit(-1); } if (empty($metadata)) { $this->error('No metadata found to generate entities.'); return -1; } $directory = Config::get('d2doctrine.paths.proxies'); if (!$directory) { $this->error('The proxy directory has not been set.'); return -1; } $this->info('Processing entities:'); foreach ($metadata as $item) { $this->line($item->name); } $this->d2em->getProxyFactory()->generateProxyClasses($metadata, $directory); $this->info('Proxies have been created.'); }
/** * Creates schema for doctrine entities * * @throws \Doctrine\ORM\Tools\ToolsException */ protected function createDoctrineSchema() { $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); $tool = new SchemaTool($this->entityManager); $tool->dropSchema($metadata); $tool->createSchema($metadata); }
/** * Builds the DB Schema * * @return void */ protected function rebuildDatabase() { # 2. Drop the existing database schema $this->schemaTool->dropDatabase(); # 3. Create the new database schema based on (1) $entityMeta = $this->em->getMetadataFactory()->getAllMetadata(); $this->schemaTool->updateSchema($entityMeta); }
/** * {@inheritdoc} */ public function createSchema() { $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); if (empty($metadata)) { throw new \UnexpectedValueException('No mapping information to process'); } $tool = new SchemaTool($this->entityManager); return $tool->getSchemaFromMetadata($metadata); }
public function generateSchema() { $metadatas = $this->em->getMetadataFactory()->getAllMetadata(); if (!empty($metadatas)) { $tool = new \Doctrine\ORM\Tools\SchemaTool($this->om); $tool->dropDatabase(); $tool->dropSchema($metadatas); $tool->createSchema($metadatas); } }
/** * Initializes a new instance of the <tt>ProxyFactory</tt> class that is * connected to the given <tt>EntityManager</tt>. * * @param EntityManagerInterface $em The EntityManager the new factory works for. * @param string $proxyDir The directory to use for the proxy classes. It must exist. * @param string $proxyNs The namespace to use for the proxy classes. * @param boolean|int $autoGenerate The strategy for automatically generating proxy classes. Possible * values are constants of Doctrine\Common\Proxy\AbstractProxyFactory. */ public function __construct(EntityManagerInterface $em, $proxyDir, $proxyNs, $autoGenerate = AbstractProxyFactory::AUTOGENERATE_NEVER) { $proxyGenerator = new ProxyGenerator($proxyDir, $proxyNs); $proxyGenerator->setPlaceholder('baseProxyInterface', 'Doctrine\\ORM\\Proxy\\Proxy'); parent::__construct($proxyGenerator, $em->getMetadataFactory(), $autoGenerate); $this->em = $em; $this->uow = $em->getUnitOfWork(); $this->proxyNs = $proxyNs; $this->identifierFlattener = new IdentifierFlattener($this->uow, $em->getMetadataFactory()); }
public function setUp() { $client = self::createClient(); $this->entityManager = $client->getContainer()->get('doctrine')->getManager(); $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); if (!empty($metadata)) { $tool = new SchemaTool($this->entityManager); $tool->dropSchema($metadata); $tool->createSchema($metadata); } }
/** * {@inheritdoc} */ public function setUp() { $this->connection = new MysqlPersistentConnection(); $params = $this->connection->getConnectionParams(); $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/Entity'], true, null, null, false); $this->em = EntityManager::create($params, $config); // create tables in the database $metadata = $this->em->getMetadataFactory()->getAllMetadata(); $schema_tool = new SchemaTool($this->em); $schema_tool->createSchema($metadata); $this->provider = new EntityMutationMetadataProvider(new AnnotationReader()); }
public static function setUpBeforeClass() { $isDevMode = true; $config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/../../../metadata/TestEntities"), $isDevMode, null, null, false); $connectionOptions = array('driver' => 'pdo_sqlite', 'memory' => true); // obtaining the entity manager self::$em = EntityManager::create($connectionOptions, $config); $schemaTool = new SchemaTool(self::$em); $cmf = self::$em->getMetadataFactory(); $classes = $cmf->getAllMetadata(); $schemaTool->dropDatabase(); $schemaTool->createSchema($classes); }
protected function regenerateSchema() { $this->client = static::createClient(); $container = $this->client->getContainer(); $doctrine = $container->get('doctrine'); $this->em = $doctrine->getManager(); $metadata = $this->em->getMetadataFactory()->getAllMetadata(); /** * Drops current schema and creates a brand new one */ if (!empty($metadata)) { $tool = new SchemaTool($this->em); $tool->dropSchema($metadata); $tool->createSchema($metadata); } }
protected function initOrm(EntityManagerInterface $entityManager) { $schemaTool = new SchemaTool($entityManager); $metadatas = $entityManager->getMetadataFactory()->getAllMetadata(); $schemaTool->dropSchema($metadatas); $schemaTool->createSchema($metadatas); }
/** * Processes an individual parameter value. * * @param mixed $value * * @return array|string * * @throws \Doctrine\ORM\ORMInvalidArgumentException */ public function processParameterValue($value) { if (is_scalar($value)) { return $value; } if ($value instanceof Collection) { $value = $value->toArray(); } if (is_array($value)) { foreach ($value as $key => $paramValue) { $paramValue = $this->processParameterValue($paramValue); $value[$key] = is_array($paramValue) ? reset($paramValue) : $paramValue; } return $value; } if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { $value = $this->_em->getUnitOfWork()->getSingleIdentifierValue($value); if ($value === null) { throw ORMInvalidArgumentException::invalidIdentifierBindingEntity(); } } if ($value instanceof Mapping\ClassMetadata) { return $value->name; } return $value; }
/** * Creates the schema for the managed entities. * * @param EntityManagerInterface $entityManager */ protected function createSchemaForSupportedEntities(EntityManagerInterface $entityManager) { $entityClasses = $this->getEntityClasses(); $entityClasses[] = $this->getRepositoryObjectClass(); $metadata = array_map(function ($className) use($entityManager) { return $entityManager->getMetadataFactory()->getMetadataFor($className); }, $entityClasses); $schemaTool = new SchemaTool($entityManager); $schemaTool->createSchema($metadata); }
/** * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata The entity metadata. * @param mixed $identifier The entity identifier. * * @return array */ private function toIdentifierArray(ClassMetadata $metadata, $identifier) { if (is_object($identifier) && $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($identifier))) { $identifier = $this->uow->getSingleIdentifierValue($identifier); if ($identifier === null) { throw ORMInvalidArgumentException::invalidIdentifierBindingEntity(); } } return array($metadata->identifier[0] => $identifier); }
public function fire() { $this->info('Starting proxy generation....'); $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); if (empty($metadata)) { $this->error('No metadata found to generate any entities.'); exit; } $directory = $this->laravel['config']['doctrine::doctrine.proxy.directory']; if (!$directory) { $this->error('The proxy directory has not been set.'); exit; } $this->info('Processing entities:'); foreach ($metadata as $item) { $this->line($item->name); } $this->entityManager->getProxyFactory()->generateProxyClasses($metadata, $directory); $this->info('Proxies have been created.'); }
public function fire() { $this->info('Starting repository generation....'); // flush all generated and cached entities, etc \D2Cache::flushAll(); try { $metadatas = $this->d2em->getMetadataFactory()->getAllMetadata(); } catch (\Doctrine\Common\Persistence\Mapping\MappingException $e) { if ($this->option('verbose') == 3) { throw $e; } $this->error("Caught Doctrine\\Common\\Persistence\\Mapping\\MappingException: " . $e->getMessage()); $this->info("Re-optimizing:"); $this->call('optimize'); $this->comment("*** You must now rerun this artisan command ***"); exit(-1); } if (empty($metadatas)) { $this->error('No metadata found to generate entities.'); return -1; } $directory = Config::get('d2bdoctrine.paths.repositories'); if (!$directory) { $this->error('The entity directory has not been set.'); return -1; } $numRepositories = 0; $generator = new EntityRepositoryGenerator(); foreach ($metadatas as $metadata) { if ($metadata->customRepositoryClassName) { $this->line(sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName)); $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $directory); $numRepositories++; } } if ($numRepositories) { $this->info('Repositories have been created.'); } else { $this->info('No Repository classes were found to be processed.'); } }
/** * Returns metadata of all entities registered in a given entity manager. * * @param EntityManagerInterface $em * * @return ClassMetadata[] */ public static function getAllMetadata(EntityManagerInterface $em) { $allMetadata = []; try { $allMetadata = $em->getMetadataFactory()->getAllMetadata(); } catch (\PDOException $e) { } catch (DBALException $e) { } catch (ORMException $e) { } catch (\ReflectionException $e) { } return $allMetadata; }
/** * {@inheritdoc} */ protected function setUp() { $this->connection = new MysqlPersistentConnection(); $params = $this->connection->getConnectionParams(); $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/Entity'], true, null, null, false); $this->em = EntityManager::create($params, $config); $event_manager = $this->em->getEventManager(); // create tables in the database $metadata = $this->em->getMetadataFactory()->getAllMetadata(); $schema_tool = new SchemaTool($this->em); $schema_tool->createSchema($metadata); // default doctrine annotation reader $annotation_reader = new AnnotationReader(); // setup required providers $mutation_metadata_provider = new EntityMutationMetadataProvider($annotation_reader); $annotation_metadata_provider = new EntityAnnotationMetadataProvider($annotation_reader); // pre flush event listener that uses the @Tracked annotation $entity_changed_listener = new EntityChangedListener($annotation_metadata_provider, $mutation_metadata_provider); $event_manager->addEventListener('preFlush', $entity_changed_listener); $event_manager->addEventListener('prePersist', $entity_changed_listener); $event_manager->addEventListener('entityChanged', $this); $this->events = []; }
/** * @param String $resourceClass * @param String $action * @return mixed * @throws \Doctrine\Common\Persistence\Mapping\MappingException * @throws \Exception */ public function resolveRouteName($resourceClass, $action, $args = array()) { $key = serialize(array($resourceClass, $action, $args)); if ($this->cache->contains('routes', $key)) { return $this->cache->fetch('routes', $key); } foreach ($this->router->getRouteCollection()->all() as $name => $route) { $defaults = $route->getDefaults(); $parts = explode('::', $defaults['_controller']); if (count($parts) === 2) { $reflection = new \ReflectionClass($parts[0]); $defaultProperties = $reflection->getdefaultProperties(); if (is_subclass_of($parts[0], '\\uebb\\HateoasBundle\\Controller\\HateoasController') && $parts[1] === $action && $this->entityManager->getMetadataFactory()->getMetadataFor($defaultProperties['entityName'])->getName() === $resourceClass) { if ($args === array_intersect_key($defaults, $args)) { $this->cache->save('routes', $key, $name); return $name; } } } } $this->cache->save('routes', $key, null); return null; }
/** * @param object $entity * @param array $associationMapping * * @return null|string */ private function getMultiTargetAssociationIdentifier($entity, array $associationMapping) { $targetIdentifier = null; $targetEntities = $this->classMetadataInfo->getFieldValue($entity, $associationMapping['fieldName']); if (count($targetEntities) > 0) { $targetClassMetadataInfo = $this->entityManager->getMetadataFactory()->getMetadataFor($associationMapping['targetEntity']); $targetEntityIdentifierCollection = []; foreach ($targetEntities as $targetEntity) { $targetEntityIdentifier = $this->getIdentifierForEntity($targetEntity, $targetClassMetadataInfo); $targetEntityIdentifierCollection[] = '@' . $targetEntityIdentifier; } $targetIdentifier = '[ ' . implode(', ', $targetEntityIdentifierCollection) . ' ]'; } return $targetIdentifier; }
/** * {@inheritdoc} */ public function evictCollectionRegions() { $metadatas = $this->em->getMetadataFactory()->getAllMetadata(); foreach ($metadatas as $metadata) { foreach ($metadata->associationMappings as $association) { if (!$association['type'] & ClassMetadata::TO_MANY) { continue; } $persister = $this->uow->getCollectionPersister($association); if (!$persister instanceof CachedPersister) { continue; } $persister->getCacheRegion()->evictAll(); } } }
/** * {@inheritdoc} */ public function getDoctrineProvidedFields() { // Check if field configurations are cached if ($this->cache->hasCache()) { $all_fields = $this->cache->getCache(); $fields = []; foreach ($all_fields as $field) { if ($field instanceof DoctrineProvidedField) { $fields[] = $field; } } return $fields; } $fields = []; // Go to Doctine Entities and fetch available fields $doctrine_meta = $this->em->getMetadataFactory()->getAllMetadata(); foreach ($doctrine_meta as $m) { $class = $m->getName(); $class_fields = $this->getFieldsForClass($class); $fields = array_merge($fields, $class_fields); } return $fields; }
/** * @param \Doctrine\ORM\Persisters\Entity\EntityPersister $persister The entity persister to cache. * @param \Doctrine\ORM\Cache\Region $region The entity cache region. * @param \Doctrine\ORM\EntityManagerInterface $em The entity manager. * @param \Doctrine\ORM\Mapping\ClassMetadata $class The entity metadata. */ public function __construct(EntityPersister $persister, Region $region, EntityManagerInterface $em, ClassMetadata $class) { $configuration = $em->getConfiguration(); $cacheConfig = $configuration->getSecondLevelCacheConfiguration(); $cacheFactory = $cacheConfig->getCacheFactory(); $this->class = $class; $this->region = $region; $this->persister = $persister; $this->cache = $em->getCache(); $this->regionName = $region->getName(); $this->uow = $em->getUnitOfWork(); $this->metadataFactory = $em->getMetadataFactory(); $this->cacheLogger = $cacheConfig->getCacheLogger(); $this->timestampRegion = $cacheFactory->getTimestampRegion(); $this->hydrator = $cacheFactory->buildEntityHydrator($em, $class); $this->timestampKey = new TimestampCacheKey($this->class->getTableName()); }
/** * Initializes a new UnitOfWork instance, bound to the given EntityManager. * * @param EntityManagerInterface $em */ public function __construct(EntityManagerInterface $em) { $this->em = $em; $this->evm = $em->getEventManager(); $this->listenersInvoker = new ListenersInvoker($em); $this->hasCache = $em->getConfiguration()->isSecondLevelCacheEnabled(); $this->identifierFlattener = new IdentifierFlattener($this, $em->getMetadataFactory()); $this->hydrationCompleteHandler = new HydrationCompleteHandler($this->listenersInvoker, $em); $this->reflectionPropertiesGetter = new ReflectionPropertiesGetter(new RuntimeReflectionService()); }
/** * Retrieves an individual parameter value. * * @param mixed $value * * @return mixed */ private function getIndividualValue($value) { if (!is_object($value) || !$this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { return $value; } return $this->em->getUnitOfWork()->getSingleIdentifierValue($value); }
/** * @param \Doctrine\ORM\Persisters\Collection\CollectionPersister $persister The collection persister that will be cached. * @param \Doctrine\ORM\Cache\Region $region The collection region. * @param \Doctrine\ORM\EntityManagerInterface $em The entity manager. * @param array $association The association mapping. */ public function __construct(CollectionPersister $persister, Region $region, EntityManagerInterface $em, array $association) { $configuration = $em->getConfiguration(); $cacheConfig = $configuration->getSecondLevelCacheConfiguration(); $cacheFactory = $cacheConfig->getCacheFactory(); $this->region = $region; $this->persister = $persister; $this->association = $association; $this->regionName = $region->getName(); $this->uow = $em->getUnitOfWork(); $this->metadataFactory = $em->getMetadataFactory(); $this->cacheLogger = $cacheConfig->getCacheLogger(); $this->hydrator = $cacheFactory->buildCollectionHydrator($em, $association); $this->sourceEntity = $em->getClassMetadata($association['sourceEntity']); $this->targetEntity = $em->getClassMetadata($association['targetEntity']); }
private function getClassMetadata($className) { return $this->entityManager->getMetadataFactory()->getMetadataFor($className); }
/** * @param \Doctrine\ORM\EntityManagerInterface $em The entity manager. */ public function __construct(EntityManagerInterface $em) { $this->em = $em; $this->uow = $em->getUnitOfWork(); $this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory()); }
/** * Checks if the Database Schema is in sync with the current metadata state. * * @return bool */ public function schemaInSyncWithMetadata() { $schemaTool = new SchemaTool($this->em); $allMetadata = $this->em->getMetadataFactory()->getAllMetadata(); return count($schemaTool->getUpdateSchemaSql($allMetadata, true)) == 0; }
/** * @param SerializerMetadataFactory|null $serializerMetadataFactory * @param NameConverterInterface|null $nameConverter * @param PropertyInfoExtractor|null $propertyInfoExtractor * @param EntityManagerInterface|null $entityManager */ public function __construct(SerializerMetadataFactory $serializerMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyInfoExtractor $propertyInfoExtractor = null, EntityManagerInterface $entityManager = null) { parent::__construct($serializerMetadataFactory, $nameConverter, $propertyInfoExtractor); $this->entityMetadataFactory = $entityManager->getMetadataFactory(); }