Completed
Push — master ( 3bd4e2...776f46 )
by Jesse
04:06
created

CompositeProxyFactory::addFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Proxy;
4
5
/**
6
 * CompositeProxyFactory.
7
 *
8
 * @author Stratadox
9
 */
10
final class CompositeProxyFactory implements ProxyFactory
11
{
12
    private $key;
13
    /** @var ProxyFactory[] */
14
    private $factories;
15
16
    public function __construct(string $decisionKey, array $factories)
17
    {
18
        $this->key = $decisionKey;
19
        foreach ($factories as $key => $factory) {
20
            $this->addFactory($key, $factory);
21
        }
22
    }
23
24
    private function addFactory(string $key, ProxyFactory $factory): void
25
    {
26
        $this->factories[$key] = $factory;
27
    }
28
29
    public static function decidingBy(string $key, array $factories): self
30
    {
31
        return new self($key, $factories);
32
    }
33
34
    public function create(array $knownData = []): Proxy
35
    {
36
        return $this->factories[$knownData[$this->key]]->create($knownData);
37
    }
38
}
39