LazyActivator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 32
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createInstance() 0 21 3
1
<?php
2
namespace DICIT\Activators;
3
4
use DICIT\Activator;
5
use DICIT\Container;
6
7
class LazyActivator implements Activator
8
{
9
10
    private $activator;
11
12
    public function __construct(Activator $activator)
13
    {
14
        $this->activator = $activator;
15
    }
16
17
    public function createInstance(Container $container, $serviceName, array $serviceConfig)
18
    {
19
        if (! isset($serviceConfig['lazy']) || ! $serviceConfig['lazy']) {
20
            return $this->activator->createInstance($container, $serviceName, $serviceConfig);
21
        }
22
23
        $activator = $this->activator;
24
        $factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory();
25
26
        $proxy = $factory->createProxy($serviceConfig['class'],
27
            function (& $wrappedObject, $proxy, $method, $parameters, & $initializer) use ($activator, $container,
28
            $serviceName, $serviceConfig)
29
            {
30
                $wrappedObject = $activator->createInstance($container, $serviceName, $serviceConfig);
31
                $initializer = null;
32
33
                return true;
34
            });
35
36
        return $proxy;
37
    }
38
}
39