/**
  * @param string                                                    $cacheName
  * @param string                                                    $objectManagerName
  * @param array                                                     $cacheDriver
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder   $container
  *
  * @return string
  */
 public function loadCacheDriver($cacheName, $objectManagerName, array $cacheDriver, ContainerBuilder $container)
 {
     $id = $this->getObjectManagerElementName($objectManagerName . '_' . $cacheName);
     $host = isset($cacheDriver['host']) ? $cacheDriver['host'] : null;
     $port = isset($cacheDriver['port']) ? $cacheDriver['port'] : null;
     $type = $cacheDriver['type'];
     if ($type == 'service') {
         $container->setAlias($id, new Alias($cacheDriver['id'], false));
         return $id;
     }
     $config = array('aliases' => array($id), $type => array(), 'type' => $type, 'namespace' => null);
     if (!isset($cacheDriver['namespace'])) {
         // generate a unique namespace for the given application
         $environment = $container->getParameter('kernel.root_dir') . $container->getParameter('kernel.environment');
         $hash = hash('sha256', $environment);
         $namespace = 'sf2' . $this->mappingResourceName . '_' . $objectManagerName . '_' . $hash;
         $cacheDriver['namespace'] = $namespace;
     }
     $config['namespace'] = $cacheDriver['namespace'];
     if (in_array($type, array('memcache', 'memcached'))) {
         $host = !empty($host) ? $host : 'localhost';
         $config[$type]['servers'][$host] = array('host' => $host, 'port' => !empty($port) ? $port : 11211);
     }
     if ($type === 'redis') {
         $config[$type] = array('host' => !empty($host) ? $host : 'localhost', 'port' => !empty($port) ? $port : 6379, 'password' => null, 'database' => null);
     }
     $this->cacheProviderLoader->loadCacheProvider($id, $config, $container);
     return $id;
 }
 /**
  * {@inheritDoc}
  */
 protected function loadCacheDriver($driverName, $entityManagerName, array $driverMap, ContainerBuilder $container)
 {
     if (!empty($driverMap['cache_provider'])) {
         $aliasId = $this->getObjectManagerElementName($driverName);
         $serviceId = printf('doctrine_cache.providers.%s', $driverMap['cache_provider']);
         $container->setAlias($aliasId, new Alias($serviceId, false));
         return;
     }
     return $this->adapter->loadCacheDriver($driverName, $entityManagerName, $driverMap, $container);
 }
Ejemplo n.º 3
0
 /**
  * @param array                                                     $rootConfig
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder   $container
  */
 protected function loadCustomProviders(array $rootConfig, ContainerBuilder $container)
 {
     foreach ($rootConfig['custom_providers'] as $type => $rootConfig) {
         $providerParameterName = $this->loader->getCustomProviderParameter($type);
         $definitionParameterName = $this->loader->getCustomDefinitionClassParameter($type);
         $container->setParameter($providerParameterName, $rootConfig['prototype']);
         if ($rootConfig['definition_class']) {
             $container->setParameter($definitionParameterName, $rootConfig['definition_class']);
         }
     }
 }