Example #1
0
 public function testSimpleRouteMatch()
 {
     $route = new Route('/', function () {
         // ...
     });
     $request = new Request();
     $request->setRequestUri('/');
     $router = new Router();
     $router->register($route);
     $this->assertFalse($router->isEmpty());
     $this->assertEquals($route, $router->route($request));
 }
Example #2
0
 /**
  * Triggers any "not found" filters and prepares an appropriate 404 error response.
  */
 private function prepareNotFoundResponse()
 {
     ob_clean();
     $this->response = new Response();
     $this->response->setResponseCode(ResponseCode::HTTP_NOT_FOUND);
     $this->context->registerInstance($this->response);
     $this->filters->trigger(Filters::NO_ROUTE_FOUND, $this->context);
     $this->finalizeOutputBuffer();
     if (empty($this->response->getBody())) {
         // If nothing was output, then at least present a default message to the user.
         if ($this->router->isEmpty()) {
             $this->serveStaticPage('enlighten_welcome');
         } else {
             $this->serveStaticPage('not_found');
         }
     }
 }