-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdependencies.php
More file actions
67 lines (52 loc) · 1.81 KB
/
dependencies.php
File metadata and controls
67 lines (52 loc) · 1.81 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
62
63
64
65
66
67
<?php
declare(strict_types=1);
use App\TwigExtension\CsrfExtension;
use DI\Bridge\Slim\Bridge;
use DI\ContainerBuilder;
use Dotenv\Dotenv;
use Slim\Csrf\Guard;
use Slim\Middleware\ErrorMiddleware;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
$dotenv = Dotenv::createImmutable(__DIR__ . '/');
$dotenv->load();
if (isset($_ENV['APP_WHOOPS']) && $_ENV['APP_WHOOPS'] === 'on') {
$whoops = new \Whoops\Run();
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
$whoops->register();
}
date_default_timezone_set($_ENV['APP_DEFAULT_TIMEZONE']);
$definitions = require_once __DIR__ . '/definitions.php';
$builder = new ContainerBuilder();
$builder->addDefinitions($definitions);
$container = $builder->build();
$app = Bridge::create($container);
// CSRF protection is optional as it requires cookies and this may present
// privacy and data protection issues
if (isset($_ENV['APP_CSRF_PROTECTION']) && $_ENV['APP_CSRF_PROTECTION'] === 'on') {
// Set sensible secure default session cookie options, even if php.ini does not
session_set_cookie_params([
'secure' => true,
'httponly' => true,
'samesite' => 'Strict',
]);
session_start();
$container->set('csrf', static function () use ($app) {
return new Guard($app->getResponseFactory());
});
$app->add('csrf');
$container->get(Twig::class)->addExtension(new CsrfExtension($container->get('csrf')));
}
$app->addRoutingMiddleware();
$app->addBodyParsingMiddleware();
$app->add(TwigMiddleware::createFromContainer($app, Twig::class));
if (!(isset($_ENV['APP_WHOOPS']) && $_ENV['APP_WHOOPS'] === 'on')) {
$errorMiddleware = new ErrorMiddleware(
$app->getCallableResolver(),
$app->getResponseFactory(),
false,
true,
true
);
$app->add($errorMiddleware);
}