Completed
Push — master ( f4be61...d5c601 )
by Nikola
08:05
created

AuraDiFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 42
ccs 14
cts 20
cp 0.7
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createContainer() 0 4 1
A configure() 0 9 1
A setFactories() 0 12 3
A setInvokables() 0 6 2
1
<?php
2
/**
3
 * This file is part of the Phoundation package.
4
 *
5
 * Copyright (c) Nikola Posa
6
 *
7
 * For full copyright and license information, please refer to the LICENSE file,
8
 * located at the package root folder.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Phoundation\Di\Container\Factory;
14
15
use Aura\Di\Container;
16
use Aura\Di\ContainerBuilder;
17
18
/**
19
 * @author Nikola Posa <[email protected]>
20
 */
21
final class AuraDiFactory extends AbstractFactory
22
{
23
    /**
24
     * @var Container
25
     */
26
    protected $container;
27
28 2
    protected function createContainer()
29
    {
30 2
        return (new ContainerBuilder())->newInstance();
31
    }
32
33 2
    protected function configure($container)
34
    {
35 2
        $this->container = $container;
36
        
37 2
        $this->setFactories();
38 2
        $this->setInvokables();
39
40 2
        $this->container->set($this->getConfigServiceName(), $this->getConfig());
41 2
    }
42
43 2
    private function setFactories()
44
    {
45 2
        foreach ($this->getDiConfig('factories') as $name => $factory) {
46
            if (is_string($factory)) {
47
                $this->container->set($name, $this->container->lazyNew($factory));
48
                $this->container->set($name, $this->container->lazyGetCall($factory, '__invoke', $this->container));
49
                continue;
50
            }
51
52
            $this->container->set($name, $factory);
53
        }
54 2
    }
55
56 2
    private function setInvokables()
57
    {
58 2
        foreach ($this->getDiConfig('invokables') as $name => $className) {
59
            $this->container->set($name, $this->container->lazyNew($className));
60
        }
61 2
    }
62
}
63