亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

ConnectionFatory.php-2

標簽:
PHP

/**

     * Get the read configuration for a read / write connection.

     *

     * @param  array  $config

     * @return array

     */

    protected function getReadConfig(array $config)

    {// Get the read configuration for a read / write connection.

        $readConfig = $this->getReadWriteConfig($config, 'read');// get the read config

 

        if (isset($readConfig['host']) && is_array($readConfig['host'])) {

           // if this read config host is a array

            $readConfig['host'] = count($readConfig['host']) > 1

                ? $readConfig['host'][array_rand($readConfig['host'])]

                : $readConfig['host'][0];

        }// a very bad array structure that i think

 

        return $this->mergeReadWriteConfig($config, $readConfig);

    }// merge read write config with the read config. ha ha

 

    /**

     * Get the read configuration for a read / write connection.

     *

     * @param  array  $config

     * @return array

     */

    protected function getWriteConfig(array $config)

    {// get the write config throw set option like "write" by this function

        $writeConfig = $this->getReadWriteConfig($config, 'write');

 

        return $this->mergeReadWriteConfig($config, $writeConfig);

    }// merge the config

 

    /**

     * Get a read / write level configuration.

     *

     * @param  array   $config

     * @param  string  $type

     * @return array

     */

    protected function getReadWriteConfig(array $config, $type)

    {// get a read or write level configuration

        if (isset($config[$type][0])) {

            return $config[$type][array_rand($config[$type])];

        }//if set the type 0 return this rand type

 

        return $config[$type];// return this all

    }

 

    /**

     * Merge a configuration for a read / write connection.

     *

     * @param  array  $config

     * @param  array  $merge

     * @return array

     */

    protected function mergeReadWriteConfig(array $config, array $merge)

    {// merge a configuration for a read / write connection.

        return Arr::except(array_merge($config, $merge), ['read', 'write']);

    }//return Arr::except this function is too powerful

 

    /**

     * Parse and prepare the database configuration.

     *

     * @param  array   $config

     * @param  string  $name

     * @return array

     */

    protected function parseConfig(array $config, $name)

    {//Parse and prepare the database configuration

        return Arr::add(Arr::add($config, 'prefix', ''), 'name', $name);

    }

 

    /**

     * Create a connector instance based on the configuration.

     *

     * @param  array  $config

     * @return \Illuminate\Database\Connectors\ConnectorInterface

     *

     * @throws \InvalidArgumentException

     */

    public function createConnector(array $config)

    {// Create a connector instance based on the configuration

        if (! isset($config['driver'])) {// no driver throw exception

            throw new InvalidArgumentException('A driver must be specified.');

        }

 

        if ($this->container->bound($key = "db.connector.{$config['driver']}")) {

            return $this->container->make($key);

        }// get the driver and make it

 

        switch ($config['driver']) {

            case 'mysql':

                return new MySqlConnector;

 

            case 'pgsql':

                return new PostgresConnector;

 

            case 'sqlite':

                return new SQLiteConnector;

 

            case 'sqlsrv':

                return new SqlServerConnector;

        }// too low ,can you use another type to show you power or smarty

 

        throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]");

       // default get the exception to return

    }

 

    /**

     * Create a new connection instance.

     *

     * @param  string   $driver

     * @param  \PDO|\Closure     $connection

     * @param  string   $database

     * @param  string   $prefix

     * @param  array    $config

     * @return \Illuminate\Database\Connection

     *

     * @throws \InvalidArgumentException

     */

    protected function createConnection($driver, $connection, $database, $prefix = '', array $config = [])

    {// Create a new connection instance

        if ($this->container->bound($key = "db.connection.{$driver}")) {

            return $this->container->make($key, [$connection, $database, $prefix, $config]);

        }// if has it just return it

 

        switch ($driver) {

            case 'mysql':

                return new MySqlConnection($connection, $database, $prefix, $config);

 

            case 'pgsql':

                return new PostgresConnection($connection, $database, $prefix, $config);

 

            case 'sqlite':

                return new SQLiteConnection($connection, $database, $prefix, $config);

 

            case 'sqlsrv':

                return new SqlServerConnection($connection, $database, $prefix, $config);

        }// other return what you want by you self,

 

        throw new InvalidArgumentException("Unsupported driver [$driver]");

       // default throw wrong message.

    }

}

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消