RemoteActivator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createInstance() 0 16 3
1
<?php
2
namespace DICIT\Activators;
3
4
use DICIT\Activator;
5
use DICIT\Container;
6
use DICIT\UnbuildableServiceException;
7
use DICIT\Util\ParamsResolver;
8
9
class RemoteActivator implements Activator
10
{
11
12
    private $adapterFactory;
13
14
    public function __construct(RemoteAdapterFactory $adapterFactory)
15
    {
16
        $this->adapterFactory = $adapterFactory;
17
    }
18
19
    public function createInstance(Container $container, $serviceName, array $serviceConfig)
20
    {
21
        if (! isset($serviceConfig['remote']) || ! isset($serviceConfig['class'])) {
22
            throw new UnbuildableServiceException(
23
                sprintf("No remote configuration available for service '%'.", $serviceName));
24
        }
25
26
        $className = $serviceConfig['class'];
27
        $remoteConfig = $serviceConfig['remote'];
28
        $convertedRemoteConfig = ParamsResolver::resolveParams($container, $remoteConfig);
29
30
        $adapter = $this->adapterFactory->getAdapter($serviceName, $convertedRemoteConfig);
31
        $factory = new \ProxyManager\Factory\RemoteObjectFactory($adapter);
32
33
        return $factory->createProxy($className);
34
    }
35
}
36