手记

ConnectionFatory.php-1

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.

0人推荐
随时随地看视频
慕课网APP