RemoteActivator::__construct()   A
last analyzed

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
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
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