Exemple #1
0
 /**
  * @return \Doctrine\Common\Cache\CacheProvider
  */
 public function configureCache()
 {
     $cacheConfig = $this->configuration->get('cache');
     $cacheClassName = '\\Kohana\\Doctrine\\Caching\\' . ucfirst($cacheConfig['type']) . 'Cache';
     /** @var CacheInterface $cacheClass */
     $cacheClass = new $cacheClassName();
     return $cacheClass->configureCache($cacheConfig);
 }
Exemple #2
0
 /**
  * @return DoctrineEventManager
  */
 public function configureEventManager()
 {
     $eventConfiguration = $this->configuration->get('events');
     foreach ($eventConfiguration['listeners'] as $listener => $events) {
         $this->eventManager->addEventListener((array) $events, new $listener());
     }
     foreach ($eventConfiguration['subscribers'] as $subscriber) {
         $this->eventManager->addEventSubscriber(new $subscriber());
     }
     return $this->eventManager;
 }
Exemple #3
0
 /**
  * @param DoctrineCache $cache
  * @return \Doctrine\ORM\Configuration
  * @throws IncorrectConfigurationException
  */
 public function configureDriver(DoctrineCache $cache = null)
 {
     $mappingConfig = $this->configuration->get('mapping');
     $proxyConfig = $this->configuration->get('proxy');
     $onProduction = $this->configuration->get('onProduction');
     if (empty($mappingConfig['path'])) {
         throw new IncorrectConfigurationException('mapping.path');
     }
     if (empty($proxyConfig['path'])) {
         throw new IncorrectConfigurationException('proxy.path');
     }
     $namingStrategy = $this->getNamingStrategy($mappingConfig['namingStrategy']);
     $driverClassName = '\\Kohana\\Doctrine\\Driver\\' . ucfirst($mappingConfig['type']) . 'Driver';
     /** @var DriverInterface $driverClass */
     $driverClass = new $driverClassName();
     $configuredDriver = $driverClass->configureDriver($mappingConfig, $proxyConfig, $onProduction, $cache);
     $configuredDriver->setNamingStrategy($namingStrategy);
     return $configuredDriver;
 }
Exemple #4
0
 /**
  * Create a \Doctrine\ORM\Configuration based on the config given.
  * If no config are given the method will try to get the config from the configuration file.
  *
  * @return \Doctrine\ORM\Configuration
  */
 public function configureDoctrine()
 {
     $configuredCache = $this->cache->configureCache();
     $configuredDriver = $this->mapping->configureDriver($configuredCache);
     foreach ($this->configuration->get('namespaces') as $namespace) {
         $this->driverChain->addDriver($configuredDriver->getMetadataDriverImpl(), $namespace);
     }
     $configuredDriver->setMetadataDriverImpl($this->driverChain);
     // Implement maximum caching
     $configuredDriver->setMetadataCacheImpl($configuredCache);
     $configuredDriver->setHydrationCacheImpl($configuredCache);
     $configuredDriver->setQueryCacheImpl($configuredCache);
     $configuredDriver->setResultCacheImpl($configuredCache);
     $proxyConfiguration = $this->configuration->get('proxy');
     // Set proxies and proxie-prefix
     $configuredDriver->setProxyNamespace($proxyConfiguration['namespace']);
     $configuredDriver->setAutoGenerateProxyClasses($proxyConfiguration['generate']);
     return $configuredDriver;
 }
Exemple #5
0
 /**
  * Get an instance of the \Doctrine\ORM\EntityManager
  *
  * The EntityManager is build based on the database.php config file
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function create()
 {
     return DoctrineEntityManager::create($this->configuration->get('credentials'), $this->configurator->configureDoctrine(), $this->eventManager->configureEventManager());
 }