/** * 根据URI创建一个新的请求对象 * * $request = new Request($uri); * * If $cache parameter is set, the response for the request will attempt to be retrieved from the cache. * * @param string $uri URI of the request * @param array $clientParams Array of params to pass to the request client * @param array $injectedRoutes An array of routes to use, for testing * @throws RequestException */ public function __construct($uri, $clientParams = [], $injectedRoutes = []) { $clientParams = is_array($clientParams) ? $clientParams : []; $this->message = new Message(); $this->routes = $injectedRoutes; $splitUri = explode('?', $uri); $uri = array_shift($splitUri); if (null !== Request::$initialRequest) { if ($splitUri) { parse_str($splitUri[0], $this->_get); } } // 要区分内部链接和外部链接 if (Valid::url($uri)) { // 为其创建一个路由 $this->route = new Entry(['uri' => $uri]); $this->uri = $uri; if (0 === strpos($uri, 'https://')) { $this->secure = true; } $this->external = true; $this->client = new ExternalClient($clientParams); Base::getLog()->debug(__METHOD__ . ' make an internal request', ['uri' => $uri, 'params' => $clientParams]); } else { $this->uri = trim($uri, '/'); $this->client = new InternalClient($clientParams); Base::getLog()->debug(__METHOD__ . ' make an external request', ['uri' => $uri, 'params' => $clientParams]); } parent::__construct(); }