/** * Gets a profiling logger. * * @return OrmLogger|null */ protected function getProfilingLogger() { if (null === $this->entityManager) { return null; } $config = $this->entityManager->getConfiguration(); return $config instanceof OrmConfiguration ? $config->getAttribute('OrmProfilingLogger') : null; }
/** * Boot the extensions */ public function boot() { foreach ($this->registry->getManagers() as $em) { $this->em = $em; $this->evm = $this->em->getEventManager(); $this->metadata = $this->em->getConfiguration(); $this->reader = $this->driverChain->getReader(); foreach ($this->extensions as $extension) { $this->bootExtension($extension); } } }
/** * Create a new repository instance for an entity class. * * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. * @param string $entityName The name of the entity. * * @return \Doctrine\Common\Persistence\ObjectRepository */ private function createRepository(EntityManagerInterface $entityManager, $entityName) { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadata */ $metadata = $entityManager->getClassMetadata($entityName); $repositoryClassName = $metadata->customRepositoryClassName ?: $entityManager->getConfiguration()->getDefaultRepositoryClassName(); return new $repositoryClassName($entityManager, $metadata); }
/** * Boot the extensions */ public function boot() { foreach ($this->registry->getManagers() as $em) { $this->em = $em; $this->evm = $this->em->getEventManager(); $this->metadata = $this->em->getConfiguration(); $this->reader = $this->driverChain->getReader(); $hash = spl_object_hash($em); if (!isset($this->subscribedExtensions[$hash])) { $this->subscribedExtensions[$hash] = []; } foreach ($this->extensions as $extension) { $this->bootExtension($extension); } } }
/** * Initializes a new SchemaTool instance that uses the connection of the * provided EntityManager. * * @param \Doctrine\ORM\EntityManagerInterface $em */ public function __construct(EntityManagerInterface $auditEm, EntityManagerInterface $sourceEm) { $this->auditEm = $auditEm; $this->sourceEm = $sourceEm; $this->platform = $auditEm->getConnection()->getDatabasePlatform(); $this->quoteStrategy = $auditEm->getConfiguration()->getQuoteStrategy(); }
/** * Boot the extensions */ public function boot() { foreach ($this->registry->getManagers() as $em) { $this->em = $em; $this->chain = new MappingDriverChain(); $this->evm = $this->em->getEventManager(); $this->metadata = $this->em->getConfiguration(); $this->reader = method_exists($this->metadata->getMetadataDriverImpl(), 'getReader') ? $this->metadata->getMetadataDriverImpl()->getReader() : false; if ($this->gedmo['enabled']) { $this->bootGedmoExtensions($this->gedmo['namespace'], $this->gedmo['all']); } foreach ($this->extensions as $extenion) { $this->bootExtension($extenion); } } }
/** * Initializes a new instance of a class derived from AbstractCollectionPersister. * * @param EntityManagerInterface $em */ public function __construct(EntityManagerInterface $em) { $this->em = $em; $this->uow = $em->getUnitOfWork(); $this->conn = $em->getConnection(); $this->platform = $this->conn->getDatabasePlatform(); $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); }
/** * @return array */ private function indexEntityClassNames() { $indexedClassNames = []; $entityClassNames = $this->em->getConfiguration()->getMetadataDriverImpl()->getAllClassNames(); foreach ($entityClassNames as $name) { // @todo Support subtypes. $resourceType = Util\Inflector::typify($name); $indexedClassNames[$resourceType][] = $name; } //Config class override foreach ($this->getResourcesConfig()->getAll() as $resource) { if (!empty($resource->type) && !empty($resource->class)) { $indexedClassNames[$resource->type] = array($resource->class); } } return $indexedClassNames; }
/** * @param EntityManagerInterface $em * @param AuditConfiguration $config * @param MetadataFactory $factory */ public function __construct(EntityManagerInterface $em, AuditConfiguration $config, MetadataFactory $factory) { $this->em = $em; $this->config = $config; $this->metadataFactory = $factory; $this->platform = $this->em->getConnection()->getDatabasePlatform(); $this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy(); }
/** * @param \Doctrine\ORM\EntityManagerInterface $em The entity manager. * @param \Doctrine\ORM\Cache\Region $region The query region. */ public function __construct(EntityManagerInterface $em, Region $region) { $cacheConfig = $em->getConfiguration()->getSecondLevelCacheConfiguration(); $this->em = $em; $this->region = $region; $this->uow = $em->getUnitOfWork(); $this->cacheLogger = $cacheConfig->getCacheLogger(); $this->validator = $cacheConfig->getQueryValidator(); }
/** * @param EntityManagerInterface $entityManager * @param string $entityName * * @return ObjectRepository */ protected function createRepository(EntityManagerInterface $entityManager, $entityName) { $metadata = $entityManager->getClassMetadata($entityName); $repository = $metadata->customRepositoryClassName; if ($repository === null) { $repository = $entityManager->getConfiguration()->getDefaultRepositoryClassName(); } return $this->createResourceRepository($repository, $entityManager, $metadata, $this->resolveResource($metadata->getName())); }
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__ . '/Proxies'); $config->setProxyNamespace('DoctrineExtensions\\Tests\\Proxies'); $config->setAutoGenerateProxyClasses(true); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver(__DIR__ . '/../Entities')); $config->setCustomDatetimeFunctions(array('YEAR' => 'DoctrineExtensions\\Query\\Sqlite\\Year', 'WEEKDAY' => 'DoctrineExtensions\\Query\\Sqlite\\WeekDay', 'WEEK' => 'DoctrineExtensions\\Query\\Sqlite\\Week', 'Month' => 'DoctrineExtensions\\Query\\Sqlite\\Month', 'MINUTE' => 'DoctrineExtensions\\Query\\Sqlite\\Minute', 'HOUR' => 'DoctrineExtensions\\Query\\Sqlite\\Hour', 'DAY' => 'DoctrineExtensions\\Query\\Sqlite\\Day', 'DATE' => 'DoctrineExtensions\\Query\\Sqlite\\Date', 'STRFTIME' => 'DoctrineExtensions\\Query\\Sqlite\\StrfTime', 'DATE_FORMAT' => 'DoctrineExtensions\\Query\\Sqlite\\DateFormat')); $this->entityManager = \Doctrine\ORM\EntityManager::create(array('driver' => 'pdo_sqlite', 'memory' => true), $config); $configuration = $this->entityManager->getConfiguration(); if (method_exists($configuration, 'getQuoteStrategy') === false) { // doctrine < 2.3 $this->columnAlias = 'sclr0'; } else { $this->columnAlias = $configuration->getQuoteStrategy()->getColumnAlias('sclr', 0, $this->entityManager->getConnection()->getDatabasePlatform(), $this->entityManager->getClassMetadata('DoctrineExtensions\\Tests\\Entities\\Date')); } }
/** * Create a new repository instance for an entity class. * * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. * @param string $entityName The name of the entity. * * @return \Doctrine\Common\Persistence\ObjectRepository */ protected function createRepository(EntityManagerInterface $entityManager, $entityName) { $metadata = $entityManager->getClassMetadata($entityName); $repositoryClassName = $metadata->customRepositoryClassName; if ($repositoryClassName === null) { $configuration = $entityManager->getConfiguration(); $repositoryClassName = $configuration->getDefaultRepositoryClassName(); } return new $repositoryClassName($entityManager, $metadata); }
/** * Create a new repository instance for an entity class. * * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. * @param string $entityName The name of the entity. * * @return ObjectRepository */ private function createRepository(EntityManagerInterface $entityManager, $entityName) { /* @var $metadata ClassMetadata */ $metadata = $entityManager->getClassMetadata($entityName); $repositoryClassName = $metadata->customRepositoryClassName ?: $entityManager->getConfiguration()->getDefaultRepositoryClassName(); $result = new $repositoryClassName($entityManager, $metadata); if ($result instanceof ContainerAwareInterface) { $result->setContainer($this->container); } return $result; }
/** * Gets the repository for an entity class. * * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. * @param string $entityName The name of the entity. * * @return \Doctrine\Common\Persistence\ObjectRepository */ public function getRepository(EntityManagerInterface $entityManager, $entityName) { if ($this->entityRepositoryManager->has($entityName)) { $repository = $this->entityRepositoryManager->get($entityName); } else { $entityMetadata = $entityManager->getClassMetadata($entityName); $className = $entityManager->getConfiguration()->getDefaultRepositoryClassName(); /** @var EntityRepository $defaultRepository */ $repository = new $className($entityManager, $entityMetadata); } return $repository; }
/** * Create a new repository instance for an entity class. * * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. * @param Doctrine\ORM\Mapping\ClassMetadata $metadata * @return Doctrine\Common\Persistence\ObjectRepository */ private function createRepository(EntityManagerInterface $entityManager, Doctrine\ORM\Mapping\ClassMetadata $metadata) { $defaultClass = $entityManager->getConfiguration()->getDefaultRepositoryClassName(); $customClass = ltrim($metadata->customRepositoryClassName, '\\'); if (empty($customClass) || $customClass === $defaultClass) { $factory = $this->getRepositoryFactory($this->defaultRepositoryFactory); } elseif (isset($this->repositoryServicesMap[$customClass])) { $factory = $this->getRepositoryFactory($this->repositoryServicesMap[$customClass]); } else { return new $customClass($entityManager, $metadata); } return $factory->create($entityManager, $metadata); }
/** * Gets a profiling logger. * * @return OrmLogger|null */ protected function getProfilingLogger() { if ($this->logger) { return $this->logger; } if (false === $this->logger) { return null; } if (null === $this->entityManager) { return null; } $config = $this->entityManager->getConfiguration(); $this->logger = $config instanceof OrmConfiguration ? $config->getAttribute('OrmProfilingLogger', false) : false; return $this->logger; }
/** * Create a new repository instance for an entity class. * * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance. * @param Doctrine\ORM\Mapping\ClassMetadata $metadata * @return Doctrine\Common\Persistence\ObjectRepository */ private function createRepository(EntityManagerInterface $entityManager, Doctrine\ORM\Mapping\ClassMetadata $metadata) { $defaultRepository = $entityManager->getConfiguration()->getDefaultRepositoryClassName(); $repositoryClassName = $metadata->customRepositoryClassName ?: $defaultRepository; if ($repositoryClassName === $defaultRepository) { return new $repositoryClassName($entityManager, $metadata); } elseif (!($services = $this->serviceLocator->findByType($repositoryClassName))) { // todo: solve me in future, maybe just throw an exception? return new $repositoryClassName($entityManager, $metadata); } elseif (count($services) > 1) { // todo: solve me in future, maybe just throw an exception? return new $repositoryClassName($entityManager, $metadata); } else { return $this->serviceLocator->createService($services[0], array('entityManager' => $entityManager, 'metadata' => $metadata)); } }
/** * Publishes a block * * TODO: cleanup created and deleted blocks in revision that were never published. * * @param BlockInterface|array $blocks */ public function publish($blocks) { if ($blocks instanceof PersistentCollection) { $blocks = $blocks->getValues(); } if (!$blocks || is_array($blocks) && !count($blocks)) { return; } if (!is_array($blocks)) { $blocks = array($blocks); } $this->disableRevisionListener(); $deletes = array(); foreach ($blocks as $block) { if (null !== ($revision = $this->revisionManager->getDraftRevision($block))) { try { $this->revisionManager->revert($block, $revision); } catch (DeletedException $e) { // $this->em->remove($block); $deletes[] = $block; } $this->em->flush($block); } } // Cycle through all deleted blocks to perform cascades manually foreach ($deletes as $block) { $descendants = $this->findDescendants($block, false); foreach ($descendants as $descendant) { $descendant->setDeletedAt(new \DateTime()); $this->em->flush($descendant); } } $cacheDriver = $this->em->getConfiguration()->getResultCacheImpl(); $cacheDriver->deleteAll(); $this->enableRevisionListener(); }
/** * @param Doctrine\ORM\EntityManagerInterface $em */ public function setEntityManager(Doctrine\ORM\EntityManagerInterface $em) { $this->em = $em; $this->config = $em->getConfiguration(); parent::setEntityManager($em); }
/** * @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()); }
/** * Gets a collection persister for a collection-valued association. * * @param array $association * * @return \Doctrine\ORM\Persisters\Collection\CollectionPersister */ public function getCollectionPersister(array $association) { $role = isset($association['cache']) ? $association['sourceEntity'] . '::' . $association['fieldName'] : $association['type']; if (isset($this->collectionPersisters[$role])) { return $this->collectionPersisters[$role]; } $persister = ClassMetadata::ONE_TO_MANY === $association['type'] ? new OneToManyPersister($this->em) : new ManyToManyPersister($this->em); if ($this->hasCache && isset($association['cache'])) { $persister = $this->em->getConfiguration()->getSecondLevelCacheConfiguration()->getCacheFactory()->buildCachedCollectionPersister($this->em, $persister, $association); } $this->collectionPersisters[$role] = $persister; return $this->collectionPersisters[$role]; }
/** * Initializes a new <tt>BasicEntityPersister</tt> that uses the given EntityManager * and persists instances of the class described by the given ClassMetadata descriptor. * * @param EntityManagerInterface $em * @param ClassMetadata $class */ public function __construct(EntityManagerInterface $em, ClassMetadata $class) { $this->em = $em; $this->class = $class; $this->conn = $em->getConnection(); $this->platform = $this->conn->getDatabasePlatform(); $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy(); $this->identifierFlattener = new IdentifierFlattener($em->getUnitOfWork(), $em->getMetadataFactory()); $this->noLimitsContext = $this->currentPersisterContext = new CachedPersisterContext($class, new Query\ResultSetMapping(), false); $this->limitsHandlingContext = new CachedPersisterContext($class, new Query\ResultSetMapping(), true); }
/** * Return all mapped entity class names * * @param EntityManagerInterface $entityManager * * @return string[] */ private function getMappedEntities(EntityManagerInterface $entityManager) { $entityClassNames = $entityManager->getConfiguration()->getMetadataDriverImpl()->getAllClassNames(); if (!$entityClassNames) { throw new \InvalidArgumentException('You do not have any mapped Doctrine ORM entities according to the current configuration. ' . 'If you have entities or mapping files you should check your mapping configuration for errors.'); } return $entityClassNames; }
/** * Constructor. * * @param EntityManagerInterface $em */ public function __construct(EntityManagerInterface $em) { $this->em = $em; $this->config = $em->getConfiguration(); }
/** * {@inheritDoc} */ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName) { return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; }
/** * @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']); }
/** * {@inheritdoc} */ public function __construct(EntityManagerInterface $em) { $this->em = $em; $this->uow = $em->getUnitOfWork(); $this->cacheFactory = $em->getConfiguration()->getSecondLevelCacheConfiguration()->getCacheFactory(); }
/** * Initializes a new ListenersInvoker instance. * * @param EntityManagerInterface $em */ public function __construct(EntityManagerInterface $em) { $this->eventManager = $em->getEventManager(); $this->resolver = $em->getConfiguration()->getEntityListenerResolver(); }
/** * Cleanup Query resource when clone is called. * * @return void */ public function __clone() { $this->parameters = new ArrayCollection(); $this->_hints = array(); $this->_hints = $this->_em->getConfiguration()->getDefaultQueryHints(); }