Exemplo n.º 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);
 }
Exemplo n.º 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;
 }
Exemplo n.º 3
0
 /**
  * @test
  */
 public function shouldBeAbleTaChangeNamingStrategy()
 {
     $this->configuration->shouldReceive('get')->with('mapping')->andReturn(['type' => 'yaml', 'path' => ['path/to/mapping/files'], "namingStrategy" => ["strategy" => "underscore", "case" => CASE_UPPER]]);
     $this->configuration->shouldReceive('get')->with('proxy')->andReturn(['path' => 'path/to/proxy/files']);
     $this->configuration->shouldReceive('get')->with('onProduction')->andReturn(true);
     $configuredDriver = $this->driver->configureDriver();
     $this->assertInstanceOf('Doctrine\\ORM\\Mapping\\UnderscoreNamingStrategy', $configuredDriver->getNamingStrategy());
     $this->assertEquals(CASE_UPPER, $configuredDriver->getNamingStrategy()->getCase());
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 /**
  * @test
  */
 public function shouldConfigureXcacheCache()
 {
     $this->configuration->shouldReceive('get')->with('cache')->andReturn(['type' => 'Xcache']);
     $configuredCache = $this->cache->configureCache();
     $this->assertInstanceOf('Doctrine\\Common\\Cache\\XcacheCache', $configuredCache);
 }
Exemplo n.º 7
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());
 }