指定服务句柄，一般为RPC服务导出的类名

@param string $handler 服务句柄（类名）
@param array|null 服务句柄的构造参数
@return RpcClient
517154
public function handler($handler, $construct = null)
    {
        $this->handler   = $handler;
        $this->construct = $construct;
        return $this;
    }
1307516
public function run( $handler = null )
	{
		if ( !is_null( $handler ) )
		{
			$this->handler( $handler );
		}
		
		return $this->handler->run( $this->build(), $this->handler->builder()->parameters );
	}
680622
public static function createHttpClient($handler = 'guzzle')
    {
        if (!$handler) {
            return self::detectDefaultClient();
        }

        if ($handler instanceof HttpClientInterface) {
            return $handler;
        }

        if ('curl' === $handler) {
            if (!extension_loaded('curl')) {
                throw new Exception('The cURL extension must be loaded in order to use the "curl" handler.');
            }

            return new SteeinCurlHttpClient();
        }

        if ('guzzle' === $handler && !class_exists('\GuzzleHttp\Client')) {
            throw new HttpClientException('HTTP-клиент Guzzle должен быть включен.');
        }

        if ($handler instanceof Client) {
            return new GuzzleHttpClient($handler);
        }

        if ('guzzle' === $handler) {
            return new GuzzleHttpClient();
        }

        throw new InvalidArgumentException('Обработчик клиента HTTP должен быть установлен как "guzzle", быть экземпляром GuzzleHttp\Client или экземпляром HttpClientInterface');
    }
1136217
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // 获取Response对象
        $response = $handler->handle($request);
        // 获取路由结果
        $result = RequestContext::get('routeResult');
        if(null === $result)
        {
            throw new \RuntimeException('RequestContent not found routeResult');
        }
        // 路由匹配结果是否是[控制器对象, 方法名]
        $isObject = is_array($result['callable']) && isset($result['callable'][0]) && $result['callable'][0] instanceof HttpController;
        if($isObject)
        {
            // 复制一份控制器对象
            $result['callable'][0] = clone $result['callable'][0];
            // 传入Request和Response对象
            $result['callable'][0]->request = $request;
            $result['callable'][0]->response = $response;
        }
        // 执行动作
        $actionResult = call_user_func_array($result['callable'], $this->prepareActionParams($request, $result));
        if($isObject)
        {
            // 获得控制器中的Response
            $response = $result['callable'][0]->response;
        }
        // 视图
        if($actionResult instanceof \Imi\Server\View\Annotation\View)
        {
            // 动作返回的值是@View注解
            $viewAnnotation = $actionResult;
        }
        else if($actionResult instanceof Response)
        {
            $response = $actionResult;
        }
        else
        {
            // 获取对应动作的视图注解
            $viewAnnotation = clone ViewParser::getInstance()->getByCallable($result['callable']);
            if(null !== $viewAnnotation)
            {
                if(is_array($actionResult))
                {
                    // 动作返回值是数组，合并到视图注解
                    $viewAnnotation->data = array_merge($viewAnnotation->data, $actionResult);
                }
                else
                {
                    // 非数组直接赋值
                    $viewAnnotation->data = $actionResult;
                }
            }
        }

        if(isset($viewAnnotation))
        {
            // 视图渲染
            $view = RequestContext::getServerBean('View');
            $response = $view->render($viewAnnotation, $response);
        }

        return $response;
    }
775870
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $ip = $this->getIp($request);

        if (!empty($ip)) {
            $address = $this->getAddress($ip);
            $request = $request->withAttribute($this->attribute, $address);
        }

        return $handler->handle($request);
    }
526259
protected function callHandler(
        callable $handler,
        array $handlerParams,
        PsrContainerInterface $container,
        ServerRequestInterface $request = null
    ): ResponseInterface {
        // check the handler method signature
        assert(
            $this->checkPublicStaticCallable(
                $handler,
                ['array', PsrContainerInterface::class, ServerRequestInterface::class],
                ResponseInterface::class
            ),
            'Handler method should have signature ' .
            '`public static methodName(array, PsrContainerInterface, ServerRequestInterface): ResponseInterface`'
        );

        $response = call_user_func($handler, $handlerParams, $container, $request);

        return $response;
    }
676739
protected function resolveHandlerAndMethod($handler)
    {
        list ($handler, $method) = array_pad(explode('@', $handler), 2, null);

        return [$handler, $method];
    }
