/** * @param string $level * @param string $message */ private function writeLog($level, $message) { if (!empty($message)) { if ($this->file === null) { $this->file = $this->container->getConfig()->get('log.doctrine'); } $content = date('Y-m-d H:i:s') . ' (' . $this->getSession() . ') ' . $level . ': ' . $message . PHP_EOL; file_put_contents($this->file, $content, FILE_APPEND); } }
/** * @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; }
/** * @return Config */ private function createConfig() { $config = $this->container->getConfig(); return (new Config())->setBootstrap($this->getBootstrap())->addServers($config->get('gearman.servers'))->setUser($config->get('gearman.user'))->setAutoUpdate($config->get('gearman.auto_update')); }