InteropServiceProviderBridgeBundle   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegistry() 0 4 1
A boot() 0 4 1
A build() 0 4 1
A __construct() 0 4 1
1
<?php
2
3
namespace Bnf\Interop\ServiceProviderBridgeBundle;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Symfony\Component\HttpKernel\Bundle\Bundle;
8
9
class InteropServiceProviderBridgeBundle extends Bundle implements RegistryProviderInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $serviceProviders;
15
16
    /**
17
     * @var int
18
     */
19
    private $id;
20
21
    /**
22
     * @param array $serviceProviders An array of service providers, in the format specified in bnf/service-provider-registry: https://github.com/bnf/service-provider-registry#how-does-it-work
23
     */
24
    public function __construct(array $serviceProviders = [], int $id = 0)
25
    {
26
        $this->serviceProviders = $serviceProviders;
27
        $this->id = $id;
28
    }
29
30
    public function build(ContainerBuilder $container)
31
    {
32
        parent::build($container);
33
        $container->addCompilerPass(new ServiceProviderCompilationPass($this->id, $this));
34
    }
35
36
    /**
37
     * At boot time, let's fill the container with the registry.
38
     */
39
    public function boot()
40
    {
41
        $registryServiceName = 'service_provider_registry_' . $this->id;
42
        $this->container->set($registryServiceName, $this->getRegistry($this->container));
43
    }
44
45
    /**
46
     * @param ContainerInterface $container
47
     * @return Registry
48
     */
49
    public function getRegistry(ContainerInterface $container): Registry
50
    {
51
        // In parallel, let's merge the registry:
52
        return new Registry($this->serviceProviders);
53
    }
54
}
55