925973
protected function reflection($handler)
    {
        if (! is_array($handler))
        {
            $instance = new \ReflectionFunction($handler);

            return array($handler, $instance);
        }

        list($class, $method) = (array) $handler;

        $instance = new \ReflectionMethod($class, $method);

        $handler = array($this->instance($class), $method);

        return array((array) $handler, $instance);
    }
797428
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // 获取Response对象
        $response = $handler->handle($request);
        RequestContext::set('response', $response);
        // 路由解析
        $route = RequestContext::getServerBean('HttpRoute');
        $result = $route->parse($request);
        if(null === $result || !is_callable($result['callable']))
        {
            // 未匹配到路由
            $response = App::getBean('HttpNotFoundHandler')->handle($request, $response);
            return $response;
        }
        else
        {
            RequestContext::set('routeResult', $result);

            $middlewares = $result['middlewares'];
            $middlewares[] = ActionMiddleware::class;
            $requestHandler = new RequestHandler($middlewares);
            return $requestHandler->handle($request);
        }
    }
908394
public function setNotFoundHandler($handler) : ClosureAutoBind
    {
        if (!$this->isClosure($handler)) {
            throw new InvalidArgumentException(
                'Handler must be closure'
            );
        }

        $this->notFoundHandler = $handler;

        return $this;
    }
731863
public static function init ($handler) {
		self::$handler = $handler;
		self::$destructor = new \Analog\Handler\Buffer\Destructor ();

		return function ($info) {
			Buffer::$buffer .= vsprintf (\Analog\Analog::$format, $info);
		};
	}
222531
public function pipe($name, $handler = null)
    {
        if (is_callable($name)) {
            $handler = $name;
            $name    = null;
        }

        return $handler($this->getRepository($name), $this);
    }
232419
private function getNamedHandler($handler)
    {
        if (!isset($this->namedHandlers[$handler])) {
            $this->namedHandlers[$handler] = new $handler();
        }

        return $this->namedHandlers[$handler];
    }
783378
public static function make($handler)
    {
        //No handler specified
        if (!$handler) {
            return new BoxGuzzleHttpClient();
        }

        //Custom Implemenation, maybe.
        if ($handler instanceof BoxHttpClientInterface) {
            return $handler;
        }

        //Handler is a custom configured Guzzle Client
        if ($handler instanceof Guzzle) {
            return new BoxGuzzleHttpClient($handler);
        }

        //Invalid handler
        throw new InvalidArgumentException('The http client handler must be an instance of GuzzleHttp\Client or an instance of Kunnu\Box\Http\Clients\BoxHttpClientInterface.');
    }
764689
public function map($handler)
    {
        $result = array();

        foreach ($this as $id => $document) {
            $result[$id] = $handler($document);
        }

        return $result;
    }
999841
public function run( $handler = null )
	{
		if ( !is_null( $handler ) )
		{
			$this->handler( $handler );
		}
		
		// if there is a special fetch handler defined pass him all the 
		// needed parameters and retrive the results
		if ( !is_null( $this->fetch_handler ) )
		{
			$results = call_user_func_array( $this->fetch_handler, array(
				&$this
			));
		}
		// otherwise simply do the default select fetch
		else 
		{
			$results = $this->handler->fetch( $this->build(), $this->handler->builder()->parameters, $this->fetch_arguments );
		}
		
		// In case we should forward a key means using a value
		// from every result as array key.
		if ( $this->forward_key !== false )
		{
			$raw_results = $results;
			$results = array();
			
			if ( in_array( 'assoc', $this->fetch_arguments ) )
			{
				foreach( $raw_results as $result )
				{
					$results[$result[$this->forward_key]] = $result;
				}
			}
			else
			{
				foreach( $raw_results as $result )
				{
					$results[$result->{$this->forward_key}] = $result;
				}
			}
		}
		
		// Group the results by a value
		if ( $this->group_result !== false )
		{
			$raw_results = $results;
			$results = array();
			
			if ( in_array( 'assoc', $this->fetch_arguments ) )
			{
				foreach( $raw_results as $key => $result )
				{
					$results[$result[$this->group_result]][$key] = $result;
				}
			}
			else
			{
				foreach( $raw_results as $key => $result )
				{
					$results[$result->{$this->group_result}][$key] = $result;
				}
			}
		}
		
		// when the limit is 1 we are going to return the 
		// result directly
		if ( $this->limit === 1 )
		{
			return reset( $results );
		}
		
		return $results;
	}
1219443
public function getByHandle($handle)
    {
        return isset($this->converters[$handle]) ? $this->converters[$handle] : null;
    }