-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdefinitions.php
More file actions
57 lines (44 loc) · 1.29 KB
/
definitions.php
File metadata and controls
57 lines (44 loc) · 1.29 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
<?php
declare(strict_types=1);
use App\Environment;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMSetup;
use Slim\Views\Twig;
use Twig\Extra\Intl\IntlExtension;
$definitions = [];
$definitions[Twig::class] = function () {
$twig = Twig::create(
__DIR__ . '/templates',
[
'strict_variables' => true
]
);
$flash = [];
if (isset($_SESSION['flash'])) {
$flash = $_SESSION['flash'];
$_SESSION['flash'] = [];
}
$twig->addExtension(new IntlExtension());
$twig->getEnvironment()->addGlobal('flash', $flash);
return $twig;
};
$definitions[Environment::class] = function () {
return new Environment($_ENV);
};
$definitions[EntityManagerInterface::class] = function () {
$config = ORMSetup::createAttributeMetadataConfiguration([]);
$connection = DriverManager::getConnection(
[
'driver' => 'pdo_mysql',
'user' => $_ENV['APP_DATABASE_USER'],
'password' => $_ENV['APP_DATABASE_PASSWORD'],
'dbname' => $_ENV['APP_DATABASE_NAME'],
'host' => $_ENV['APP_DATABASE_HOST']
],
$config
);
return new EntityManager($connection, $config);
};
return $definitions;