[Li Jingshan php] every day laravel-20161118| Connectionfatory.php-2

Source: Internet
Author: User
Tags unsupported

    /**     * 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 &Nbsp;    *  @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  &nBSP, $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 ':         &nBsp;       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.    }}


This article is from the "Focus on PHP Group number: 414194301" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1853487

[Li Jingshan php] every day laravel-20161118| Connectionfatory.php-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.