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.
[李景山php]每天laravel-20161117|ConnectionFatory.php-1
原创
©著作权归作者所有:来自51CTO博客作者lijingsan1的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:[李景山php]每天laravel-20161116|Manager.php
下一篇:ubuntu 14.04.3 LTS 版本 通过 nginx + keepalived 配置 高可用 负载均衡集群演示
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章