Completed
Branch FET/asset-manager (433489)
by
unknown
32:42 queued 18:11
created

BootstrapDependencyInjectionContainer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 123
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 123
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A buildDependencyInjectionContainer() 0 7 1
A buildLegacyDependencyInjectionContainer() 0 23 1
A buildLoader() 0 12 1
A getDependencyMap() 0 4 1
A getRegistry() 0 4 1
A getLoader() 0 4 1
1
<?php
2
3
namespace EventEspresso\core\services\bootstrap;
4
5
use EE_Dependency_Map;
6
use EE_Error;
7
use EE_Registry;
8
use EventEspresso\core\exceptions\InvalidDataTypeException;
9
use EventEspresso\core\exceptions\InvalidInterfaceException;
10
use EventEspresso\core\services\container\Mirror;
11
use EventEspresso\core\services\loaders\ClassInterfaceCache;
12
use EventEspresso\core\services\loaders\LoaderFactory;
13
use EventEspresso\core\services\loaders\LoaderInterface;
14
use EventEspresso\core\services\loaders\ObjectIdentifier;
15
use InvalidArgumentException;
16
17
/**
18
 * Class BootstrapDependencyInjectionContainer
19
 * Builds the main DI container
20
 *
21
 * @package EventEspresso\core\services\request
22
 * @author  Brent Christensen
23
 * @since   4.9.59.p
24
 */
25
class BootstrapDependencyInjectionContainer
26
{
27
28
    /**
29
     * @var EE_Dependency_Map $dependency_map
30
     */
31
    protected $dependency_map;
32
33
    /**
34
     * @type LoaderInterface $loader
35
     */
36
    protected $loader;
37
38
    /**
39
     * @var EE_Registry $registry
40
     */
41
    protected $registry;
42
43
    /**
44
     * @var ClassInterfaceCache $class_cache
45
     */
46
    private $class_cache;
47
48
    /**
49
     * @var Mirror
50
     */
51
    private $mirror;
52
53
    /**
54
     * @var ObjectIdentifier
55
     */
56
    private $object_identifier;
57
58
59
    /**
60
     * Can't use this just yet until we exorcise some more of our singleton usage from core
61
     */
62
    public function buildDependencyInjectionContainer()
63
    {
64
        // build DI container
65
        // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop();
66
        // $OpenCoffeeShop->addRecipes();
67
        // $CoffeeShop = $OpenCoffeeShop->CoffeeShop();
68
    }
69
70
71
    /**
72
     * Setups  EE_Registry and EE_Dependency_Map
73
     *
74
     * @throws EE_Error
75
     */
76
    public function buildLegacyDependencyInjectionContainer()
77
    {
78
        $this->class_cache = new ClassInterfaceCache();
79
        $this->object_identifier = new ObjectIdentifier($this->class_cache);
80
        $this->mirror = new Mirror();
81
        // EE_Dependency_Map: info about how to load classes required by other classes
82
        espresso_load_required(
83
            'EE_Dependency_Map',
84
            EE_CORE . 'EE_Dependency_Map.core.php'
85
        );
86
        $this->dependency_map = EE_Dependency_Map::instance($this->class_cache);
87
        // EE_Registry: central repository for classes (legacy)
88
        espresso_load_required(
89
            'EE_Registry',
90
            EE_CORE . 'EE_Registry.core.php'
91
        );
92
        $this->registry = EE_Registry::instance(
93
            $this->dependency_map,
94
            $this->mirror,
95
            $this->class_cache,
96
            $this->object_identifier
97
        );
98
    }
99
100
101
    /**
102
     * Performs initial setup for the generic Loader
103
     *
104
     * @throws InvalidDataTypeException
105
     * @throws InvalidInterfaceException
106
     * @throws InvalidArgumentException
107
     */
108
    public function buildLoader()
109
    {
110
        $this->loader = LoaderFactory::getLoader(
111
            $this->registry,
112
            $this->class_cache,
113
            $this->object_identifier
114
        );
115
        $this->loader->share('EventEspresso\core\services\loaders\ClassInterfaceCache', $this->class_cache);
116
        $this->loader->share('EventEspresso\core\services\loaders\ObjectIdentifier', $this->object_identifier);
117
        $this->loader->share('EventEspresso\core\services\container\Mirror', $this->mirror);
118
        $this->dependency_map->setLoader($this->loader);
119
    }
120
121
122
    /**
123
     * @return EE_Dependency_Map
124
     */
125
    public function getDependencyMap()
126
    {
127
        return $this->dependency_map;
128
    }
129
130
131
    /**
132
     * @return EE_Registry
133
     */
134
    public function getRegistry()
135
    {
136
        return $this->registry;
137
    }
138
139
140
    /**
141
     * @return LoaderInterface
142
     */
143
    public function getLoader()
144
    {
145
        return $this->loader;
146
    }
147
}
148