Exemplo n.º 1
0
 /**
  * Create connection adapter instance
  *
  * @param string $connectionName
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  * @throws \InvalidArgumentException
  */
 public function create($connectionName)
 {
     $connectionConfig = $this->_localConfig->getConnection($connectionName);
     if (!$connectionConfig || !isset($connectionConfig['active']) || !$connectionConfig['active']) {
         return null;
     }
     if (!isset($connectionConfig['adapter'])) {
         throw new \InvalidArgumentException('Adapter is not set for connection "' . $connectionName . '"');
     }
     $adapterInstance = $this->_objectManager->create($connectionConfig['adapter'], $connectionConfig);
     if (!$adapterInstance instanceof ConnectionAdapterInterface) {
         throw new \InvalidArgumentException('Trying to create wrong connection adapter');
     }
     return $adapterInstance->getConnection();
 }
Exemplo n.º 2
0
 /**
  * Retrieve connection data from config
  *
  * @return array
  */
 public function getConnectionData()
 {
     if (!$this->_connectionData) {
         if ($this->_configData) {
             $connectionData = array('host' => $this->_configData['db_host'], 'username' => $this->_configData['db_user'], 'password' => $this->_configData['db_pass'], 'dbName' => $this->_configData['db_name'], 'pdoType' => $this->getPdoType());
         } else {
             $default = $this->_arguments->getConnection('default');
             $connectionData = array('host' => $default['host'], 'username' => $default['username'], 'password' => $default['password'], 'dbName' => $default['dbName'], 'pdoType' => $this->getPdoType());
         }
         $this->_connectionData = $connectionData;
     }
     return $this->_connectionData;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getConnection($connectionName)
 {
     return $this->subject->getConnection($connectionName);
 }