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