继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

ConnectionFatory.php-1

凤凰求蛊
关注TA
已关注
手记 188
粉丝 9
获赞 15

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.

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP