Completed
Push — master ( 0fa39d...2d8d21 )
by Dominik
14:39
created

Di::copy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Di.php
5
 *
6
 * @author Dominik Kocuj
7
 * @license https://opensource.org/licenses/MIT The MIT License
8
 * @copyright Copyright (c) 2017 kocuj.pl
9
 * @package kocuj_di
10
 */
11
namespace Kocuj\Di;
12
13
use Kocuj\Di\Container\Container;
14
use Kocuj\Di\Container\ContainerInterface;
15
use Kocuj\Di\Service\ServiceFactory;
16
use Kocuj\Di\Service\ServiceFactoryInterface;
17
use Kocuj\Di\ServiceIdDecorator\ServiceIdDecorator;
18
use Kocuj\Di\ServiceIdDecorator\ServiceIdDecoratorInterface;
19
use Kocuj\Di\Tools\Camelizer\Camelizer;
20
21
/**
22
 * Dependency injection containers library
23
 */
24
class Di
25
{
26
27
    /**
28
     * Service identifier decorator
29
     *
30
     * @var ServiceIdDecoratorInterface
31
     */
32
    private $serviceIdDecorator;
33
34
    /**
35
     * Service factory
36
     *
37
     * @var ServiceFactoryInterface
38
     */
39
    private $serviceFactory;
40
41
    /**
42
     * Default dependency injection container for services
43
     *
44
     * @var ContainerInterface
45
     */
46
    private $defaultContainer;
47
48
    /**
49
     * Constructor
50
     *
51
     * @codeCoverageIgnore
52
     */
53
    public function __construct()
54
    {
55
        // remember arguments
56
        $this->serviceIdDecorator = new ServiceIdDecorator(new Camelizer());
57
        $this->serviceFactory = new ServiceFactory();
58
        // create default container
59
        $this->defaultContainer = $this->create();
60
    }
61
62
    /**
63
     * Create dependency injection container for services
64
     *
65
     * @return ContainerInterface New container
66
     *         @codeCoverageIgnore
67
     */
68
    public function create(): ContainerInterface
69
    {
70
        // exit
71
        return new Container($this->serviceIdDecorator, $this->serviceFactory);
72
    }
73
74
    /**
75
     * Copy container
76
     *
77
     * @param ContainerInterface $fromContainer
78
     *            Container from which copy will be made
79
     * @return ContainerInterface Copied container
80
     *         @codeCoverageIgnore
81
     */
82
    public function copy(ContainerInterface $fromContainer): ContainerInterface
83
    {
84
        // exit
85
        return clone $fromContainer;
86
    }
87
88
    /**
89
     * Get default dependency injection container for services
90
     *
91
     * @return ContainerInterface Default container
92
     *         @codeCoverageIgnore
93
     */
94
    public function getDefault(): ContainerInterface
95
    {
96
        // exit
97
        return $this->defaultContainer;
98
    }
99
}
100