Ejemplo n.º 1
0
 public function run()
 {
     $entityManager = null;
     if (is_array($_SERVER['argv'])) {
         foreach ($_SERVER['argv'] as $key => $value) {
             if (substr($value, 0, 5) === '--em=') {
                 $entityManager = substr($value, 5);
                 unset($_SERVER['argv'][$key]);
                 if (is_int($_SERVER['argc'])) {
                     $_SERVER['argc']--;
                 }
                 break;
             }
         }
     }
     $commands = $this->container->getDoctrine()->getCommands();
     $helperSet = $this->container->getDoctrine()->getHelperSet($entityManager);
     if (!$helperSet instanceof HelperSet) {
         foreach ($GLOBALS as $helperSetCandidate) {
             if ($helperSetCandidate instanceof HelperSet) {
                 $helperSet = $helperSetCandidate;
                 break;
             }
         }
     }
     ConsoleRunner::run($helperSet, $commands);
 }
Ejemplo n.º 2
0
 /**
  * @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);
     }
 }
Ejemplo n.º 3
0
 /**
  * @return Process
  */
 public function getProcess()
 {
     if (null === $this->process) {
         $this->setProcess(new Process($this->getConfig(), $this->container->getJobLogger()));
     }
     return $this->process;
 }
Ejemplo n.º 4
0
 /**
  * @return Client
  */
 public function getClient()
 {
     if (null === $this->client) {
         $this->client = $this->container->getPredis()->getClient();
     }
     return $this->client;
 }
Ejemplo n.º 5
0
 /**
  * @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;
 }
Ejemplo n.º 6
0
 /**
  * @param ContainerInterface|Container $container
  */
 public function __construct(ContainerInterface $container)
 {
     $this->controller = new BrowserSessionController(new DoctrineDriver($container->getEntityManager()), new SmartDriver($container->getRouter(), $container->getRequest(), $container->getResponse()), new PredisDriver($container->getPredis()->getClient()), null, true);
 }