예제 #1
0
 /**
  * Dispatch a request
  *
  * @param Request $request
  * @return Response
  * @throws BadRequestException
  * @throws NotFoundException if if no action has been found
  */
 public function dispatch(Request $request) : Response
 {
     $URL = $request->url();
     $routes = $this->_getRoutes();
     $app = AppRegistry::getInstance()->find($request->host());
     $this->_request = $request;
     $appName = $app->name();
     if (isset($this->_appScopes[$appName])) {
         $routes = array_merge($routes, $this->_appScopes[$appName]->_getRoutes());
     }
     $method = $_SERVER['REQUEST_METHOD'];
     foreach ($routes as $route) {
         if ($route->method() == $method && $route->parse($URL)) {
             return $route->exec($request);
         }
     }
     throw new NotFoundException();
 }
예제 #2
0
 /**
  * Get the request context for an error/exception trace.
  *
  * @param Request $request The request to read from.
  * @return string
  */
 protected function _requestContext($request)
 {
     $message = "\nRequest URL: " . $request->url();
     $referer = $request->env('HTTP_REFERER');
     if ($referer) {
         $message .= "\nReferer URL: " . $referer;
     }
     $clientIp = $request->clientIp();
     if ($clientIp && $clientIp !== '::1') {
         $message .= "\nClient IP: " . $clientIp;
     }
     return $message;
 }