Ejemplo n.º 1
0
 /**
  * Sets the entity manager.
  *
  * @return \BackBee\Cache\DAO\Cache
  *
  * @throws \BackBee\Cache\Exception\CacheException Occurs if if enable to create a database connection.
  */
 private function setEntityManager()
 {
     try {
         if ($this->_instance_options['em'] instanceof EntityManager) {
             $this->_em = $this->_instance_options['em'];
         } else {
             $this->_em = EntityManagerCreator::create($this->_instance_options['dbal'], $this->getLogger());
         }
     } catch (InvalidArgumentException $e) {
         throw new CacheException('DAO cache: enable to create a database conneciton', CacheException::INVALID_DB_CONNECTION, $e);
     }
     return $this;
 }
Ejemplo n.º 2
0
 /**
  * Initiate doctrine connection for the Command on master database if its configure
  *
  * @param object       $input       The input option of command
  * @param object       $output      The output of command
  *
  * @throws \DatabaseConnectionException When Unable to connect to database
  */
 protected function initConnection($input, $output)
 {
     if (null !== $input->getOption('host')) {
         $connection['host'] = $input->getOption('host');
     }
     if (null !== $input->getOption('port')) {
         $connection['port'] = $input->getOption('port');
     }
     if (null !== $input->getOption('user')) {
         $connection['user'] = $input->getOption('user');
     }
     if (null !== $input->getOption('password')) {
         $connection['password'] = $input->getOption('password');
     }
     $doctrine_config = $this->bbapp->getConfig()->getDoctrineConfig();
     if (isset($connection['user']) && isset($connection['password'])) {
         if (isset($doctrine_config['dbal']['master'])) {
             $doctrine_config['dbal']['master'] = array_merge($doctrine_config['dbal']['master'], $connection);
         } else {
             $doctrine_config['dbal'] = array_merge($doctrine_config['dbal'], $connection);
         }
     }
     // DISABLE CACHE DOCTRINE
     unset($doctrine_config['dbal']['metadata_cache_driver']);
     unset($doctrine_config['dbal']['query_cache_driver']);
     if (!array_key_exists('proxy_ns', $doctrine_config['dbal'])) {
         $doctrine_config['dbal']['proxy_ns'] = 'Proxies';
     }
     if (!array_key_exists('proxy_dir', $doctrine_config['dbal'])) {
         $doctrine_config['dbal']['proxy_dir'] = $this->bbapp->getCacheDir() . '/' . 'Proxies';
     }
     try {
         $em = EntityManagerCreator::create($doctrine_config['dbal']);
         if (isset($doctrine_config['dbal']['master'])) {
             $em->getConnection()->connect('master');
         } else {
             $em->getConnection()->connect();
         }
     } catch (\Exception $e) {
         throw new DatabaseConnectionException('Unable to connect to the database.', 0, $e);
     }
     return $em;
 }