SymfonyContainerAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TheCodingMachine\Interop\ServiceProviderBridgeBundle;
4
5
use Psr\Container\ContainerInterface;
6
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
7
8
/**
9
 * An adapter from a Symfony Container to the standardized ContainerInterface
10
 * Heavily adapter from Acclimate's SymfonyContainerAdapter
11
 */
12
class SymfonyContainerAdapter implements ContainerInterface
13
{
14
    /**
15
     * @var SymfonyContainerInterface A Symfony Container
16
     */
17
    private $container;
18
19
    /**
20
     * @param SymfonyContainerInterface $container A Symfony Container
21
     */
22
    public function __construct(SymfonyContainerInterface $container)
23
    {
24
        $this->container = $container;
25
    }
26
27
    public function get($id)
28
    {
29
        // First, let's test if there is a parameter (parameters and services are the same thing in container/interop)
30
        if ($this->container->hasParameter($id)) {
31
            return $this->container->getParameter($id);
32
        }
33
34
        return $this->container->get($id);
35
    }
36
37
    public function has($id)
38
    {
39
        return $this->container->has($id) || $this->container->hasParameter($id);
40
    }
41
}
42