示例#1
0
 /**
  * 获取管道调用闭包链表
  * @return \Closure
  */
 protected function getSlice()
 {
     return function ($stack, $pipe) {
         return function ($send) use($stack, $pipe) {
             if ($pipe instanceof Closure) {
                 return call_user_func($pipe, $send, $stack);
             } else {
                 list($name, $params) = $this->parsePipeString($pipe);
                 return call_user_func_array([$this->container->make($name), $this->method], array_merge([$send, $stack], $params));
             }
         };
     };
 }
示例#2
0
 /**
  * 创建连接器链接
  *
  * @param  string   $driver
  * @param  \PDO|\Closure     $connection
  * @param  array    $config
  * @return \CatLib\Database\Connections\Connection
  *
  * @throws \InvalidArgumentException
  */
 protected function createConnection($driver, $connection, array $config = [])
 {
     if ($this->container->isExists($key = "db.connection.{$driver}")) {
         return $this->container->make($key, [$connection, $config]);
     }
     switch ($driver) {
         case 'mysql':
             return new Libs\MySqlConnection($connection, $config);
         case 'pgsql':
             return new Libs\PostgresConnection($connection, $config);
         case 'sqlite':
             return new Libs\SQLiteConnection($connection, $config);
         case 'sqlsrv':
             return new Libs\SqlServerConnection($connection, $config);
     }
     throw new InvalidArgumentException("Unsupported driver [{$driver}]");
 }