/** * @return Client */ public function getClient() { if (null === $this->client) { $config = $this->container->getConfig(); $this->client = new Client(['scheme' => $config->get('predis.scheme'), 'host' => $config->get('predis.host'), 'port' => $config->get('predis.port')]); } return $this->client; }
/** * @return Process */ public function getProcess() { if (null === $this->process) { $this->setProcess(new Process($this->getConfig(), $this->container->getJobLogger())); } return $this->process; }
/** * @return Client */ public function getClient() { if (null === $this->client) { $this->client = $this->container->getPredis()->getClient(); } return $this->client; }
/** * @return Twig_Environment */ protected function createEnvironment() { $options = []; $config = $this->container->getConfig(); if ($config->get('app.debug')) { $options['debug'] = true; $options['auto_reload'] = true; } if ($cache = $config->get('twig.cache')) { $options['cache'] = $cache; } $paths = $config->get('twig.paths'); if (isset($paths)) { $loader = new Twig_Loader_Filesystem(); $firstPath = null; $hasMain = false; foreach ($paths as $namespace => $path) { if (null === $firstPath) { $firstPath = $path; } if (is_int($namespace)) { $hasMain = true; $loader->addPath($path); } else { $loader->addPath($path, $namespace); } } if (!$hasMain && null !== $firstPath) { $loader->addPath($firstPath); } } else { $loader = new Twig_Loader_String(); } $twig = new Twig_Environment($loader, $options); if (isset($options['debug']) && $options['debug']) { $twig->addExtension(new Twig_Extension_Debug()); } $twig->addExtension(new ContainerTwigExtension($this->container)); return $twig; }
/** * @param string $name * @return EntityManager|null * @throws Exception * todo: split into chunks */ public function createEntityManager($name = null) { if (null === $name) { $name = $this->getDefautName(); } $config = $this->container->getConfig(); if ($config->get("doctrine.connections.{$name}")) { $connectionConfig = $config->get("doctrine.connections.{$name}"); } elseif ($config->get("doctrine.connections." . $this->getDefautName())) { $connectionConfig = $config->get("doctrine.connections." . $this->getDefautName()); } else { throw new Exception("There are no entity manager configurations"); } if (isset($connectionConfig['is_dev_mode'])) { $isDevMode = (bool) $connectionConfig['is_dev_mode']; } else { $isDevMode = false; } $doctrineConfig = Setup::createConfiguration($isDevMode); $doctrineConfig->setMetadataDriverImpl(new AnnotationDriver(new AnnotationReader(), $connectionConfig['paths'])); $doctrineConfig->setQuoteStrategy(new DefaultQuoteStrategy()); if (isset($connectionConfig['cache'])) { switch ($connectionConfig['cache']) { case 'apc': $this->cache = new ApcCache(); $doctrineConfig->setQueryCacheImpl($this->cache); $doctrineConfig->setMetadataCacheImpl($this->cache); $doctrineConfig->setHydrationCacheImpl($this->cache); $doctrineConfig->setResultCacheImpl($this->cache); break; case 'array': $this->cache = new ArrayCache(); $doctrineConfig->setQueryCacheImpl($this->cache); $doctrineConfig->setMetadataCacheImpl($this->cache); $doctrineConfig->setHydrationCacheImpl($this->cache); $doctrineConfig->setResultCacheImpl($this->cache); break; } if (null !== $this->cache && isset($connectionConfig['second_level_cache']) && $connectionConfig['second_level_cache'] === true) { throw new Exception("Doctrine Second Level Cache does not work so don't bother"); $this->regionsConfiguration = new RegionsConfiguration(); $this->regionsConfiguration->setLifetime('my_entity_region', 3600); $this->cacheFactory = new DefaultCacheFactory($this->regionsConfiguration, $this->cache); $doctrineConfig->setSecondLevelCacheEnabled(); $secondLevelCacheConfiguration = $doctrineConfig->getSecondLevelCacheConfiguration(); $secondLevelCacheConfiguration->setCacheFactory($this->cacheFactory); $secondLevelCacheConfiguration->setRegionsConfiguration($this->regionsConfiguration); if (isset($connectionConfig['debug']) && $connectionConfig['debug'] === true) { $this->cacheLogger = new CacheLogger(); $secondLevelCacheConfiguration->setCacheLogger($this->cacheLogger); } } } if (isset($connectionConfig['proxy_dir'])) { $doctrineConfig->setProxyDir($connectionConfig['proxy_dir']); if (isset($connectionConfig['proxy_namespace'])) { $doctrineConfig->setProxyNamespace($connectionConfig['proxy_namespace']); } else { $doctrineConfig->setProxyNamespace('Proxies'); } } if (!isset($connectionConfig['charset'])) { $connectionConfig['charset'] = 'utf8'; } $entityManager = EntityManager::create($connectionConfig, $doctrineConfig); $connection = $entityManager->getConnection(); $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); if (isset($connectionConfig['debug']) && $connectionConfig['debug'] === true) { $this->sqlLogger = new SqlLogger($this->container); $connection->getConfiguration()->setSQLLogger($this->sqlLogger); } $this->addListeners($entityManager); return $entityManager; }
/** * @param InputInterface $input * @param OutputInterface $output * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { $output->write('Flushing all Redis cache: '); $this->container->getPredis()->getClient()->flushall(); $output->write('[ <fg=green>DONE</fg=green> ]', true); }