/**
  * @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
    /**
     * Pop the currently active connection off the stack.
     *
     * @param boolean $close Whether or not to close the connection (optional) (default=false).
     *
     * @throws Exception If no connection is available.
     * @return Doctrine_Connection The newly active connection.
     */
    public static function popConnection($close = false)
    {
        LogUtil::log(__f('Warning! %1$s is deprecated.', array(__CLASS__ . '::' . __FUNCTION__)), E_USER_DEPRECATED);
        if (!self::$manager->count()) {
            throw new Exception(__('Attempted to pop connection from empty connection stack'));
        }

        $connection = self::$manager->getConnection();
        if ($close) {
            $name = $connection->getName();
            $connInfo = self::$connectionInfo[$name];

            // close
            $connection->close();

            // reopen connection
            self::$manager->openConnection($connInfo['dsn'], $name, true);
        }

        return self::$manager->getConnection();
    }