Completed
Push — master ( d7bbda...0e324f )
by Kamil
06:08
created

KernelBasedContainerAccessor::getParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the CrossContainerExtension package.
5
 *
6
 * (c) Kamil Kokot <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FriendsOfBehat\CrossContainerExtension;
13
14
use Symfony\Component\DependencyInjection\Container;
15
use Symfony\Component\HttpKernel\KernelInterface;
16
17
final class KernelBasedContainerAccessor implements ContainerAccessor
18
{
19
    /**
20
     * @var KernelInterface
21
     */
22
    private $kernel;
23
24
    /**
25
     * @param KernelInterface $kernel
26
     */
27
    public function __construct(KernelInterface $kernel)
28
    {
29
        $this->kernel = $kernel;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getService($id)
36
    {
37
        return $this->kernel->getContainer()->get($id);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function getParameters()
44
    {
45
        $container = $this->kernel->getContainer();
46
47
        if (!$container instanceof Container) {
48
            throw new \DomainException('Could not get the parameters of kernel\'s container.');
49
        }
50
51
        return $container->getParameterBag()->all();
52
    }
53
}
54