|
1
|
|
|
<?php |
|
2
|
|
|
namespace EventEspresso\core\services\container; |
|
3
|
|
|
|
|
4
|
|
|
use EventEspresso\core\exceptions\InvalidClassException; |
|
5
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
6
|
|
|
use EventEspresso\core\exceptions\InvalidEntityException; |
|
7
|
|
|
use EventEspresso\core\exceptions\InvalidIdentifierException; |
|
8
|
|
|
use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
9
|
|
|
use EventEspresso\core\services\container\exceptions\ServiceNotFoundException; |
|
10
|
|
|
use OutOfBoundsException; |
|
11
|
|
|
|
|
12
|
|
|
defined('EVENT_ESPRESSO_VERSION') || exit; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class OpenCoffeeShop |
|
18
|
|
|
* Initialize and configure the CoffeeSop DI container |
|
19
|
|
|
* |
|
20
|
|
|
* @package Event Espresso |
|
21
|
|
|
* @author Brent Christensen |
|
22
|
|
|
* @since $VID:$ |
|
23
|
|
|
*/ |
|
24
|
|
|
class OpenCoffeeShop { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var CoffeeShop $CoffeeShop |
|
28
|
|
|
*/ |
|
29
|
|
|
private $CoffeeShop; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* OpenCoffeeShop constructor |
|
35
|
|
|
* |
|
36
|
|
|
* @throws InvalidInterfaceException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct() |
|
39
|
|
|
{ |
|
40
|
|
|
// instantiate the DI container |
|
41
|
|
|
$this->CoffeeShop = new CoffeeShop(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return CoffeeShop |
|
48
|
|
|
*/ |
|
49
|
|
|
public function CoffeeShop() { |
|
50
|
|
|
return $this->CoffeeShop; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* configure coffee makers which control the different kinds of brews |
|
57
|
|
|
* ( shared services, new factory objects, etc ) |
|
58
|
|
|
* |
|
59
|
|
|
* @throws InvalidEntityException |
|
60
|
|
|
*/ |
|
61
|
|
|
public function setupCoffeeMakers() { |
|
62
|
|
|
// create a dependency injector class for resolving class constructor arguments |
|
63
|
|
|
$DependencyInjector = new DependencyInjector( |
|
64
|
|
|
$this->CoffeeShop, |
|
65
|
|
|
new \EEH_Array() |
|
66
|
|
|
); |
|
67
|
|
|
// and some coffeemakers, one for creating new instances |
|
68
|
|
|
$this->CoffeeShop->addCoffeeMaker( |
|
69
|
|
|
new NewCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
70
|
|
|
CoffeeMaker::BREW_NEW |
|
71
|
|
|
); |
|
72
|
|
|
// one for shared services |
|
73
|
|
|
$this->CoffeeShop->addCoffeeMaker( |
|
74
|
|
|
new SharedCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
75
|
|
|
CoffeeMaker::BREW_SHARED |
|
76
|
|
|
); |
|
77
|
|
|
// and one for classes that only get loaded |
|
78
|
|
|
$this->CoffeeShop->addCoffeeMaker( |
|
79
|
|
|
new LoadOnlyCoffeeMaker($this->CoffeeShop, $DependencyInjector), |
|
80
|
|
|
CoffeeMaker::BREW_LOAD_ONLY |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Recipes define how to load legacy classes |
|
88
|
|
|
* |
|
89
|
|
|
* @throws InvalidIdentifierException |
|
90
|
|
|
*/ |
|
91
|
|
|
public function addRecipes() { |
|
92
|
|
|
// add default recipe, which should handle loading for most PSR-4 compatible classes |
|
93
|
|
|
// as long as they are not type hinting for interfaces |
|
94
|
|
|
$this->CoffeeShop->addRecipe( |
|
95
|
|
|
new Recipe( |
|
96
|
|
|
Recipe::DEFAULT_ID |
|
97
|
|
|
) |
|
98
|
|
|
); |
|
99
|
|
|
// PSR-4 compatible class with aliases |
|
100
|
|
|
$this->CoffeeShop->addRecipe( |
|
101
|
|
|
new Recipe( |
|
102
|
|
|
'CommandHandlerManager', |
|
103
|
|
|
'EventEspresso\core\services\commands\CommandHandlerManager', |
|
104
|
|
|
array( |
|
105
|
|
|
'CommandHandlerManagerInterface', |
|
106
|
|
|
'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
107
|
|
|
), |
|
108
|
|
|
array(), |
|
109
|
|
|
CoffeeMaker::BREW_SHARED |
|
110
|
|
|
) |
|
111
|
|
|
); |
|
112
|
|
|
// PSR-4 compatible class with aliases, which dependency on CommandHandlerManager |
|
113
|
|
|
$this->CoffeeShop->addRecipe( |
|
114
|
|
|
new Recipe( |
|
115
|
|
|
'CommandBus', |
|
116
|
|
|
'EventEspresso\core\services\commands\CommandBus', |
|
117
|
|
|
array( |
|
118
|
|
|
'CommandBusInterface', |
|
119
|
|
|
'EventEspresso\core\services\commands\CommandBusInterface', |
|
120
|
|
|
), |
|
121
|
|
|
array(), |
|
122
|
|
|
CoffeeMaker::BREW_SHARED |
|
123
|
|
|
) |
|
124
|
|
|
); |
|
125
|
|
|
// LEGACY classes that are NOT compatible with PSR-4 autoloading, and so must specify a filepath |
|
126
|
|
|
// add a wildcard recipe for loading legacy core interfaces |
|
127
|
|
|
$this->CoffeeShop->addRecipe( |
|
128
|
|
|
new Recipe( |
|
129
|
|
|
'EEI_*', |
|
130
|
|
|
'', |
|
131
|
|
|
array(), |
|
132
|
|
|
array(), |
|
133
|
|
|
CoffeeMaker::BREW_LOAD_ONLY, |
|
134
|
|
|
array( |
|
135
|
|
|
EE_INTERFACES . '*.php', |
|
136
|
|
|
EE_INTERFACES . '*.interfaces.php', |
|
137
|
|
|
) |
|
138
|
|
|
) |
|
139
|
|
|
); |
|
140
|
|
|
// add a wildcard recipe for loading models |
|
141
|
|
|
$this->CoffeeShop->addRecipe( |
|
142
|
|
|
new Recipe( |
|
143
|
|
|
'EEM_*', |
|
144
|
|
|
'', |
|
145
|
|
|
array(), |
|
146
|
|
|
array(), |
|
147
|
|
|
CoffeeMaker::BREW_SHARED, |
|
148
|
|
|
EE_MODELS . '*.model.php' |
|
149
|
|
|
) |
|
150
|
|
|
); |
|
151
|
|
|
// add a wildcard recipe for loading core classes |
|
152
|
|
|
$this->CoffeeShop->addRecipe( |
|
153
|
|
|
new Recipe( |
|
154
|
|
|
'EE_*', |
|
155
|
|
|
'', |
|
156
|
|
|
array(), |
|
157
|
|
|
array(), |
|
158
|
|
|
CoffeeMaker::BREW_SHARED, |
|
159
|
|
|
array( |
|
160
|
|
|
EE_CORE . '*.core.php', |
|
161
|
|
|
EE_ADMIN . '*.core.php', |
|
162
|
|
|
EE_CPTS . '*.core.php', |
|
163
|
|
|
EE_CORE . 'data_migration_scripts' . DS . '*.core.php', |
|
164
|
|
|
EE_CORE . 'request_stack' . DS . '*.core.php', |
|
165
|
|
|
EE_CORE . 'middleware' . DS . '*.core.php', |
|
166
|
|
|
) |
|
167
|
|
|
) |
|
168
|
|
|
); |
|
169
|
|
|
// load admin page parent class |
|
170
|
|
|
$this->CoffeeShop->addRecipe( |
|
171
|
|
|
new Recipe( |
|
172
|
|
|
'EE_Admin_Page*', |
|
173
|
|
|
'', |
|
174
|
|
|
array(), |
|
175
|
|
|
array(), |
|
176
|
|
|
CoffeeMaker::BREW_LOAD_ONLY, |
|
177
|
|
|
array( EE_ADMIN . '*.core.php' ) |
|
178
|
|
|
) |
|
179
|
|
|
); |
|
180
|
|
|
// add a wildcard recipe for loading core classes |
|
181
|
|
|
// $this->CoffeeShop->addRecipe( |
|
182
|
|
|
// new Recipe( |
|
183
|
|
|
// '*_Admin_Page', |
|
184
|
|
|
// '', |
|
185
|
|
|
// array(), |
|
186
|
|
|
// array(), |
|
187
|
|
|
// CoffeeMaker::BREW_SHARED, |
|
188
|
|
|
// array( |
|
189
|
|
|
// EE_ADMIN_PAGES . 'transactions' . DS . '*.core.php', |
|
190
|
|
|
// ) |
|
191
|
|
|
// ) |
|
192
|
|
|
// ); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
|
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* bootstrap EE and the request stack |
|
199
|
|
|
* |
|
200
|
|
|
* @throws ServiceNotFoundException |
|
201
|
|
|
* @throws InvalidClassException |
|
202
|
|
|
* @throws InvalidDataTypeException |
|
203
|
|
|
* @throws InvalidIdentifierException |
|
204
|
|
|
* @throws exceptions\ServiceExistsException |
|
205
|
|
|
* @throws OutOfBoundsException |
|
206
|
|
|
* @throws exceptions\InstantiationException |
|
207
|
|
|
*/ |
|
208
|
|
|
public function firstBrew() |
|
209
|
|
|
{ |
|
210
|
|
|
$this->CoffeeShop->brew('EE_Request', array($_GET, $_POST, $_COOKIE)); |
|
211
|
|
|
$this->CoffeeShop->brew('EE_Response'); |
|
212
|
|
|
$this->CoffeeShop->brew('EE_Bootstrap'); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
|
|
|
216
|
|
|
} |
|
217
|
|
|
// End of file OpenCoffeeShop.php |
|
218
|
|
|
// Location: /OpenCoffeeShop.php |
|
219
|
|
|
|