Dsn.php 1.15 KB
<?php
/**
 * Created by PhpStorm.
 * User: Zip
 * Date: 15/12/22
 * Time: 18:32
 */

namespace Hood\Dao\Db\PostgreSQL;

use Hood\Core\Root;
use Hood\Core\Server;

class Dsn extends Root
{
    /**
     * 获取DB配置
     * @param $dbname
     * @return array
     * @throws Exception
     */
    public function getConfig($dbname, $proxy = null)
    {
        $server = $this->getServerHost('db');
        $node = $dbname;
        if ($proxy != null) {
            $node = $proxy;
        }
        $_serverConfig = $server->getServerConfig('postgre.database', $node);
        if (empty($_serverConfig)) {
            throw new \Exception('db.' . APPLICATION_ENV . '.config.ini No [postgre.database] Node.');
        }
        $_dbConfig = $server->getServerConfig('mysql');
        $_server = $server->getServerMap($_serverConfig['write'], Server::SERVER_SELECT_MODEL_RAND);
        if (empty($_server)) {
            throw new \Exception('Db:' . $dbname . ' Server is null.');
        }
        $dbname = isset($_serverConfig['dbname']) ? $_serverConfig['dbname'] : $dbname;
        $_dbConfig['dbname'] = $dbname;
        return array_merge($_dbConfig, $_serverConfig);
    }
}