为了账号安全,请及时绑定邮箱和手机立即绑定

ConnectionFatory.php-1

标签:
PHP

namespace Illuminate\Database\Connectors;

 

use PDO;

use Illuminate\Support\Arr;

use InvalidArgumentException;

use Illuminate\Database\MySqlConnection;

use Illuminate\Database\SQLiteConnection;

use Illuminate\Database\PostgresConnection;

use Illuminate\Database\SqlServerConnection;

use Illuminate\Contracts\Container\Container;

// namespace it is the namespace

class ConnectionFactory

{// make the Connection Factory

    /**

     * The IoC container instance.

     *

     * @var \Illuminate\Contracts\Container\Container

     */

    protected $container;//The IoC container instance.

   // IoC container instance

 

    /**

     * Create a new connection factory instance.

     *

     * @param  \Illuminate\Contracts\Container\Container  $container

     * @return void

     */

    public function __construct(Container $container)

    {//Create a new connection factory instance.

        $this->container = $container;// set the container

    }// this->container container;

 

    /**

     * Establish a PDO connection based on the configuration.

     *

     * @param  array   $config

     * @param  string  $name

     * @return \Illuminate\Database\Connection

     */

    public function make(array $config, $name = null)

    {//Establish a PDO connection based on the configuration.

        $config = $this->parseConfig($config, $name);// set the config

 

        if (isset($config['read'])) {

            return $this->createReadWriteConnection($config);//createReadWriteConnection

        }// if set the config

       // if it is set read

 

        return $this->createSingleConnection($config);// get the single

    }// create Single Connection

    /**

     * Create a single database connection instance.

     *

     * @param  array  $config

     * @return \Illuminate\Database\Connection

     */

    protected function createSingleConnection(array $config)

    {//Create a single database connection instance.

        $pdo = function () use ($config) {

            return $this->createConnector($config)->connect($config);

        };// set the pdo set the create Connector connect

       // create Connector

 

        return $this->createConnection($config['driver'], $pdo, $config['database'], $config['prefix'], $config);

    }// create the Connection

 

    /**

     * Create a single database connection instance.

     *

     * @param  array  $config

     * @return \Illuminate\Database\Connection

     */

    protected function createReadWriteConnection(array $config)

    {//Create a single database connection instance.

        $connection = $this->createSingleConnection($this->getWriteConfig($config));

// connection set the create Single Connection

        return $connection->setReadPdo($this->createReadPdo($config));

    }// setReadPdo

 

    /**

     * Create a new PDO instance for reading.

     *

     * @param  array  $config

     * @return \PDO

     */

    protected function createReadPdo(array $config)

    {

        $readConfig = $this->getReadConfig($config);//

 

        return $this->createConnector($readConfig)->connect($readConfig);

    }//Create a new PDO instance for reading.

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消