xref: /web-bugs/config/container.php (revision fd1338e3)
1<?php
2
3/**
4 * Container initialization. Each service is created using Container::set()
5 * method and a callable argument for convenience of future customizations or
6 * adjustments beyond the scope of this container. See documentation for more
7 * information.
8 */
9
10use App\Container\Container;
11
12$container = new Container(include __DIR__.'/parameters.php');
13
14$container->set(\PDO::class, function ($c) {
15    return new \PDO(
16        'mysql:host='.$c->get('db_host').';dbname='.$c->get('db_name').';charset=utf8',
17        $c->get('db_user'),
18        $c->get('db_password'),
19        [
20            \PDO::ATTR_ERRMODE            => \PDO::ERRMODE_EXCEPTION,
21            \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
22            \PDO::ATTR_EMULATE_PREPARES   => false,
23            \PDO::ATTR_STATEMENT_CLASS    => [App\Database\Statement::class],
24        ]
25    );
26});
27
28$container->set(App\Repository\BugRepository::class, function ($c) {
29    return new App\Repository\BugRepository($c->get(\PDO::class));
30});
31
32$container->set(App\Repository\CommentRepository::class, function ($c) {
33    return new App\Repository\CommentRepository($c->get(\PDO::class));
34});
35
36$container->set(App\Repository\DatabaseStatusRepository::class, function ($c) {
37    return new App\Repository\DatabaseStatusRepository($c->get(\PDO::class));
38});
39
40$container->set(App\Repository\ObsoletePatchRepository::class, function ($c) {
41    return new App\Repository\ObsoletePatchRepository($c->get(\PDO::class));
42});
43
44$container->set(App\Repository\PackageRepository::class, function ($c) {
45    return new App\Repository\PackageRepository($c->get(\PDO::class));
46});
47
48$container->set(App\Repository\PatchRepository::class, function ($c) {
49    return new App\Repository\PatchRepository($c->get(\PDO::class), $c->get('uploads_dir'));
50});
51
52$container->set(App\Repository\PhpInfoRepository::class, function ($c) {
53    return new App\Repository\PhpInfoRepository();
54});
55
56$container->set(App\Repository\PullRequestRepository::class, function ($c) {
57    return new App\Repository\PullRequestRepository($c->get(\PDO::class));
58});
59
60$container->set(App\Repository\ReasonRepository::class, function ($c) {
61    return new App\Repository\ReasonRepository($c->get(\PDO::class));
62});
63
64$container->set(App\Repository\VoteRepository::class, function ($c) {
65    return new App\Repository\VoteRepository($c->get(\PDO::class));
66});
67
68$container->set(App\Template\Engine::class, function ($c) {
69    return new App\Template\Engine($c->get('templates_dir'));
70});
71
72$container->set(App\Utils\Captcha::class, function ($c) {
73    return new App\Utils\Captcha();
74});
75
76$container->set(App\Utils\GitHub::class, function ($c) {
77    return new App\Utils\GitHub($c->get(\PDO::class));
78});
79
80$container->set(App\Utils\PatchTracker::class, function ($c) {
81    return new App\Utils\PatchTracker(
82        $c->get(\PDO::class),
83        $c->get(App\Utils\Uploader::class),
84        $c->get('uploads_dir')
85    );
86});
87
88$container->set(App\Utils\Uploader::class, function ($c) {
89    return new App\Utils\Uploader();
90});
91
92return $container;
93