Completed
Push — master ( f15fe2...9a8393 )
by Pavel
07:23 queued 11s
created

DataGridServiceContainer::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
4
namespace Pfilsx\DataGrid;
5
6
7
use Symfony\Bridge\Doctrine\ManagerRegistry;
8
use Symfony\Component\HttpFoundation\RequestStack;
9
use Symfony\Component\Routing\RouterInterface;
10
use Symfony\Contracts\Translation\TranslatorInterface;
11
use Twig\Environment;
12
13
/**
14
 * Class DataGridServiceContainer
15
 * @package Pfilsx\DataGrid
16
 * @internal
17
 */
18
class DataGridServiceContainer
19
{
20
21
    private $container;
22
23
    public function __construct(
24
        ManagerRegistry $doctrine,
25
        RouterInterface $router,
26
        Environment $twig,
27
        RequestStack $requestStack,
28
        TranslatorInterface $translator = null
29
    )
30
    {
31
        $this->container = [
32
            'doctrine' => $doctrine,
33
            'router' => $router,
34
            'twig' => $twig,
35
            'request' => $requestStack,
36
            'translator' => $translator
37
        ];
38
    }
39
40
    public function get(string $service)
41
    {
42
        return array_key_exists($service, $this->container) ? $this->container[$service] : null;
43
    }
44
45
46
    public function getDoctrine(): ManagerRegistry
47
    {
48
        return $this->container['doctrine'];
49
    }
50
51
    public function getRouter(): RouterInterface
52
    {
53
        return $this->container['router'];
54
    }
55
56
    public function getTwig(): Environment
57
    {
58
        return $this->container['twig'];
59
    }
60
61
    public function getRequest(): RequestStack
62
    {
63
        return $this->container['request'];
64
    }
65
66
    public function getTranslator(): ?TranslatorInterface
67
    {
68
        return $this->container['translator'];
69
    }
70
}