-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
31 lines (23 loc) · 920 Bytes
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
use FastRoute\RouteCollector;
$container = require __DIR__ . '/../app/bootstrap.php';
$dispatcher = FastRoute\simpleDispatcher(function (RouteCollector $r) {
$r->addRoute('GET', '/', 'SuperBlog\Controller\HomeController');
$r->addRoute('GET', '/article/{id}', ['SuperBlog\Controller\ArticleController', 'show']);
});
$route = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
switch ($route[0]) {
case FastRoute\Dispatcher::NOT_FOUND:
echo '404 Not Found';
break;
case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
echo '405 Method Not Allowed';
break;
case FastRoute\Dispatcher::FOUND:
$controller = $route[1];
$parameters = $route[2];
// We could do $container->get($controller) but $container->call()
// does that automatically
$container->call($controller, $parameters);
break;
}