e9d5d1659e9d59481b5c60239e4ac0bb2e2f74d5
9 use FastRoute\Dispatcher
;
19 function __construct(BaseUrl
$baseUrl, Request
$request, Response
$response, Plates\Engine
$view) {
20 $this->baseUrl
= $baseUrl;
21 $this->request
= $request;
22 $this->response
= $response;
27 function __invoke(Dispatcher
$dispatcher) {
28 $route = $dispatcher->dispatch($this->request
->getRequestMethod(),
29 $this->baseUrl
->pathinfo($this->request
->getRequestUrl()));
32 case Dispatcher
::NOT_FOUND
:
33 $this->response
->setResponseCode(404);
34 $this->response
->getBody()->append($this->view
->render("404"));
37 case Dispatcher
::METHOD_NOT_ALLOWED
:
38 $this->response
->setResponseCode(405);
39 $this->response
->setHeader("Allowed", $route[1]);
40 $this->response
->getBody()->append($this->view
->render("405"));
43 case Dispatcher
::FOUND
:
44 list(, $handler, $args) = $route;
45 $handler(array_map("urldecode", $args));
49 $this->response
->send();
52 function display($view, array $data = []) {
53 $this->response
->getBody()->append(
54 $this->view
->render($view, $data));
57 function redirect($url, $code = 302) {
58 $this->response
->setResponseCode($code);
59 $this->response
->setHeader("Location", $url);
62 function getBaseUrl() {
63 return $this->baseUrl
;
70 function getRequest() {
71 return $this->request
;
74 function getResponse() {
75 return $this->response
;