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

DataGridServiceContainer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
dl 0
loc 51
rs 10
c 1
b 0
f 1
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A getTranslator() 0 3 1
A getDoctrine() 0 3 1
A getRouter() 0 3 1
A get() 0 3 2
A getTwig() 0 3 1
A getRequest() 0 3 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
}