Ejemplo n.º 1
0
    /**
     * Initialize a DBConnection and place it on the connection stack.
     *
     * @param string  $name        The database alias name in the DBInfo configuration array (optional) (default=null which then defaults to 'default').
     * @param boolean $lazyConnect Whether or not to connect lazy.
     *
     * @deprecated
     *
     * @throws PDOException If database connection failed.
     * @return Doctrine_Connection Desired database connection reference.
     */
    public static function init($name = 'default', $lazyConnect = false)
    {
        LogUtil::log(__f('Warning! %1$s is deprecated.', array(__CLASS__ . '::' . __FUNCTION__)), E_USER_DEPRECATED);
        $serviceManager = ServiceUtil::getManager();
        $eventManager = EventUtil::getManager();

        // Lazy load DB connection to avoid testing DSNs that are not yet valid (e.g. no DB created yet)
        $dbEvent = new Zikula_Event('doctrine.init_connection', null, array('lazy' => $lazyConnect, 'name' => $name));
        $connection = $eventManager->notify($dbEvent)->getData();
        if (!self::$manager instanceof Doctrine_Manager) {
            self::$manager = Doctrine_Manager::getInstance();
        }
        $databases = $serviceManager['databases'];
        self::$connectionInfo[$name] = $databases[$name];

        return $connection;
    }