Completed
Push — master ( a3955d...bffb57 )
by Nikola
02:12
created

AuraDiFactory::setFactories()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 0
crap 3
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 5
    protected function createContainer()
29
    {
30 5
        return (new ContainerBuilder())->newInstance();
31
    }
32
33 5
    protected function configure($container)
34
    {
35 5
        $this->container = $container;
36
        
37 5
        $this->setFactories();
38 5
        $this->setInvokables();
39
40 5
        $this->container->set($this->getConfigServiceName(), $this->getConfig());
41 5
    }
42
43 5
    private function setFactories()
44
    {
45 5
        foreach ($this->getDiConfigGroup('factories') as $name => $factory) {
46 2
            if (is_string($factory)) {
47 1
                $this->container->set($factory, $this->container->lazyNew($factory));
48 1
                $this->container->set($name, $this->container->lazyGetCall($factory, '__invoke', $this->container));
49 1
                continue;
50
            }
51
52 1
            $this->container->set($name, $factory);
53
        }
54 5
    }
55
56 5
    private function setInvokables()
57
    {
58 5
        foreach ($this->getDiConfigGroup('invokables') as $name => $className) {
59 1
            $this->container->set($name, $this->container->lazyNew($className));
60
        }
61 5
    }
62
}
63