/**
  * @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);
 }
Exemplo n.º 2
0
    /**
     * Get the currently active connection (the connection on top of the connection stack).
     *
     * @throws Exception If no connection is available.
     *
     * @return void|Doctrine_Connection The connection object.
     */
    public static function getConnection()
    {
        LogUtil::log(__f('Warning! %1$s is deprecated. Use %2$s instead.', array(__CLASS__ . '::' . __FUNCTION__, 'Doctrine_Manager::getInstance()->getCurrentConnection()')), E_USER_DEPRECATED);
        if (!isset(self::$manager)) {
            self::init();
        }

        if (!self::$manager->count()) {
            if (System::isInstalling()) {
                return;
            }
            throw new Exception(__('Attempted to get connection from empty connection stack'));
        }
        $connection = self::$manager->getCurrentConnection();
        return $connection;
    }