栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP

Manager.php

PHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Manager.php

 

namespace IlluminateDatabaseCapsule;

 

use PDO;

use IlluminateContainerContainer;

use IlluminateDatabaseDatabaseManager;

use IlluminateContractsEventsDispatcher;

use IlluminateSupportTraitsCapsuleManagerTrait;

use IlluminateDatabaseEloquentModel as Eloquent;

use IlluminateDatabaseConnectorsConnectionFactory;

// get this namespace

class Manager

{//get the Capsule like the

   // capsule manager

    use CapsuleManagerTrait;// use the Capsule Manager Trait

 

   

    protected $manager;//The database manager instance.

 

   

    public function __construct(Container $container = null)

    {//Create a new database capsule manager.

        $this->setupContainer($container ?: new Container);// setup Container

       // container get the container

 

        // once we have the container setup, we will setup the default configuration

        // options in the container "config" binding. This will make the database

        // manager behave correctly since all the correct binding are in place.

        $this->setupDefaultConfiguration();

       // once we have the container setup, we will setup the default configuration

       // options in the container "config" binding. This will make the database

       // manager behave correctly since all the correct binding are in place.

       // setup Default Configuration

 

        $this->setupManager();//setup Manager

    }

 

   

    protected function setupDefaultConfiguration()

    {//Setup the default database configuration options.

        $this->container['config']['database.fetch'] = PDO::FETCH_OBJ;

       // PDO::FETCH_OBJ  this container

       // set the config

 

        $this->container['config']['database.default'] = 'default';

       // default the config

    }

 

   

    protected function setupManager()

    {//Build the database manager instance.

        $factory = new ConnectionFactory($this->container);// factory get the Connection Factory

 

        $this->manager = new DatabaseManager($this->container, $factory);

       //Database Manager

       // set the manager

    }

 

   

    public static function connection($connection = null)

    {//Get a connection instance from the global manager.

        return static::$instance->getConnection($connection);

    }// return static::$instance->getConnection($connection);

   // return the getConnection

 

   

    public static function table($table, $connection = null)

    {//Get a fluent query builder instance.

        return static::$instance->connection($connection)->table($table);

    }//instance connection table

 

   

    public static function schema($connection = null)

    {//Get a schema builder instance.

        return static::$instance->connection($connection)->getSchemaBuilder();

    }// table and the get SchemaBuilder

 

   

    public function getConnection($name = null)

    {

        return $this->manager->connection($name);//connection

    }//Get a registered connection instance.

 

   

    public function addConnection(array $config, $name = 'default')

    {//Register a connection with the manager.

       //addConnection

        $connections = $this->container['config']['database.connections'];//get the connections

 

        $connections[$name] = $config;//config this connections

 

        $this->container['config']['database.connections'] = $connections;// set the config

    }

 

   

    public function bootEloquent()

    {//Bootstrap Eloquent so it is ready for usage.

        Eloquent::setConnectionResolver($this->manager);//Eloquent::setConnectionResolver(this->mamager)

 

        // If we have an event dispatcher instance, we will go ahead and register it

        // with the Eloquent ORM, allowing for model callbacks while creating and

        // updating "model" instances; however, if it not necessary to operate.

        if ($dispatcher = $this->getEventDispatcher()) {

            Eloquent::setEventDispatcher($dispatcher);

        }

       // If we have an event dispatcher instance, we will go ahead and register it

       // with the Eloquent ORM,allowing for model callbacks while creating and

       // updating "model" instance; however,if it not necessary to operate.s

    }

 

   

    public function setFetchMode($fetchMode)

    {

        $this->container['config']['database.fetch'] = $fetchMode;//set config

 

        return $this;//return the this

    }//Set the fetch mode for the database connections

 

   

    public function getDatabaseManager()

    {

        return $this->manager;// set the manager

    }//Get the database manager instance.

 

   

    public function getEventDispatcher()

    {

        if ($this->container->bound('events')) {

            return $this->container['events'];//return container

        }//getEventDispatcher

    }//Get the current event dispatcher instance.

 

   

    public function setEventDispatcher(Dispatcher $dispatcher)

    {

        $this->container->instance('events', $dispatcher);// the instance

    }//Set the event dispatcher instance to be used by connections

 

   

    public static function __callStatic($method, $parameters)

    {// callStatic

       // call_user_func_array

        return call_user_func_array([static::connection(), $method], $parameters);

    }//Dynamically pass methods to the default connection.

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/230077.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号