-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
61 lines (49 loc) · 1.75 KB
/
Copy pathindex.php
File metadata and controls
61 lines (49 loc) · 1.75 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* App main file
*
* @category Main
* @package App
* @author Ricardo Striquer Soares <rstriquer.gmail>
* @license https://github.com/rstriquer/php-ps4-sample/blob/master/LICENSE
* @version Release: @package_version@
*/
use DI\ContainerBuilder;
use FastRoute\RouteCollector;
use App\Controllers\QuestionsController;
use App\Session;
use Symfony\Component\Dotenv\Dotenv;
require __DIR__ . '/vendor/autoload.php';
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
if (getenv('APP_DEBUG')) {
ini_set('display_errors', 'On');
ini_set('ignore_repeated_errors', 'On');
ini_set('html_errors', 'On');
error_reporting(E_ALL|E_STRICT);
}
Session::start();
$containerBuilder = new ContainerBuilder;
$container = $containerBuilder->build();
$dispatcher = FastRoute\simpleDispatcher(function (RouteCollector $r) {
$r->addRoute('POST', '/start', [QuestionsController::class, 'startRound']);
$r->addRoute('POST', '/yes', [QuestionsController::class, 'getYes']);
$r->addRoute('POST', '/no', [QuestionsController::class, 'getNo']);
$r->addRoute('GET', '/', [QuestionsController::class, 'initGame']);
$r->addRoute('POST', '/add', [QuestionsController::class, 'addLink']);
$r->addRoute('GET', '/knowledge', [QuestionsController::class, 'showKnowledge']);
});
$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];
$container->call($controller, $parameters);
break;
}