/** * @return \Doctrine_Connection * @throws \Doctrine_Connection_Exception * @throws \Doctrine_Manager_Exception */ private function getConnection() { // if there is a name and a connection with that name exists, use that one if ($this->name && $this->manager->contains($this->name)) { return $this->manager->getConnection($this->name); } // if there is a name and no connection with that name exists, create one if ($this->name) { return $this->manager->openConnection($this->dsn, $this->name); } // if there is no name (so it's not using multiple connections) and one connection is present, use that one if (!$this->name && $this->manager->count()) { return $this->manager->getCurrentConnection(); } // if there is no name (so it's not using multiple connections) and no connection is present, create one return $this->manager->openConnection($this->dsn); }
/** * Get the DB connection info structure for a connection as defined in config.php. * * If $field is supplied, the value of the specified field is retuerned, otherwise * the entire connection info array is returned. * * @param string $name The name of the connection info to get. Passing null returns the current (ie: top) connection (optional) (default=null). * @param string $field The field of the connection info record to return. * * @throws Exception If no connection is available. * @throws Exception If the given connection does not exist. * @throws Exception If the given field does not exist. * @return void|mixed The connection info array or the specified field value. */ public static function getConnectionInfo($name = null, $field = null) { LogUtil::log(__f('Warning! %1$s is deprecated.', array(__CLASS__ . '::' . __FUNCTION__)), E_USER_DEPRECATED); if (!self::$manager instanceof Doctrine_Manager) { self::init($name); } if (!self::$manager->count()) { if (System::isInstalling()) { return; } throw new Exception(__('Attempted to get info from empty connection stack')); } // look if $name points to a valid connection if (!is_null($name) && !self::$manager->contains($name)) { throw new Exception(__f('Invalid connection key [%s]', $name)); } if (is_null($name)) { // take the current connection which is the last element on the stack $name = self::$manager->getCurrentConnection()->getName(); } if (!isset(self::$connectionInfo[$name])) { self::init($name); } if (!isset(self::$connectionInfo[$name])) { throw new Exception(__f('Invalid connection key [%s]', $name)); } $connectionInfo = self::$connectionInfo[$name]; if ($field) { if ($field == 'alias') { return $name; } // only return a specific field if (!isset($connectionInfo[$field])) { throw new Exception(__f('Unknown field [%s] requested', $field)); } return $connectionInfo[$field]; } // return the complete information array return $connectionInfo; }