예제 #1
0
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $memcache = $serviceLocator->get('memcache');
     $config = $serviceLocator->get('ApplicationConfig');
     if (is_array($config) && isset($config['tenant_id'])) {
         if ($memcache instanceof \Memcache) {
             $cache = new MemcacheCache();
             $cache->setNamespace(sprintf('stokq.doctrine.%s', $config['tenant_id']));
             $cache->setMemcache($memcache);
             return $cache;
         }
     } else {
         throw new \RuntimeException("Unable to get `tenant_id` from config.");
     }
     throw new \RuntimeException("Invalid memcache instance returned.");
 }
예제 #2
0
 /**
  * Creates cache by name.
  *
  * @param string $name    Name.
  * @param array  $options Options.
  *
  * @return CacheProvider
  * @throws \InvalidArgumentException When cache provider with given name not found.
  * @throws \LogicException When no caches provided for "chain" cache.
  */
 public function create($name, array $options = array())
 {
     switch ($name) {
         case 'chain':
             $valid_caches = array();
             foreach (array_filter($options) as $cache_name) {
                 $valid_caches[] = self::create($cache_name);
             }
             if (!$valid_caches) {
                 throw new \LogicException('No valid caches provided for "chain" cache.');
             }
             $cache_driver = new ChainCache($valid_caches);
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
         case 'array':
             $cache_driver = new ArrayCache();
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
         case 'apc':
             $cache_driver = new ApcCache();
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
         case 'memcache':
             $memcache = new \Memcache();
             $memcache->connect('localhost', 11211);
             $cache_driver = new MemcacheCache();
             $cache_driver->setMemcache($memcache);
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
         case 'memcached':
             $memcached = new \Memcached();
             $memcached->addServer('memcache_host', 11211);
             $cache_driver = new MemcachedCache();
             $cache_driver->setMemcached($memcached);
             $cache_driver->setNamespace($this->_namespace);
             return $cache_driver;
     }
     throw new \InvalidArgumentException('Cache provider "' . $name . '" not found.');
 }
예제 #3
0
 /**
  * @param IConfiguration $applicationConfiguration
  */
 public function init(IConfiguration $applicationConfiguration)
 {
     $this->router->parseExpressions();
     $this->router->detectCurrentRoute($this->kernel->getRequest()->url(), $this->kernel->getServer()->getRequestMethod());
     $this->kernel->getRequest()->assignExpressionValues($this->router);
     $ds = DIRECTORY_SEPARATOR;
     $proxyPath = $this->kernel->getServer()->getDocumentRoot() . "var" . $ds . "cache" . $ds . "Proxies";
     $entityPath = $this->kernel->getServer()->getDocumentRoot() . "src";
     if (!file_exists($proxyPath)) {
         mkdir($proxyPath, 0770, true);
     }
     $isDevMode = $applicationConfiguration->get("devmode") == true;
     $emConfig = Setup::createAnnotationMetadataConfiguration(array($entityPath), $isDevMode, $proxyPath);
     /*$emConfig->addCustomStringFunction("GROUP_CONCAT", "DoctrineExtensions\\Query\\Mysql\\GroupConcat");
     		$emConfig->addCustomStringFunction("DATE_FORMAT", "DoctrineExtensions\\Query\\Mysql\\DateFormat");
     		$emConfig->addCustomStringFunction("IFNULL", "DoctrineExtensions\\Query\\Mysql\\IfNull");
     		$emConfig->addCustomStringFunction("STR_TO_DATE", "DoctrineExtensions\\Query\\Mysql\\StrToDate");
     		$emConfig->addCustomStringFunction("CONCAT_WS", "DoctrineExtensions\\Query\\Mysql\\ConcatWs");
     		$emConfig->addCustomStringFunction("DATEDIFF", "DoctrineExtensions\\Query\\Mysql\\DateDiff");
     		$emConfig->addCustomStringFunction("MATCH_AGAINST", "DoctrineExtensions\\Query\\Mysql\\MatchAgainst");
     		$emConfig->addCustomStringFunction("REGEXP", "DoctrineExtensions\\Query\\Mysql\\Regexp");
     		$emConfig->addCustomStringFunction("IFELSE", "DoctrineExtensions\\Query\\Mysql\\IfElse");*/
     if (!empty($applicationConfiguration->get("repository-factory"))) {
         $repositoryFactory = $applicationConfiguration->get("repository-factory");
         $emConfig->setRepositoryFactory(new $repositoryFactory());
     }
     if (!$isDevMode) {
         $memcache = new \Memcache();
         $memcache->addServer("127.0.0.1", 11211);
         $cacheDriver = new MemcacheCache();
         $cacheDriver->setMemcache($memcache);
         $cacheDriver->setNamespace($this->kernel->getServer()->getHttpHost());
         $emConfig->setResultCacheImpl($cacheDriver);
         $emConfig->setQueryCacheImpl($cacheDriver);
         $emConfig->setMetadataCacheImpl($cacheDriver);
     }
     $conn = array('dbname' => $applicationConfiguration->get("dbname"), 'user' => $applicationConfiguration->get("dbuser"), 'password' => $applicationConfiguration->get("dbpassword"), 'host' => $applicationConfiguration->get("dbhost"), 'charset' => $applicationConfiguration->get("dbcharset"), 'driver' => $applicationConfiguration->get("dbdriver"));
     $em = $this->injector->getClassname("doctrine.entitymanager");
     $this->kernel->setEntityManager($em::create($conn, $emConfig));
 }