[李景山php]每天laravel-20161118|ConnectionFatory.php-2

    /**
     * Get the read configuration for a read / write connection.
     *
     * @param  array  $config
     * @return array
     */
    protected function getReadConfig(array $config)
    {// Get the read configuration for a read / write connection.
        $readConfig = $this->getReadWriteConfig($config, ‘read‘);// get the read config

        if (isset($readConfig[‘host‘]) && is_array($readConfig[‘host‘])) {
           // if this read config host is a array
            $readConfig[‘host‘] = count($readConfig[‘host‘]) > 1
                ? $readConfig[‘host‘][array_rand($readConfig[‘host‘])]
                : $readConfig[‘host‘][0];
        }// a very bad array structure that i think

        return $this->mergeReadWriteConfig($config, $readConfig);
    }// merge read write config with the read config. ha ha

    /**
     * Get the read configuration for a read / write connection.
     *
     * @param  array  $config
     * @return array
     */
    protected function getWriteConfig(array $config)
    {// get the write config throw set option like "write" by this function
        $writeConfig = $this->getReadWriteConfig($config, ‘write‘);

        return $this->mergeReadWriteConfig($config, $writeConfig);
    }// merge the config

    /**
     * Get a read / write level configuration.
     *
     * @param  array   $config
     * @param  string  $type
     * @return array
     */
    protected function getReadWriteConfig(array $config, $type)
    {// get a read or write level configuration
        if (isset($config[$type][0])) {
            return $config[$type][array_rand($config[$type])];
        }//if set the type 0 return this rand type

        return $config[$type];// return this all
    }

    /**
     * Merge a configuration for a read / write connection.
     *
     * @param  array  $config
     * @param  array  $merge
     * @return array
     */
    protected function mergeReadWriteConfig(array $config, array $merge)
    {// merge a configuration for a read / write connection.
        return Arr::except(array_merge($config, $merge), [‘read‘, ‘write‘]);
    }//return Arr::except this function is too powerful

    /**
     * Parse and prepare the database configuration.
     *
     * @param  array   $config
     * @param  string  $name
     * @return array
     */
    protected function parseConfig(array $config, $name)
    {//Parse and prepare the database configuration
        return Arr::add(Arr::add($config, ‘prefix‘, ‘‘), ‘name‘, $name);
    }

    /**
     * Create a connector instance based on the configuration.
     *
     * @param  array  $config
     * @return \Illuminate\Database\Connectors\ConnectorInterface
     *
     * @throws \InvalidArgumentException
     */
    public function createConnector(array $config)
    {// Create a connector instance based on the configuration
        if (! isset($config[‘driver‘])) {// no driver throw exception
            throw new InvalidArgumentException(‘A driver must be specified.‘);
        }

        if ($this->container->bound($key = "db.connector.{$config[‘driver‘]}")) {
            return $this->container->make($key);
        }// get the driver and make it

        switch ($config[‘driver‘]) {
            case ‘mysql‘:
                return new MySqlConnector;

            case ‘pgsql‘:
                return new PostgresConnector;

            case ‘sqlite‘:
                return new SQLiteConnector;

            case ‘sqlsrv‘:
                return new SqlServerConnector;
        }// too low ,can you use another type to show you power or smarty

        throw new InvalidArgumentException("Unsupported driver [{$config[‘driver‘]}]");
       // default get the exception to return
    }

    /**
     * Create a new connection instance.
     *
     * @param  string   $driver
     * @param  \PDO|\Closure     $connection
     * @param  string   $database
     * @param  string   $prefix
     * @param  array    $config
     * @return \Illuminate\Database\Connection
     *
     * @throws \InvalidArgumentException
     */
    protected function createConnection($driver, $connection, $database, $prefix = ‘‘, array $config = [])
    {// Create a new connection instance
        if ($this->container->bound($key = "db.connection.{$driver}")) {
            return $this->container->make($key, [$connection, $database, $prefix, $config]);
        }// if has it just return it

        switch ($driver) {
            case ‘mysql‘:
                return new MySqlConnection($connection, $database, $prefix, $config);

            case ‘pgsql‘:
                return new PostgresConnection($connection, $database, $prefix, $config);

            case ‘sqlite‘:
                return new SQLiteConnection($connection, $database, $prefix, $config);

            case ‘sqlsrv‘:
                return new SqlServerConnection($connection, $database, $prefix, $config);
        }// other return what you want by you self,

        throw new InvalidArgumentException("Unsupported driver [$driver]");
       // default throw wrong message.
    }
}
时间: 2024-08-03 15:43:44

[李景山php]每天laravel-20161118|ConnectionFatory.php-2的相关文章

[李景山php]每天laravel-20160920|Writer-2

    //2016-07-20     /**      * Register a file log handler.      *      * @param  string  $path      * @param  string  $level      * @return void      */     public function useFiles($path, $level = 'debug')     {         $this->monolog->pushHandle

[李景山php]每天laravel-20161021|Request.php-2

/**  * Determine if the current request URL and query string matches a pattern.  *  * @param  mixed  string  * @return bool  */ public function fullUrlIs() {// check string like URL     $url = $this->fullUrl();     foreach (func_get_args() as $patter

[李景山php]每天laravel-20161103|CompilerEngine.php-2

    /**      * Handle a view exception.      *      * @param  \Exception  $e      * @param  int  $obLevel      * @return void      *      * @throws $e      */     protected function handleViewException(Exception $e, $obLevel)     {         $e = new E

[李景山php]每天laravel-20161104|Engine.php

<?php namespace Illuminate\View\Engines; abstract class Engine {     /**      * The view that was last to be rendered.      *      * @var string      */     protected $lastRendered;//The view that was last to be rendered.     /**      * Get the last 

[李景山php]每天laravel-20161105|EngineInterface.php

<?php namespace Illuminate\View\Engines; interface EngineInterface {     /**      * Get the evaluated contents of the view.      *      * @param  string  $path      * @param  array   $data      * @return string      */     public function get($path, 

[李景山php]每天laravel-20161106|EngineResolver.php

<?php namespace Illuminate\View\Engines; use Closure; use InvalidArgumentException; class EngineResolver {// engineResolver     /**      * The array of engine resolvers.      *      * @var array      */     protected $resolvers = [];// The array of e

[李景山php]每天laravel-20161107|PhpEngine.php

<?php namespace Illuminate\View\Engines; use Exception; use Throwable; use Symfony\Component\Debug\Exception\FatalThrowableError; class PhpEngine implements EngineInterface {// PhpEngine implements EngineInterface     /**      * Get the evaluated con

[李景山php]每天laravel-20161010|Validator.php-10

   /**     * Validate the guessed extension of a file upload is in a set of file extensions.     *     * @param  string  $attribute     * @param  mixed  $value     * @param  array   $parameters     * @return bool     */    protected function validate

[李景山php]每天TP5-20170204|thinkphp5-Response.php

<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006~2016 http://thinkphp.cn All