1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
require_once '../vendor/autoload.php'; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Error handling |
8
|
|
|
*/ |
9
|
|
|
// @todo Remove usage of ini_set |
10
|
|
|
|
11
|
|
|
ini_set('error_reporting', E_ALL); // @todo should be set to maximum error reporting in php.ini |
12
|
|
|
ini_set('display_errors', true); // @todo should be false in php.ini |
13
|
|
|
ini_set('log_errors', true); // @todo should be true in php.ini |
14
|
|
|
ini_set('error_log', sprintf('../../shared/errors-%s.log', date('Y-m-d'))); |
15
|
|
|
|
16
|
|
|
// @todo Add bugsnag snippet for error logging |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Configuration and routing |
20
|
|
|
*/ |
21
|
|
|
$configuration = new \Zortje\MVC\Configuration\Configuration(include '../config.default.php'); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Request |
25
|
|
|
*/ |
26
|
|
|
$cookie = new \Zortje\MVC\Storage\Cookie\Cookie($configuration, !empty($_COOKIE['token']) ? $_COOKIE['token'] : ''); |
27
|
|
|
|
28
|
|
|
$request = new Zortje\MVC\Network\Request($cookie, $_SERVER, $_POST); |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Dispatch |
32
|
|
|
*/ |
33
|
|
|
$pdo = new \PDO('mysql:host=127.0.0.1;dbname=my_app', 'root', 'password'); |
34
|
|
|
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
35
|
|
|
$pdo->exec('SET NAMES utf8'); |
36
|
|
|
|
37
|
|
|
$dispatcher = new Zortje\MVC\Routing\Dispatcher($pdo, $configuration); |
38
|
|
|
|
39
|
|
|
// @todo $logger = new \Monolog\Logger('mvc'); |
|
|
|
|
40
|
|
|
// @todo $logger->pushHandler(new \Monolog\Handler\StreamHandler('path/to/log/mvc.log', \Monolog\Logger::DEBUG)); |
41
|
|
|
|
42
|
|
|
// @todo $dispatcher->setLogger($logger); |
|
|
|
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Response |
47
|
|
|
*/ |
48
|
|
|
// @todo add example for calling dispatch with user object |
49
|
|
|
$response = $dispatcher->dispatch($request); |
50
|
|
|
|
51
|
|
|
foreach ($response->getHeaders() as $header) { |
52
|
|
|
header($header); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$cookie = $response->getCookie(); |
56
|
|
|
|
57
|
|
|
if (!is_null($cookie)) { |
58
|
|
|
setcookie('token', $cookie->getTokenString(), time() + 3600, $path = '/', $domain = '', $secureOnly = true, $httpOnly = true); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
echo $response->getOutput(); |
62
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.