/**
  * Handle the given request and response in the case of a routing error.
  * 
  * @param Request  $request
  * @param Response $response
  * @return mixed
  */
 public function handle(Request $request, Response $response)
 {
     $status = $response->status();
     $response->content("{$status} error.");
     if ($this->view->exists("errors/{$status}")) {
         $response->content($this->view->create("errors/{$status}", array('http_host' => $request->host(), 'request_uri' => $request->path(), 'signature' => $request->server('server_signature'))));
     }
     return $response;
 }
Beispiel #2
0
 /**
  * Register a global HTTP request, response and session with the container.
  * 
  * @param Container $container
  */
 public function register(Container $container)
 {
     $container->register(array('Darya\\Http\\Request' => function ($container) {
         return Request::createFromGlobals($container->resolve('Darya\\Http\\Session'));
     }, 'Darya\\Http\\Response' => new Response(), 'Darya\\Http\\Session' => new Session\Php()));
 }
Beispiel #3
0
 /**
  * Create a new request using PHP's super globals.
  * 
  * @param \Darya\Http\Session $session [optional]
  * @return \Darya\Http\Request
  */
 public static function createFromGlobals(Session $session = null)
 {
     $request = Request::create($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD'], array('get' => $_GET, 'post' => $_POST, 'cookie' => $_COOKIE, 'file' => $_FILES, 'server' => $_SERVER, 'header' => static::headersFromGlobals($_SERVER)), $session);
     return $request;
 }
Beispiel #4
0
 /**
  * Test a request against a route.
  * 
  * Accepts an optional extra callback for filtering matched routes and their
  * parameters. This callback is executed after testing the route against
  * the router's filters.
  * 
  * Fires the 'router.prefilter' event before testing against filters.
  * 
  * @param Request  $request
  * @param Route    $route
  * @param callable $callback [optional]
  * @return bool
  */
 protected function testMatch(Request $request, Route $route, $callback = null)
 {
     $path = $this->stripBase($request->path());
     $pattern = $this->preparePattern($route->path());
     if (preg_match($pattern, $path, $matches)) {
         $route->matches($matches);
         $this->event('router.prefilter', array($route));
         if ($this->testMatchFilters($route, $callback)) {
             return true;
         }
     }
     return false;
 }