@@ -13,42 +13,42 @@ |
||
13 | 13 | */ |
14 | 14 | class AssetManifestException extends DomainException |
15 | 15 | { |
16 | - /** |
|
17 | - * AssetManifestException constructor |
|
18 | - * |
|
19 | - * @param string $entry |
|
20 | - * @param string $path |
|
21 | - * @param string $message |
|
22 | - * @param int $code |
|
23 | - * @param Exception $previous |
|
24 | - */ |
|
25 | - public function __construct($entry, $path, $message = '', $code = 0, Exception $previous = null) |
|
26 | - { |
|
27 | - if (empty($message)) { |
|
28 | - switch($entry) { |
|
29 | - case AssetManifest::KEY_DEPENDENCIES: |
|
30 | - $key = 'file'; |
|
31 | - break; |
|
32 | - case AssetManifest::KEY_VERSION: |
|
33 | - $key = 'version'; |
|
34 | - break; |
|
35 | - case AssetManifest::KEY_ENTRY_POINTS: |
|
36 | - case AssetManifest::KEY_FILES: |
|
37 | - default: |
|
38 | - $key = 'key'; |
|
39 | - } |
|
40 | - $message = |
|
41 | - sprintf( |
|
42 | - esc_html__( |
|
43 | - 'The "%1$s" %2$s was not found in the assets manifest file at: %3$s', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - $entry, |
|
47 | - $key, |
|
48 | - $path |
|
49 | - ); |
|
50 | - } |
|
51 | - parent::__construct($message, $code, $previous); |
|
52 | - } |
|
16 | + /** |
|
17 | + * AssetManifestException constructor |
|
18 | + * |
|
19 | + * @param string $entry |
|
20 | + * @param string $path |
|
21 | + * @param string $message |
|
22 | + * @param int $code |
|
23 | + * @param Exception $previous |
|
24 | + */ |
|
25 | + public function __construct($entry, $path, $message = '', $code = 0, Exception $previous = null) |
|
26 | + { |
|
27 | + if (empty($message)) { |
|
28 | + switch($entry) { |
|
29 | + case AssetManifest::KEY_DEPENDENCIES: |
|
30 | + $key = 'file'; |
|
31 | + break; |
|
32 | + case AssetManifest::KEY_VERSION: |
|
33 | + $key = 'version'; |
|
34 | + break; |
|
35 | + case AssetManifest::KEY_ENTRY_POINTS: |
|
36 | + case AssetManifest::KEY_FILES: |
|
37 | + default: |
|
38 | + $key = 'key'; |
|
39 | + } |
|
40 | + $message = |
|
41 | + sprintf( |
|
42 | + esc_html__( |
|
43 | + 'The "%1$s" %2$s was not found in the assets manifest file at: %3$s', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + $entry, |
|
47 | + $key, |
|
48 | + $path |
|
49 | + ); |
|
50 | + } |
|
51 | + parent::__construct($message, $code, $previous); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | public function __construct($entry, $path, $message = '', $code = 0, Exception $previous = null) |
26 | 26 | { |
27 | 27 | if (empty($message)) { |
28 | - switch($entry) { |
|
28 | + switch ($entry) { |
|
29 | 29 | case AssetManifest::KEY_DEPENDENCIES: |
30 | 30 | $key = 'file'; |
31 | 31 | break; |
@@ -14,328 +14,328 @@ |
||
14 | 14 | class AssetManifest implements AssetManifestInterface |
15 | 15 | { |
16 | 16 | |
17 | - const ASSET_EXT_CSS = '.css'; |
|
18 | - |
|
19 | - const ASSET_EXT_JS = '.js'; |
|
20 | - |
|
21 | - const ASSET_EXT_PHP = '.php'; |
|
22 | - |
|
23 | - const FILE_NAME = 'asset-manifest.json'; |
|
24 | - |
|
25 | - const KEY_DEPENDENCIES = 'dependencies'; |
|
26 | - |
|
27 | - const KEY_ENTRY_POINTS = 'entrypoints'; |
|
28 | - |
|
29 | - const KEY_FILES = 'files'; |
|
30 | - |
|
31 | - const KEY_VERSION = 'version'; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - private $asset_files; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - private $assets_namespace; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private $assets_path; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var DomainInterface |
|
51 | - */ |
|
52 | - protected $domain; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - private $entry_points; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - private $manifest; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - private $manifest_path; |
|
68 | - |
|
69 | - /** |
|
70 | - * This is a list of known handles that are used for css. |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - private $wp_css_handle_dependencies = [ |
|
74 | - 'wp-components', |
|
75 | - 'wp-block-editor', |
|
76 | - 'wp-block-library', |
|
77 | - 'wp-edit-post', |
|
78 | - 'wp-edit-widgets', |
|
79 | - 'wp-editor', |
|
80 | - 'wp-format-library', |
|
81 | - 'wp-list-reusable-blocks', |
|
82 | - 'wp-nux', |
|
83 | - ]; |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * AssetManifest constructor. |
|
88 | - * |
|
89 | - * @param DomainInterface $domain |
|
90 | - */ |
|
91 | - public function __construct(DomainInterface $domain) |
|
92 | - { |
|
93 | - $this->domain = $domain; |
|
94 | - $this->initialize(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public function initialize() |
|
102 | - { |
|
103 | - if (! $this->manifest) { |
|
104 | - $this->assets_namespace = $this->domain->assetNamespace(); |
|
105 | - $assets_path = $this->domain->distributionAssetsPath(); |
|
106 | - $this->assets_path = trailingslashit($assets_path); |
|
107 | - $this->setManifestFilepath(); |
|
108 | - $this->loadManifest(); |
|
109 | - $this->getAssetFiles(); |
|
110 | - $this->getEntryPoints(); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $manifest_path |
|
117 | - */ |
|
118 | - public function setManifestFilepath($manifest_path = '') |
|
119 | - { |
|
120 | - $manifest_path = $manifest_path ? $manifest_path : $this->assets_path . AssetManifest::FILE_NAME; |
|
121 | - if (! is_readable($manifest_path)) { |
|
122 | - throw new AssetManifestException( |
|
123 | - $manifest_path, |
|
124 | - '', |
|
125 | - sprintf( |
|
126 | - esc_html__( |
|
127 | - 'The "%1$s" file was not found or is not readable. Please verify that the file exists and has appropriate permissions.', |
|
128 | - 'event_espresso' |
|
129 | - ), |
|
130 | - $manifest_path |
|
131 | - ) |
|
132 | - ); |
|
133 | - } |
|
134 | - $this->manifest_path = $manifest_path; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - private function loadManifest() |
|
142 | - { |
|
143 | - if (! $this->manifest) { |
|
144 | - // TODO May be use WP File system? ¯\_(ツ)_/¯ |
|
145 | - $manifest_json = file_get_contents($this->manifest_path); |
|
146 | - $this->manifest = json_decode($manifest_json, true); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $file_name |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - private function trimAssetFilename($file_name) |
|
156 | - { |
|
157 | - return ltrim($file_name, '/'); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public function getAssetFiles() |
|
165 | - { |
|
166 | - if (! $this->asset_files) { |
|
167 | - if (empty($this->manifest[ AssetManifest::KEY_FILES ])) { |
|
168 | - if (WP_DEBUG) { |
|
169 | - throw new AssetManifestException(AssetManifest::KEY_FILES, $this->manifest_path); |
|
170 | - } |
|
171 | - return []; |
|
172 | - } |
|
173 | - $this->asset_files = $this->manifest[ AssetManifest::KEY_FILES ]; |
|
174 | - } |
|
175 | - return $this->asset_files; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - public function getEntryPoints() |
|
183 | - { |
|
184 | - if (! $this->entry_points) { |
|
185 | - if (empty($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ])) { |
|
186 | - if (WP_DEBUG) { |
|
187 | - throw new AssetManifestException(AssetManifest::KEY_ENTRY_POINTS, $this->manifest_path); |
|
188 | - } |
|
189 | - return []; |
|
190 | - } |
|
191 | - $this->entry_points = array_keys($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ]); |
|
192 | - } |
|
193 | - return $this->entry_points; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param string $entry_point |
|
199 | - * @param string $type |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - private function getAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
203 | - { |
|
204 | - return $this->hasAsset($entry_point, $type) |
|
205 | - ? $this->trimAssetFilename($this->asset_files[ $entry_point . $type ]) |
|
206 | - : ''; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $entry_point |
|
212 | - * @param string $type |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - public function getAssetDependencies($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
216 | - { |
|
217 | - $asset = $this->getAssetDetails($entry_point); |
|
218 | - if (! isset($asset[AssetManifest::KEY_DEPENDENCIES])) { |
|
219 | - return []; |
|
220 | - } |
|
221 | - $dependencies = $asset[AssetManifest::KEY_DEPENDENCIES]; |
|
222 | - // remove cyclical dependencies, if any |
|
223 | - if (($key = array_search($this->assets_namespace . '-' . $entry_point, $dependencies, true)) !== false) { |
|
224 | - unset($dependencies[ $key ]); |
|
225 | - } |
|
226 | - // currently need to derive dependencies for CSS from the JS dependencies |
|
227 | - if ($type === AssetManifest::ASSET_EXT_CSS) { |
|
228 | - $css_dependencies = []; |
|
229 | - foreach ($dependencies as $handle) { |
|
230 | - $dependency_style = $this->getEntryPointFromHandle($handle) . AssetManifest::ASSET_EXT_CSS; |
|
231 | - if (isset($this->asset_files[ $dependency_style ]) |
|
232 | - || in_array($handle, $this->wp_css_handle_dependencies) |
|
233 | - ) { |
|
234 | - $css_dependencies[] = $handle; |
|
235 | - } |
|
236 | - } |
|
237 | - return $css_dependencies; |
|
238 | - } |
|
239 | - return $dependencies; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string $entry_point |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - public function getAssetDetails($entry_point) |
|
248 | - { |
|
249 | - $file_name = $this->getAsset($entry_point, AssetManifest::ASSET_EXT_PHP); |
|
250 | - if (! $file_name) { |
|
251 | - return []; |
|
252 | - } |
|
253 | - $full_path = $this->assets_path . $file_name; |
|
254 | - if (! is_readable($full_path)) { |
|
255 | - if (WP_DEBUG) { |
|
256 | - throw new AssetManifestException(AssetManifest::KEY_DEPENDENCIES, $full_path); |
|
257 | - } |
|
258 | - return []; |
|
259 | - } |
|
260 | - return require($full_path); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param string $entry_point |
|
266 | - * @return string|int|false |
|
267 | - */ |
|
268 | - public function getAssetHandle($entry_point) |
|
269 | - { |
|
270 | - return $this->assets_namespace . '-' . $entry_point; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - public function getAssetsPath() |
|
278 | - { |
|
279 | - return $this->assets_path; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @param string $handle |
|
285 | - * @return string|int|false |
|
286 | - */ |
|
287 | - private function getEntryPointFromHandle($handle) |
|
288 | - { $find = $this->assets_namespace . '-'; |
|
289 | - return str_replace($find, '', $handle); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @param string $entry_point |
|
295 | - * @param string $type |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - public function getAssetPath($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
299 | - { |
|
300 | - $file_name = $this->getAsset($entry_point, $type); |
|
301 | - return $file_name ? $this->domain->distributionAssetsPath($file_name) : ''; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @param string $entry_point |
|
307 | - * @param string $type |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - public function getAssetUrl($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
311 | - { |
|
312 | - $file_name = $this->getAsset($entry_point, $type); |
|
313 | - return $file_name ? $this->domain->distributionAssetsUrl($file_name) : ''; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * @param string $entry_point |
|
319 | - * @param string $type |
|
320 | - * @return string|int|false |
|
321 | - */ |
|
322 | - public function getAssetVersion($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
323 | - { |
|
324 | - $asset = $this->getAssetDetails($entry_point); |
|
325 | - return $type === AssetManifest::ASSET_EXT_JS && isset($asset[AssetManifest::KEY_VERSION]) |
|
326 | - ? $asset[AssetManifest::KEY_VERSION] |
|
327 | - : filemtime($this->getAssetPath($entry_point, $type)); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @param string $entry_point |
|
333 | - * @param string $type |
|
334 | - * @return string |
|
335 | - */ |
|
336 | - public function hasAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
337 | - { |
|
338 | - $file_name = $entry_point . $type; |
|
339 | - return ! empty($this->asset_files[ $file_name ]); |
|
340 | - } |
|
17 | + const ASSET_EXT_CSS = '.css'; |
|
18 | + |
|
19 | + const ASSET_EXT_JS = '.js'; |
|
20 | + |
|
21 | + const ASSET_EXT_PHP = '.php'; |
|
22 | + |
|
23 | + const FILE_NAME = 'asset-manifest.json'; |
|
24 | + |
|
25 | + const KEY_DEPENDENCIES = 'dependencies'; |
|
26 | + |
|
27 | + const KEY_ENTRY_POINTS = 'entrypoints'; |
|
28 | + |
|
29 | + const KEY_FILES = 'files'; |
|
30 | + |
|
31 | + const KEY_VERSION = 'version'; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + private $asset_files; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + private $assets_namespace; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $assets_path; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var DomainInterface |
|
51 | + */ |
|
52 | + protected $domain; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + private $entry_points; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + private $manifest; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + private $manifest_path; |
|
68 | + |
|
69 | + /** |
|
70 | + * This is a list of known handles that are used for css. |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + private $wp_css_handle_dependencies = [ |
|
74 | + 'wp-components', |
|
75 | + 'wp-block-editor', |
|
76 | + 'wp-block-library', |
|
77 | + 'wp-edit-post', |
|
78 | + 'wp-edit-widgets', |
|
79 | + 'wp-editor', |
|
80 | + 'wp-format-library', |
|
81 | + 'wp-list-reusable-blocks', |
|
82 | + 'wp-nux', |
|
83 | + ]; |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * AssetManifest constructor. |
|
88 | + * |
|
89 | + * @param DomainInterface $domain |
|
90 | + */ |
|
91 | + public function __construct(DomainInterface $domain) |
|
92 | + { |
|
93 | + $this->domain = $domain; |
|
94 | + $this->initialize(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public function initialize() |
|
102 | + { |
|
103 | + if (! $this->manifest) { |
|
104 | + $this->assets_namespace = $this->domain->assetNamespace(); |
|
105 | + $assets_path = $this->domain->distributionAssetsPath(); |
|
106 | + $this->assets_path = trailingslashit($assets_path); |
|
107 | + $this->setManifestFilepath(); |
|
108 | + $this->loadManifest(); |
|
109 | + $this->getAssetFiles(); |
|
110 | + $this->getEntryPoints(); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $manifest_path |
|
117 | + */ |
|
118 | + public function setManifestFilepath($manifest_path = '') |
|
119 | + { |
|
120 | + $manifest_path = $manifest_path ? $manifest_path : $this->assets_path . AssetManifest::FILE_NAME; |
|
121 | + if (! is_readable($manifest_path)) { |
|
122 | + throw new AssetManifestException( |
|
123 | + $manifest_path, |
|
124 | + '', |
|
125 | + sprintf( |
|
126 | + esc_html__( |
|
127 | + 'The "%1$s" file was not found or is not readable. Please verify that the file exists and has appropriate permissions.', |
|
128 | + 'event_espresso' |
|
129 | + ), |
|
130 | + $manifest_path |
|
131 | + ) |
|
132 | + ); |
|
133 | + } |
|
134 | + $this->manifest_path = $manifest_path; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + private function loadManifest() |
|
142 | + { |
|
143 | + if (! $this->manifest) { |
|
144 | + // TODO May be use WP File system? ¯\_(ツ)_/¯ |
|
145 | + $manifest_json = file_get_contents($this->manifest_path); |
|
146 | + $this->manifest = json_decode($manifest_json, true); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $file_name |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + private function trimAssetFilename($file_name) |
|
156 | + { |
|
157 | + return ltrim($file_name, '/'); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public function getAssetFiles() |
|
165 | + { |
|
166 | + if (! $this->asset_files) { |
|
167 | + if (empty($this->manifest[ AssetManifest::KEY_FILES ])) { |
|
168 | + if (WP_DEBUG) { |
|
169 | + throw new AssetManifestException(AssetManifest::KEY_FILES, $this->manifest_path); |
|
170 | + } |
|
171 | + return []; |
|
172 | + } |
|
173 | + $this->asset_files = $this->manifest[ AssetManifest::KEY_FILES ]; |
|
174 | + } |
|
175 | + return $this->asset_files; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + public function getEntryPoints() |
|
183 | + { |
|
184 | + if (! $this->entry_points) { |
|
185 | + if (empty($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ])) { |
|
186 | + if (WP_DEBUG) { |
|
187 | + throw new AssetManifestException(AssetManifest::KEY_ENTRY_POINTS, $this->manifest_path); |
|
188 | + } |
|
189 | + return []; |
|
190 | + } |
|
191 | + $this->entry_points = array_keys($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ]); |
|
192 | + } |
|
193 | + return $this->entry_points; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param string $entry_point |
|
199 | + * @param string $type |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + private function getAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
203 | + { |
|
204 | + return $this->hasAsset($entry_point, $type) |
|
205 | + ? $this->trimAssetFilename($this->asset_files[ $entry_point . $type ]) |
|
206 | + : ''; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $entry_point |
|
212 | + * @param string $type |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + public function getAssetDependencies($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
216 | + { |
|
217 | + $asset = $this->getAssetDetails($entry_point); |
|
218 | + if (! isset($asset[AssetManifest::KEY_DEPENDENCIES])) { |
|
219 | + return []; |
|
220 | + } |
|
221 | + $dependencies = $asset[AssetManifest::KEY_DEPENDENCIES]; |
|
222 | + // remove cyclical dependencies, if any |
|
223 | + if (($key = array_search($this->assets_namespace . '-' . $entry_point, $dependencies, true)) !== false) { |
|
224 | + unset($dependencies[ $key ]); |
|
225 | + } |
|
226 | + // currently need to derive dependencies for CSS from the JS dependencies |
|
227 | + if ($type === AssetManifest::ASSET_EXT_CSS) { |
|
228 | + $css_dependencies = []; |
|
229 | + foreach ($dependencies as $handle) { |
|
230 | + $dependency_style = $this->getEntryPointFromHandle($handle) . AssetManifest::ASSET_EXT_CSS; |
|
231 | + if (isset($this->asset_files[ $dependency_style ]) |
|
232 | + || in_array($handle, $this->wp_css_handle_dependencies) |
|
233 | + ) { |
|
234 | + $css_dependencies[] = $handle; |
|
235 | + } |
|
236 | + } |
|
237 | + return $css_dependencies; |
|
238 | + } |
|
239 | + return $dependencies; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string $entry_point |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + public function getAssetDetails($entry_point) |
|
248 | + { |
|
249 | + $file_name = $this->getAsset($entry_point, AssetManifest::ASSET_EXT_PHP); |
|
250 | + if (! $file_name) { |
|
251 | + return []; |
|
252 | + } |
|
253 | + $full_path = $this->assets_path . $file_name; |
|
254 | + if (! is_readable($full_path)) { |
|
255 | + if (WP_DEBUG) { |
|
256 | + throw new AssetManifestException(AssetManifest::KEY_DEPENDENCIES, $full_path); |
|
257 | + } |
|
258 | + return []; |
|
259 | + } |
|
260 | + return require($full_path); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param string $entry_point |
|
266 | + * @return string|int|false |
|
267 | + */ |
|
268 | + public function getAssetHandle($entry_point) |
|
269 | + { |
|
270 | + return $this->assets_namespace . '-' . $entry_point; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + public function getAssetsPath() |
|
278 | + { |
|
279 | + return $this->assets_path; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @param string $handle |
|
285 | + * @return string|int|false |
|
286 | + */ |
|
287 | + private function getEntryPointFromHandle($handle) |
|
288 | + { $find = $this->assets_namespace . '-'; |
|
289 | + return str_replace($find, '', $handle); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param string $entry_point |
|
295 | + * @param string $type |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + public function getAssetPath($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
299 | + { |
|
300 | + $file_name = $this->getAsset($entry_point, $type); |
|
301 | + return $file_name ? $this->domain->distributionAssetsPath($file_name) : ''; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @param string $entry_point |
|
307 | + * @param string $type |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + public function getAssetUrl($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
311 | + { |
|
312 | + $file_name = $this->getAsset($entry_point, $type); |
|
313 | + return $file_name ? $this->domain->distributionAssetsUrl($file_name) : ''; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * @param string $entry_point |
|
319 | + * @param string $type |
|
320 | + * @return string|int|false |
|
321 | + */ |
|
322 | + public function getAssetVersion($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
323 | + { |
|
324 | + $asset = $this->getAssetDetails($entry_point); |
|
325 | + return $type === AssetManifest::ASSET_EXT_JS && isset($asset[AssetManifest::KEY_VERSION]) |
|
326 | + ? $asset[AssetManifest::KEY_VERSION] |
|
327 | + : filemtime($this->getAssetPath($entry_point, $type)); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @param string $entry_point |
|
333 | + * @param string $type |
|
334 | + * @return string |
|
335 | + */ |
|
336 | + public function hasAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
337 | + { |
|
338 | + $file_name = $entry_point . $type; |
|
339 | + return ! empty($this->asset_files[ $file_name ]); |
|
340 | + } |
|
341 | 341 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | class AssetManifest implements AssetManifestInterface |
15 | 15 | { |
16 | 16 | |
17 | - const ASSET_EXT_CSS = '.css'; |
|
17 | + const ASSET_EXT_CSS = '.css'; |
|
18 | 18 | |
19 | 19 | const ASSET_EXT_JS = '.js'; |
20 | 20 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function initialize() |
102 | 102 | { |
103 | - if (! $this->manifest) { |
|
103 | + if ( ! $this->manifest) { |
|
104 | 104 | $this->assets_namespace = $this->domain->assetNamespace(); |
105 | 105 | $assets_path = $this->domain->distributionAssetsPath(); |
106 | 106 | $this->assets_path = trailingslashit($assets_path); |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function setManifestFilepath($manifest_path = '') |
119 | 119 | { |
120 | - $manifest_path = $manifest_path ? $manifest_path : $this->assets_path . AssetManifest::FILE_NAME; |
|
121 | - if (! is_readable($manifest_path)) { |
|
120 | + $manifest_path = $manifest_path ? $manifest_path : $this->assets_path.AssetManifest::FILE_NAME; |
|
121 | + if ( ! is_readable($manifest_path)) { |
|
122 | 122 | throw new AssetManifestException( |
123 | 123 | $manifest_path, |
124 | 124 | '', |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | private function loadManifest() |
142 | 142 | { |
143 | - if (! $this->manifest) { |
|
143 | + if ( ! $this->manifest) { |
|
144 | 144 | // TODO May be use WP File system? ¯\_(ツ)_/¯ |
145 | 145 | $manifest_json = file_get_contents($this->manifest_path); |
146 | 146 | $this->manifest = json_decode($manifest_json, true); |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function getAssetFiles() |
165 | 165 | { |
166 | - if (! $this->asset_files) { |
|
167 | - if (empty($this->manifest[ AssetManifest::KEY_FILES ])) { |
|
166 | + if ( ! $this->asset_files) { |
|
167 | + if (empty($this->manifest[AssetManifest::KEY_FILES])) { |
|
168 | 168 | if (WP_DEBUG) { |
169 | 169 | throw new AssetManifestException(AssetManifest::KEY_FILES, $this->manifest_path); |
170 | 170 | } |
171 | 171 | return []; |
172 | 172 | } |
173 | - $this->asset_files = $this->manifest[ AssetManifest::KEY_FILES ]; |
|
173 | + $this->asset_files = $this->manifest[AssetManifest::KEY_FILES]; |
|
174 | 174 | } |
175 | 175 | return $this->asset_files; |
176 | 176 | } |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function getEntryPoints() |
183 | 183 | { |
184 | - if (! $this->entry_points) { |
|
185 | - if (empty($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ])) { |
|
184 | + if ( ! $this->entry_points) { |
|
185 | + if (empty($this->manifest[AssetManifest::KEY_ENTRY_POINTS])) { |
|
186 | 186 | if (WP_DEBUG) { |
187 | 187 | throw new AssetManifestException(AssetManifest::KEY_ENTRY_POINTS, $this->manifest_path); |
188 | 188 | } |
189 | 189 | return []; |
190 | 190 | } |
191 | - $this->entry_points = array_keys($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ]); |
|
191 | + $this->entry_points = array_keys($this->manifest[AssetManifest::KEY_ENTRY_POINTS]); |
|
192 | 192 | } |
193 | 193 | return $this->entry_points; |
194 | 194 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | private function getAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
203 | 203 | { |
204 | 204 | return $this->hasAsset($entry_point, $type) |
205 | - ? $this->trimAssetFilename($this->asset_files[ $entry_point . $type ]) |
|
205 | + ? $this->trimAssetFilename($this->asset_files[$entry_point.$type]) |
|
206 | 206 | : ''; |
207 | 207 | } |
208 | 208 | |
@@ -215,20 +215,20 @@ discard block |
||
215 | 215 | public function getAssetDependencies($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
216 | 216 | { |
217 | 217 | $asset = $this->getAssetDetails($entry_point); |
218 | - if (! isset($asset[AssetManifest::KEY_DEPENDENCIES])) { |
|
218 | + if ( ! isset($asset[AssetManifest::KEY_DEPENDENCIES])) { |
|
219 | 219 | return []; |
220 | 220 | } |
221 | 221 | $dependencies = $asset[AssetManifest::KEY_DEPENDENCIES]; |
222 | 222 | // remove cyclical dependencies, if any |
223 | - if (($key = array_search($this->assets_namespace . '-' . $entry_point, $dependencies, true)) !== false) { |
|
224 | - unset($dependencies[ $key ]); |
|
223 | + if (($key = array_search($this->assets_namespace.'-'.$entry_point, $dependencies, true)) !== false) { |
|
224 | + unset($dependencies[$key]); |
|
225 | 225 | } |
226 | 226 | // currently need to derive dependencies for CSS from the JS dependencies |
227 | 227 | if ($type === AssetManifest::ASSET_EXT_CSS) { |
228 | 228 | $css_dependencies = []; |
229 | 229 | foreach ($dependencies as $handle) { |
230 | - $dependency_style = $this->getEntryPointFromHandle($handle) . AssetManifest::ASSET_EXT_CSS; |
|
231 | - if (isset($this->asset_files[ $dependency_style ]) |
|
230 | + $dependency_style = $this->getEntryPointFromHandle($handle).AssetManifest::ASSET_EXT_CSS; |
|
231 | + if (isset($this->asset_files[$dependency_style]) |
|
232 | 232 | || in_array($handle, $this->wp_css_handle_dependencies) |
233 | 233 | ) { |
234 | 234 | $css_dependencies[] = $handle; |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | public function getAssetDetails($entry_point) |
248 | 248 | { |
249 | 249 | $file_name = $this->getAsset($entry_point, AssetManifest::ASSET_EXT_PHP); |
250 | - if (! $file_name) { |
|
250 | + if ( ! $file_name) { |
|
251 | 251 | return []; |
252 | 252 | } |
253 | - $full_path = $this->assets_path . $file_name; |
|
254 | - if (! is_readable($full_path)) { |
|
253 | + $full_path = $this->assets_path.$file_name; |
|
254 | + if ( ! is_readable($full_path)) { |
|
255 | 255 | if (WP_DEBUG) { |
256 | 256 | throw new AssetManifestException(AssetManifest::KEY_DEPENDENCIES, $full_path); |
257 | 257 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function getAssetHandle($entry_point) |
269 | 269 | { |
270 | - return $this->assets_namespace . '-' . $entry_point; |
|
270 | + return $this->assets_namespace.'-'.$entry_point; |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @return string|int|false |
286 | 286 | */ |
287 | 287 | private function getEntryPointFromHandle($handle) |
288 | - { $find = $this->assets_namespace . '-'; |
|
288 | + { $find = $this->assets_namespace.'-'; |
|
289 | 289 | return str_replace($find, '', $handle); |
290 | 290 | } |
291 | 291 | |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function hasAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
337 | 337 | { |
338 | - $file_name = $entry_point . $type; |
|
339 | - return ! empty($this->asset_files[ $file_name ]); |
|
338 | + $file_name = $entry_point.$type; |
|
339 | + return ! empty($this->asset_files[$file_name]); |
|
340 | 340 | } |
341 | 341 | } |
@@ -24,598 +24,598 @@ |
||
24 | 24 | class Registry |
25 | 25 | { |
26 | 26 | |
27 | - const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var AssetCollection[] $assets |
|
31 | - */ |
|
32 | - protected $assets = []; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var AssetManifestInterface |
|
36 | - */ |
|
37 | - private $asset_manifest; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var I18nRegistry |
|
41 | - */ |
|
42 | - private $i18n_registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $jsdata = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
53 | - * page source. |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - private $script_handles_with_data = array(); |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Registry constructor. |
|
62 | - * Hooking into WP actions for script registry. |
|
63 | - * |
|
64 | - * @param AssetCollection $assets |
|
65 | - * @param AssetManifestInterface $asset_manifest |
|
66 | - * @param I18nRegistry $i18n_registry |
|
67 | - * @throws InvalidArgumentException |
|
68 | - * @throws InvalidDataTypeException |
|
69 | - * @throws InvalidInterfaceException |
|
70 | - */ |
|
71 | - public function __construct(AssetCollection $assets, AssetManifestInterface $asset_manifest, I18nRegistry $i18n_registry) |
|
72 | - { |
|
73 | - $this->addAssetCollection($assets); |
|
74 | - $this->asset_manifest = $asset_manifest; |
|
75 | - $this->asset_manifest->initialize(); |
|
76 | - $this->i18n_registry = $i18n_registry; |
|
77 | - add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4); |
|
78 | - add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4); |
|
79 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 5); |
|
80 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 5); |
|
81 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
82 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param AssetCollection $asset_collection |
|
88 | - */ |
|
89 | - public function addAssetCollection(AssetCollection $asset_collection) |
|
90 | - { |
|
91 | - $id = $asset_collection->collectionIdentifier(); |
|
92 | - if (! array_key_exists($id, $this->assets)) { |
|
93 | - $this->assets[ $id ] = $asset_collection; |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
102 | - * translation handling. |
|
103 | - * |
|
104 | - * @return I18nRegistry |
|
105 | - */ |
|
106 | - public function getI18nRegistry() |
|
107 | - { |
|
108 | - return $this->i18n_registry; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Callback for the wp_enqueue_scripts actions used to register assets. |
|
114 | - * |
|
115 | - * @since 4.9.62.p |
|
116 | - * @throws Exception |
|
117 | - */ |
|
118 | - public function registerScriptsAndStyles() |
|
119 | - { |
|
120 | - try { |
|
121 | - foreach ($this->assets as $asset_collection) { |
|
122 | - $this->registerScripts($asset_collection->getJavascriptAssets()); |
|
123 | - $this->registerStyles($asset_collection->getStylesheetAssets()); |
|
124 | - } |
|
125 | - } catch (Exception $exception) { |
|
126 | - new ExceptionStackTraceDisplay($exception); |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * Registers JS assets with WP core |
|
133 | - * |
|
134 | - * @param JavascriptAsset[] $scripts |
|
135 | - * @throws AssetRegistrationException |
|
136 | - * @throws InvalidDataTypeException |
|
137 | - * @throws DomainException |
|
138 | - * @since 4.9.62.p |
|
139 | - */ |
|
140 | - public function registerScripts(array $scripts) |
|
141 | - { |
|
142 | - foreach ($scripts as $script) { |
|
143 | - // skip to next script if this has already been done |
|
144 | - if ($script->isRegistered()) { |
|
145 | - continue; |
|
146 | - } |
|
147 | - do_action( |
|
148 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
149 | - $script |
|
150 | - ); |
|
151 | - $registered = wp_register_script( |
|
152 | - $script->handle(), |
|
153 | - $script->source(), |
|
154 | - $script->dependencies(), |
|
155 | - $script->version(), |
|
156 | - $script->loadInFooter() |
|
157 | - ); |
|
158 | - if (! $registered && $this->debug()) { |
|
159 | - throw new AssetRegistrationException($script->handle()); |
|
160 | - } |
|
161 | - $script->setRegistered($registered); |
|
162 | - if ($script->requiresTranslation()) { |
|
163 | - $this->registerTranslation($script->handle()); |
|
164 | - } |
|
165 | - if ($script->enqueueImmediately()) { |
|
166 | - wp_enqueue_script($script->handle()); |
|
167 | - } |
|
168 | - do_action( |
|
169 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
170 | - $script |
|
171 | - ); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - /** |
|
177 | - * Registers CSS assets with WP core |
|
178 | - * |
|
179 | - * @param StylesheetAsset[] $styles |
|
180 | - * @throws InvalidDataTypeException |
|
181 | - * @throws DomainException |
|
182 | - * @since 4.9.62.p |
|
183 | - */ |
|
184 | - public function registerStyles(array $styles) |
|
185 | - { |
|
186 | - foreach ($styles as $style) { |
|
187 | - // skip to next style if this has already been done |
|
188 | - if ($style->isRegistered()) { |
|
189 | - continue; |
|
190 | - } |
|
191 | - do_action( |
|
192 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
193 | - $style |
|
194 | - ); |
|
195 | - wp_register_style( |
|
196 | - $style->handle(), |
|
197 | - $style->source(), |
|
198 | - $style->dependencies(), |
|
199 | - $style->version(), |
|
200 | - $style->media() |
|
201 | - ); |
|
202 | - $style->setRegistered(); |
|
203 | - if ($style->enqueueImmediately()) { |
|
204 | - wp_enqueue_style($style->handle()); |
|
205 | - } |
|
206 | - do_action( |
|
207 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
208 | - $style |
|
209 | - ); |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Call back for the script print in frontend and backend. |
|
216 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
217 | - * |
|
218 | - * @throws Exception |
|
219 | - * @since 4.9.31.rc.015 |
|
220 | - */ |
|
221 | - public function enqueueData() |
|
222 | - { |
|
223 | - try { |
|
224 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
225 | - wp_add_inline_script( |
|
226 | - 'eejs-core', |
|
227 | - 'var eejsdata=' . wp_json_encode(['data' => $this->jsdata]), |
|
228 | - 'before' |
|
229 | - ); |
|
230 | - foreach ($this->assets as $asset_collection) { |
|
231 | - $scripts = $asset_collection->getJavascriptAssetsWithData(); |
|
232 | - foreach ($scripts as $script) { |
|
233 | - $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
234 | - if ($script->hasInlineDataCallback()) { |
|
235 | - $localize = $script->inlineDataCallback(); |
|
236 | - $localize(); |
|
237 | - } |
|
238 | - } |
|
239 | - } |
|
240 | - } catch (Exception $exception) { |
|
241 | - EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
242 | - new ExceptionStackTraceDisplay($exception); |
|
243 | - } |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Used to add data to eejs.data object. |
|
249 | - * Note: Overriding existing data is not allowed. |
|
250 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
251 | - * If the data you add is something like this: |
|
252 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
253 | - * It will be exposed in the page source as: |
|
254 | - * eejs.data.my_plugin_data.foo == gar |
|
255 | - * |
|
256 | - * @param string $key Key used to access your data |
|
257 | - * @param string|array $value Value to attach to key |
|
258 | - * @throws InvalidArgumentException |
|
259 | - */ |
|
260 | - public function addData($key, $value) |
|
261 | - { |
|
262 | - if ($this->verifyDataNotExisting($key)) { |
|
263 | - $this->jsdata[ $key ] = $value; |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
270 | - * elements in an array. |
|
271 | - * |
|
272 | - * When you use this method, the value you include will be merged with the array on $key. |
|
273 | - * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript |
|
274 | - * object like this, eejs.data.test = [ my_data, |
|
275 | - * ] |
|
276 | - * If there has already been a scalar value attached to the data object given key (via addData for instance), then |
|
277 | - * this will throw an exception. |
|
278 | - * |
|
279 | - * Caution: Only add data using this method if you are okay with the potential for additional data added on the same |
|
280 | - * key potentially overriding the existing data on merge (specifically with associative arrays). |
|
281 | - * |
|
282 | - * @param string $key Key to attach data to. |
|
283 | - * @param string|array $value Value being registered. |
|
284 | - * @throws InvalidArgumentException |
|
285 | - */ |
|
286 | - public function pushData($key, $value) |
|
287 | - { |
|
288 | - if (isset($this->jsdata[ $key ]) |
|
289 | - && ! is_array($this->jsdata[ $key ]) |
|
290 | - ) { |
|
291 | - if (! $this->debug()) { |
|
292 | - return; |
|
293 | - } |
|
294 | - throw new InvalidArgumentException( |
|
295 | - sprintf( |
|
296 | - __( |
|
297 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
27 | + const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json'; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var AssetCollection[] $assets |
|
31 | + */ |
|
32 | + protected $assets = []; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var AssetManifestInterface |
|
36 | + */ |
|
37 | + private $asset_manifest; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var I18nRegistry |
|
41 | + */ |
|
42 | + private $i18n_registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $jsdata = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
53 | + * page source. |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + private $script_handles_with_data = array(); |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Registry constructor. |
|
62 | + * Hooking into WP actions for script registry. |
|
63 | + * |
|
64 | + * @param AssetCollection $assets |
|
65 | + * @param AssetManifestInterface $asset_manifest |
|
66 | + * @param I18nRegistry $i18n_registry |
|
67 | + * @throws InvalidArgumentException |
|
68 | + * @throws InvalidDataTypeException |
|
69 | + * @throws InvalidInterfaceException |
|
70 | + */ |
|
71 | + public function __construct(AssetCollection $assets, AssetManifestInterface $asset_manifest, I18nRegistry $i18n_registry) |
|
72 | + { |
|
73 | + $this->addAssetCollection($assets); |
|
74 | + $this->asset_manifest = $asset_manifest; |
|
75 | + $this->asset_manifest->initialize(); |
|
76 | + $this->i18n_registry = $i18n_registry; |
|
77 | + add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4); |
|
78 | + add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 4); |
|
79 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 5); |
|
80 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 5); |
|
81 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
82 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param AssetCollection $asset_collection |
|
88 | + */ |
|
89 | + public function addAssetCollection(AssetCollection $asset_collection) |
|
90 | + { |
|
91 | + $id = $asset_collection->collectionIdentifier(); |
|
92 | + if (! array_key_exists($id, $this->assets)) { |
|
93 | + $this->assets[ $id ] = $asset_collection; |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
102 | + * translation handling. |
|
103 | + * |
|
104 | + * @return I18nRegistry |
|
105 | + */ |
|
106 | + public function getI18nRegistry() |
|
107 | + { |
|
108 | + return $this->i18n_registry; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Callback for the wp_enqueue_scripts actions used to register assets. |
|
114 | + * |
|
115 | + * @since 4.9.62.p |
|
116 | + * @throws Exception |
|
117 | + */ |
|
118 | + public function registerScriptsAndStyles() |
|
119 | + { |
|
120 | + try { |
|
121 | + foreach ($this->assets as $asset_collection) { |
|
122 | + $this->registerScripts($asset_collection->getJavascriptAssets()); |
|
123 | + $this->registerStyles($asset_collection->getStylesheetAssets()); |
|
124 | + } |
|
125 | + } catch (Exception $exception) { |
|
126 | + new ExceptionStackTraceDisplay($exception); |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * Registers JS assets with WP core |
|
133 | + * |
|
134 | + * @param JavascriptAsset[] $scripts |
|
135 | + * @throws AssetRegistrationException |
|
136 | + * @throws InvalidDataTypeException |
|
137 | + * @throws DomainException |
|
138 | + * @since 4.9.62.p |
|
139 | + */ |
|
140 | + public function registerScripts(array $scripts) |
|
141 | + { |
|
142 | + foreach ($scripts as $script) { |
|
143 | + // skip to next script if this has already been done |
|
144 | + if ($script->isRegistered()) { |
|
145 | + continue; |
|
146 | + } |
|
147 | + do_action( |
|
148 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
149 | + $script |
|
150 | + ); |
|
151 | + $registered = wp_register_script( |
|
152 | + $script->handle(), |
|
153 | + $script->source(), |
|
154 | + $script->dependencies(), |
|
155 | + $script->version(), |
|
156 | + $script->loadInFooter() |
|
157 | + ); |
|
158 | + if (! $registered && $this->debug()) { |
|
159 | + throw new AssetRegistrationException($script->handle()); |
|
160 | + } |
|
161 | + $script->setRegistered($registered); |
|
162 | + if ($script->requiresTranslation()) { |
|
163 | + $this->registerTranslation($script->handle()); |
|
164 | + } |
|
165 | + if ($script->enqueueImmediately()) { |
|
166 | + wp_enqueue_script($script->handle()); |
|
167 | + } |
|
168 | + do_action( |
|
169 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
170 | + $script |
|
171 | + ); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + /** |
|
177 | + * Registers CSS assets with WP core |
|
178 | + * |
|
179 | + * @param StylesheetAsset[] $styles |
|
180 | + * @throws InvalidDataTypeException |
|
181 | + * @throws DomainException |
|
182 | + * @since 4.9.62.p |
|
183 | + */ |
|
184 | + public function registerStyles(array $styles) |
|
185 | + { |
|
186 | + foreach ($styles as $style) { |
|
187 | + // skip to next style if this has already been done |
|
188 | + if ($style->isRegistered()) { |
|
189 | + continue; |
|
190 | + } |
|
191 | + do_action( |
|
192 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
193 | + $style |
|
194 | + ); |
|
195 | + wp_register_style( |
|
196 | + $style->handle(), |
|
197 | + $style->source(), |
|
198 | + $style->dependencies(), |
|
199 | + $style->version(), |
|
200 | + $style->media() |
|
201 | + ); |
|
202 | + $style->setRegistered(); |
|
203 | + if ($style->enqueueImmediately()) { |
|
204 | + wp_enqueue_style($style->handle()); |
|
205 | + } |
|
206 | + do_action( |
|
207 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
208 | + $style |
|
209 | + ); |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Call back for the script print in frontend and backend. |
|
216 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
217 | + * |
|
218 | + * @throws Exception |
|
219 | + * @since 4.9.31.rc.015 |
|
220 | + */ |
|
221 | + public function enqueueData() |
|
222 | + { |
|
223 | + try { |
|
224 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
225 | + wp_add_inline_script( |
|
226 | + 'eejs-core', |
|
227 | + 'var eejsdata=' . wp_json_encode(['data' => $this->jsdata]), |
|
228 | + 'before' |
|
229 | + ); |
|
230 | + foreach ($this->assets as $asset_collection) { |
|
231 | + $scripts = $asset_collection->getJavascriptAssetsWithData(); |
|
232 | + foreach ($scripts as $script) { |
|
233 | + $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
234 | + if ($script->hasInlineDataCallback()) { |
|
235 | + $localize = $script->inlineDataCallback(); |
|
236 | + $localize(); |
|
237 | + } |
|
238 | + } |
|
239 | + } |
|
240 | + } catch (Exception $exception) { |
|
241 | + EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
242 | + new ExceptionStackTraceDisplay($exception); |
|
243 | + } |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Used to add data to eejs.data object. |
|
249 | + * Note: Overriding existing data is not allowed. |
|
250 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
251 | + * If the data you add is something like this: |
|
252 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
253 | + * It will be exposed in the page source as: |
|
254 | + * eejs.data.my_plugin_data.foo == gar |
|
255 | + * |
|
256 | + * @param string $key Key used to access your data |
|
257 | + * @param string|array $value Value to attach to key |
|
258 | + * @throws InvalidArgumentException |
|
259 | + */ |
|
260 | + public function addData($key, $value) |
|
261 | + { |
|
262 | + if ($this->verifyDataNotExisting($key)) { |
|
263 | + $this->jsdata[ $key ] = $value; |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
270 | + * elements in an array. |
|
271 | + * |
|
272 | + * When you use this method, the value you include will be merged with the array on $key. |
|
273 | + * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript |
|
274 | + * object like this, eejs.data.test = [ my_data, |
|
275 | + * ] |
|
276 | + * If there has already been a scalar value attached to the data object given key (via addData for instance), then |
|
277 | + * this will throw an exception. |
|
278 | + * |
|
279 | + * Caution: Only add data using this method if you are okay with the potential for additional data added on the same |
|
280 | + * key potentially overriding the existing data on merge (specifically with associative arrays). |
|
281 | + * |
|
282 | + * @param string $key Key to attach data to. |
|
283 | + * @param string|array $value Value being registered. |
|
284 | + * @throws InvalidArgumentException |
|
285 | + */ |
|
286 | + public function pushData($key, $value) |
|
287 | + { |
|
288 | + if (isset($this->jsdata[ $key ]) |
|
289 | + && ! is_array($this->jsdata[ $key ]) |
|
290 | + ) { |
|
291 | + if (! $this->debug()) { |
|
292 | + return; |
|
293 | + } |
|
294 | + throw new InvalidArgumentException( |
|
295 | + sprintf( |
|
296 | + __( |
|
297 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
298 | 298 | push values to this data element when it is an array.', |
299 | - 'event_espresso' |
|
300 | - ), |
|
301 | - $key, |
|
302 | - __METHOD__ |
|
303 | - ) |
|
304 | - ); |
|
305 | - } |
|
306 | - if ( ! isset( $this->jsdata[ $key ] ) ) { |
|
307 | - $this->jsdata[ $key ] = is_array($value) ? $value : [$value]; |
|
308 | - } else { |
|
309 | - $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value); |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Used to set content used by javascript for a template. |
|
316 | - * Note: Overrides of existing registered templates are not allowed. |
|
317 | - * |
|
318 | - * @param string $template_reference |
|
319 | - * @param string $template_content |
|
320 | - * @throws InvalidArgumentException |
|
321 | - */ |
|
322 | - public function addTemplate($template_reference, $template_content) |
|
323 | - { |
|
324 | - if (! isset($this->jsdata['templates'])) { |
|
325 | - $this->jsdata['templates'] = array(); |
|
326 | - } |
|
327 | - //no overrides allowed. |
|
328 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
329 | - if (! $this->debug()) { |
|
330 | - return; |
|
331 | - } |
|
332 | - throw new InvalidArgumentException( |
|
333 | - sprintf( |
|
334 | - __( |
|
335 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
336 | - 'event_espresso' |
|
337 | - ), |
|
338 | - $template_reference |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * Retrieve the template content already registered for the given reference. |
|
348 | - * |
|
349 | - * @param string $template_reference |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - public function getTemplate($template_reference) |
|
353 | - { |
|
354 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
355 | - ? $this->jsdata['templates'][ $template_reference ] |
|
356 | - : ''; |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Retrieve registered data. |
|
362 | - * |
|
363 | - * @param string $key Name of key to attach data to. |
|
364 | - * @return mixed If there is no for the given key, then false is returned. |
|
365 | - */ |
|
366 | - public function getData($key) |
|
367 | - { |
|
368 | - return isset($this->jsdata[ $key ]) |
|
369 | - ? $this->jsdata[ $key ] |
|
370 | - : false; |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * Verifies whether the given data exists already on the jsdata array. |
|
376 | - * Overriding data is not allowed. |
|
377 | - * |
|
378 | - * @param string $key Index for data. |
|
379 | - * @return bool If valid then return true. |
|
380 | - * @throws InvalidArgumentException if data already exists. |
|
381 | - */ |
|
382 | - protected function verifyDataNotExisting($key) |
|
383 | - { |
|
384 | - if (isset($this->jsdata[ $key ])) { |
|
385 | - if (! $this->debug()) { |
|
386 | - return false; |
|
387 | - } |
|
388 | - if (is_array($this->jsdata[ $key ])) { |
|
389 | - throw new InvalidArgumentException( |
|
390 | - sprintf( |
|
391 | - __( |
|
392 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
299 | + 'event_espresso' |
|
300 | + ), |
|
301 | + $key, |
|
302 | + __METHOD__ |
|
303 | + ) |
|
304 | + ); |
|
305 | + } |
|
306 | + if ( ! isset( $this->jsdata[ $key ] ) ) { |
|
307 | + $this->jsdata[ $key ] = is_array($value) ? $value : [$value]; |
|
308 | + } else { |
|
309 | + $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value); |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Used to set content used by javascript for a template. |
|
316 | + * Note: Overrides of existing registered templates are not allowed. |
|
317 | + * |
|
318 | + * @param string $template_reference |
|
319 | + * @param string $template_content |
|
320 | + * @throws InvalidArgumentException |
|
321 | + */ |
|
322 | + public function addTemplate($template_reference, $template_content) |
|
323 | + { |
|
324 | + if (! isset($this->jsdata['templates'])) { |
|
325 | + $this->jsdata['templates'] = array(); |
|
326 | + } |
|
327 | + //no overrides allowed. |
|
328 | + if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
329 | + if (! $this->debug()) { |
|
330 | + return; |
|
331 | + } |
|
332 | + throw new InvalidArgumentException( |
|
333 | + sprintf( |
|
334 | + __( |
|
335 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
336 | + 'event_espresso' |
|
337 | + ), |
|
338 | + $template_reference |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * Retrieve the template content already registered for the given reference. |
|
348 | + * |
|
349 | + * @param string $template_reference |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + public function getTemplate($template_reference) |
|
353 | + { |
|
354 | + return isset($this->jsdata['templates'][ $template_reference ]) |
|
355 | + ? $this->jsdata['templates'][ $template_reference ] |
|
356 | + : ''; |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Retrieve registered data. |
|
362 | + * |
|
363 | + * @param string $key Name of key to attach data to. |
|
364 | + * @return mixed If there is no for the given key, then false is returned. |
|
365 | + */ |
|
366 | + public function getData($key) |
|
367 | + { |
|
368 | + return isset($this->jsdata[ $key ]) |
|
369 | + ? $this->jsdata[ $key ] |
|
370 | + : false; |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * Verifies whether the given data exists already on the jsdata array. |
|
376 | + * Overriding data is not allowed. |
|
377 | + * |
|
378 | + * @param string $key Index for data. |
|
379 | + * @return bool If valid then return true. |
|
380 | + * @throws InvalidArgumentException if data already exists. |
|
381 | + */ |
|
382 | + protected function verifyDataNotExisting($key) |
|
383 | + { |
|
384 | + if (isset($this->jsdata[ $key ])) { |
|
385 | + if (! $this->debug()) { |
|
386 | + return false; |
|
387 | + } |
|
388 | + if (is_array($this->jsdata[ $key ])) { |
|
389 | + throw new InvalidArgumentException( |
|
390 | + sprintf( |
|
391 | + __( |
|
392 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
393 | 393 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
394 | 394 | %2$s method to push your value to the array.', |
395 | - 'event_espresso' |
|
396 | - ), |
|
397 | - $key, |
|
398 | - 'pushData()' |
|
399 | - ) |
|
400 | - ); |
|
401 | - } |
|
402 | - throw new InvalidArgumentException( |
|
403 | - sprintf( |
|
404 | - __( |
|
405 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
395 | + 'event_espresso' |
|
396 | + ), |
|
397 | + $key, |
|
398 | + 'pushData()' |
|
399 | + ) |
|
400 | + ); |
|
401 | + } |
|
402 | + throw new InvalidArgumentException( |
|
403 | + sprintf( |
|
404 | + __( |
|
405 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
406 | 406 | allowed. Consider attaching your value to a different key', |
407 | - 'event_espresso' |
|
408 | - ), |
|
409 | - $key |
|
410 | - ) |
|
411 | - ); |
|
412 | - } |
|
413 | - return true; |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Get the actual asset path for asset manifests. |
|
419 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
420 | - * |
|
421 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
422 | - * asset file location. |
|
423 | - * @param string $chunk_name |
|
424 | - * @param string $asset_type |
|
425 | - * @return string |
|
426 | - * @since 4.9.59.p |
|
427 | - */ |
|
428 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
429 | - { |
|
430 | - return apply_filters( |
|
431 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
432 | - $this->asset_manifest->getAssetUrl($chunk_name, $asset_type), |
|
433 | - $namespace, |
|
434 | - $chunk_name, |
|
435 | - $asset_type |
|
436 | - ); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * Return the url to a js file for the given namespace and chunk name. |
|
443 | - * |
|
444 | - * @param string $namespace |
|
445 | - * @param string $chunk_name |
|
446 | - * @return string |
|
447 | - */ |
|
448 | - public function getJsUrl($namespace, $chunk_name) |
|
449 | - { |
|
450 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * Return the url to a css file for the given namespace and chunk name. |
|
456 | - * |
|
457 | - * @param string $namespace |
|
458 | - * @param string $chunk_name |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public function getCssUrl($namespace, $chunk_name) |
|
462 | - { |
|
463 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * This is used to set registered script handles that have data. |
|
469 | - * |
|
470 | - * @param string $script_handle |
|
471 | - */ |
|
472 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
473 | - { |
|
474 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /**i |
|
407 | + 'event_espresso' |
|
408 | + ), |
|
409 | + $key |
|
410 | + ) |
|
411 | + ); |
|
412 | + } |
|
413 | + return true; |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Get the actual asset path for asset manifests. |
|
419 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
420 | + * |
|
421 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
422 | + * asset file location. |
|
423 | + * @param string $chunk_name |
|
424 | + * @param string $asset_type |
|
425 | + * @return string |
|
426 | + * @since 4.9.59.p |
|
427 | + */ |
|
428 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
429 | + { |
|
430 | + return apply_filters( |
|
431 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
432 | + $this->asset_manifest->getAssetUrl($chunk_name, $asset_type), |
|
433 | + $namespace, |
|
434 | + $chunk_name, |
|
435 | + $asset_type |
|
436 | + ); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * Return the url to a js file for the given namespace and chunk name. |
|
443 | + * |
|
444 | + * @param string $namespace |
|
445 | + * @param string $chunk_name |
|
446 | + * @return string |
|
447 | + */ |
|
448 | + public function getJsUrl($namespace, $chunk_name) |
|
449 | + { |
|
450 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * Return the url to a css file for the given namespace and chunk name. |
|
456 | + * |
|
457 | + * @param string $namespace |
|
458 | + * @param string $chunk_name |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public function getCssUrl($namespace, $chunk_name) |
|
462 | + { |
|
463 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * This is used to set registered script handles that have data. |
|
469 | + * |
|
470 | + * @param string $script_handle |
|
471 | + */ |
|
472 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
473 | + { |
|
474 | + $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /**i |
|
479 | 479 | * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
480 | 480 | * Dependency stored in WP_Scripts if its set. |
481 | 481 | */ |
482 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
483 | - { |
|
484 | - if (empty($this->script_handles_with_data)) { |
|
485 | - return; |
|
486 | - } |
|
487 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
488 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
489 | - } |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
495 | - * |
|
496 | - * @param string $script_handle |
|
497 | - */ |
|
498 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
499 | - { |
|
500 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
501 | - global $wp_scripts; |
|
502 | - $unset_handle = false; |
|
503 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
504 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
505 | - $unset_handle = true; |
|
506 | - } |
|
507 | - //deal with inline_scripts |
|
508 | - if ($wp_scripts->get_data($script_handle, 'before')) { |
|
509 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
510 | - $unset_handle = true; |
|
511 | - } |
|
512 | - if ($wp_scripts->get_data($script_handle, 'after')) { |
|
513 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
514 | - } |
|
515 | - if ($unset_handle) { |
|
516 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * register translations for a registered script |
|
524 | - * |
|
525 | - * @param string $handle |
|
526 | - */ |
|
527 | - public function registerTranslation($handle) |
|
528 | - { |
|
529 | - $this->i18n_registry->registerScriptI18n($handle); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * @since 4.9.63.p |
|
535 | - * @return bool |
|
536 | - */ |
|
537 | - private function debug() |
|
538 | - { |
|
539 | - return apply_filters( |
|
540 | - 'FHEE__EventEspresso_core_services_assets_Registry__debug', |
|
541 | - defined('EE_DEBUG') && EE_DEBUG |
|
542 | - ); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /**************** deprecated ****************/ |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * @param string $namespace |
|
551 | - * @param string $chunk_name |
|
552 | - * @return array |
|
553 | - * @deprecated $VID:$ |
|
554 | - */ |
|
555 | - public function getCssAssetDetails($namespace, $chunk_name) |
|
556 | - { |
|
557 | - return [ |
|
558 | - AssetManifest::KEY_DEPENDENCIES => $this->asset_manifest->getAssetDependencies($chunk_name, Asset::TYPE_CSS), |
|
559 | - AssetManifest::KEY_VERSION => $this->asset_manifest->getAssetVersion($chunk_name, Asset::TYPE_CSS), |
|
560 | - ]; |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * @param string $namespace |
|
566 | - * @param string $chunk_name |
|
567 | - * @return array |
|
568 | - * @deprecated $VID:$ |
|
569 | - */ |
|
570 | - public function getCssDependencies($namespace, $chunk_name) |
|
571 | - { |
|
572 | - return $this->asset_manifest->getAssetDependencies($chunk_name, AssetManifest::ASSET_EXT_CSS); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * @param string $namespace |
|
578 | - * @param string $chunk_name |
|
579 | - * @return array |
|
580 | - * @deprecated $VID:$ |
|
581 | - */ |
|
582 | - public function getJsAssetDetails($namespace, $chunk_name) |
|
583 | - { |
|
584 | - return [ |
|
585 | - AssetManifest::KEY_DEPENDENCIES => $this->asset_manifest->getAssetDependencies($chunk_name, Asset::TYPE_JS), |
|
586 | - AssetManifest::KEY_VERSION => $this->asset_manifest->getAssetVersion($chunk_name, Asset::TYPE_JS), |
|
587 | - ]; |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - /** |
|
592 | - * @param string $namespace |
|
593 | - * @param string $chunk_name |
|
594 | - * @return array |
|
595 | - * @deprecated $VID:$ |
|
596 | - */ |
|
597 | - public function getJsDependencies($namespace, $chunk_name) |
|
598 | - { |
|
599 | - return $this->asset_manifest->getAssetDependencies($chunk_name); |
|
600 | - } |
|
601 | - |
|
602 | - |
|
603 | - /** |
|
604 | - * @deprecated $VID:$ |
|
605 | - */ |
|
606 | - public function registerManifestFiles() |
|
607 | - { |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * @param string $namespace |
|
613 | - * @param string $url_base |
|
614 | - * @param string $manifest_file |
|
615 | - * @param string $manifest_file_path |
|
616 | - * @deprecated $VID:$ |
|
617 | - */ |
|
618 | - public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '') |
|
619 | - { |
|
620 | - } |
|
482 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
483 | + { |
|
484 | + if (empty($this->script_handles_with_data)) { |
|
485 | + return; |
|
486 | + } |
|
487 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
488 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
489 | + } |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
495 | + * |
|
496 | + * @param string $script_handle |
|
497 | + */ |
|
498 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
499 | + { |
|
500 | + if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
501 | + global $wp_scripts; |
|
502 | + $unset_handle = false; |
|
503 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
504 | + unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
505 | + $unset_handle = true; |
|
506 | + } |
|
507 | + //deal with inline_scripts |
|
508 | + if ($wp_scripts->get_data($script_handle, 'before')) { |
|
509 | + unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
510 | + $unset_handle = true; |
|
511 | + } |
|
512 | + if ($wp_scripts->get_data($script_handle, 'after')) { |
|
513 | + unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
514 | + } |
|
515 | + if ($unset_handle) { |
|
516 | + unset($this->script_handles_with_data[ $script_handle ]); |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * register translations for a registered script |
|
524 | + * |
|
525 | + * @param string $handle |
|
526 | + */ |
|
527 | + public function registerTranslation($handle) |
|
528 | + { |
|
529 | + $this->i18n_registry->registerScriptI18n($handle); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * @since 4.9.63.p |
|
535 | + * @return bool |
|
536 | + */ |
|
537 | + private function debug() |
|
538 | + { |
|
539 | + return apply_filters( |
|
540 | + 'FHEE__EventEspresso_core_services_assets_Registry__debug', |
|
541 | + defined('EE_DEBUG') && EE_DEBUG |
|
542 | + ); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /**************** deprecated ****************/ |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * @param string $namespace |
|
551 | + * @param string $chunk_name |
|
552 | + * @return array |
|
553 | + * @deprecated $VID:$ |
|
554 | + */ |
|
555 | + public function getCssAssetDetails($namespace, $chunk_name) |
|
556 | + { |
|
557 | + return [ |
|
558 | + AssetManifest::KEY_DEPENDENCIES => $this->asset_manifest->getAssetDependencies($chunk_name, Asset::TYPE_CSS), |
|
559 | + AssetManifest::KEY_VERSION => $this->asset_manifest->getAssetVersion($chunk_name, Asset::TYPE_CSS), |
|
560 | + ]; |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * @param string $namespace |
|
566 | + * @param string $chunk_name |
|
567 | + * @return array |
|
568 | + * @deprecated $VID:$ |
|
569 | + */ |
|
570 | + public function getCssDependencies($namespace, $chunk_name) |
|
571 | + { |
|
572 | + return $this->asset_manifest->getAssetDependencies($chunk_name, AssetManifest::ASSET_EXT_CSS); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * @param string $namespace |
|
578 | + * @param string $chunk_name |
|
579 | + * @return array |
|
580 | + * @deprecated $VID:$ |
|
581 | + */ |
|
582 | + public function getJsAssetDetails($namespace, $chunk_name) |
|
583 | + { |
|
584 | + return [ |
|
585 | + AssetManifest::KEY_DEPENDENCIES => $this->asset_manifest->getAssetDependencies($chunk_name, Asset::TYPE_JS), |
|
586 | + AssetManifest::KEY_VERSION => $this->asset_manifest->getAssetVersion($chunk_name, Asset::TYPE_JS), |
|
587 | + ]; |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + /** |
|
592 | + * @param string $namespace |
|
593 | + * @param string $chunk_name |
|
594 | + * @return array |
|
595 | + * @deprecated $VID:$ |
|
596 | + */ |
|
597 | + public function getJsDependencies($namespace, $chunk_name) |
|
598 | + { |
|
599 | + return $this->asset_manifest->getAssetDependencies($chunk_name); |
|
600 | + } |
|
601 | + |
|
602 | + |
|
603 | + /** |
|
604 | + * @deprecated $VID:$ |
|
605 | + */ |
|
606 | + public function registerManifestFiles() |
|
607 | + { |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * @param string $namespace |
|
613 | + * @param string $url_base |
|
614 | + * @param string $manifest_file |
|
615 | + * @param string $manifest_file_path |
|
616 | + * @deprecated $VID:$ |
|
617 | + */ |
|
618 | + public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '') |
|
619 | + { |
|
620 | + } |
|
621 | 621 | } |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | public function addAssetCollection(AssetCollection $asset_collection) |
90 | 90 | { |
91 | 91 | $id = $asset_collection->collectionIdentifier(); |
92 | - if (! array_key_exists($id, $this->assets)) { |
|
93 | - $this->assets[ $id ] = $asset_collection; |
|
92 | + if ( ! array_key_exists($id, $this->assets)) { |
|
93 | + $this->assets[$id] = $asset_collection; |
|
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $script->version(), |
156 | 156 | $script->loadInFooter() |
157 | 157 | ); |
158 | - if (! $registered && $this->debug()) { |
|
158 | + if ( ! $registered && $this->debug()) { |
|
159 | 159 | throw new AssetRegistrationException($script->handle()); |
160 | 160 | } |
161 | 161 | $script->setRegistered($registered); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | $this->removeAlreadyRegisteredDataForScriptHandles(); |
225 | 225 | wp_add_inline_script( |
226 | 226 | 'eejs-core', |
227 | - 'var eejsdata=' . wp_json_encode(['data' => $this->jsdata]), |
|
227 | + 'var eejsdata='.wp_json_encode(['data' => $this->jsdata]), |
|
228 | 228 | 'before' |
229 | 229 | ); |
230 | 230 | foreach ($this->assets as $asset_collection) { |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | public function addData($key, $value) |
261 | 261 | { |
262 | 262 | if ($this->verifyDataNotExisting($key)) { |
263 | - $this->jsdata[ $key ] = $value; |
|
263 | + $this->jsdata[$key] = $value; |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
@@ -285,10 +285,10 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public function pushData($key, $value) |
287 | 287 | { |
288 | - if (isset($this->jsdata[ $key ]) |
|
289 | - && ! is_array($this->jsdata[ $key ]) |
|
288 | + if (isset($this->jsdata[$key]) |
|
289 | + && ! is_array($this->jsdata[$key]) |
|
290 | 290 | ) { |
291 | - if (! $this->debug()) { |
|
291 | + if ( ! $this->debug()) { |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | throw new InvalidArgumentException( |
@@ -303,10 +303,10 @@ discard block |
||
303 | 303 | ) |
304 | 304 | ); |
305 | 305 | } |
306 | - if ( ! isset( $this->jsdata[ $key ] ) ) { |
|
307 | - $this->jsdata[ $key ] = is_array($value) ? $value : [$value]; |
|
306 | + if ( ! isset($this->jsdata[$key])) { |
|
307 | + $this->jsdata[$key] = is_array($value) ? $value : [$value]; |
|
308 | 308 | } else { |
309 | - $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value); |
|
309 | + $this->jsdata[$key] = array_merge($this->jsdata[$key], (array) $value); |
|
310 | 310 | } |
311 | 311 | } |
312 | 312 | |
@@ -321,12 +321,12 @@ discard block |
||
321 | 321 | */ |
322 | 322 | public function addTemplate($template_reference, $template_content) |
323 | 323 | { |
324 | - if (! isset($this->jsdata['templates'])) { |
|
324 | + if ( ! isset($this->jsdata['templates'])) { |
|
325 | 325 | $this->jsdata['templates'] = array(); |
326 | 326 | } |
327 | 327 | //no overrides allowed. |
328 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
329 | - if (! $this->debug()) { |
|
328 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
329 | + if ( ! $this->debug()) { |
|
330 | 330 | return; |
331 | 331 | } |
332 | 332 | throw new InvalidArgumentException( |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | ) |
340 | 340 | ); |
341 | 341 | } |
342 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
342 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | */ |
352 | 352 | public function getTemplate($template_reference) |
353 | 353 | { |
354 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
355 | - ? $this->jsdata['templates'][ $template_reference ] |
|
354 | + return isset($this->jsdata['templates'][$template_reference]) |
|
355 | + ? $this->jsdata['templates'][$template_reference] |
|
356 | 356 | : ''; |
357 | 357 | } |
358 | 358 | |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | */ |
366 | 366 | public function getData($key) |
367 | 367 | { |
368 | - return isset($this->jsdata[ $key ]) |
|
369 | - ? $this->jsdata[ $key ] |
|
368 | + return isset($this->jsdata[$key]) |
|
369 | + ? $this->jsdata[$key] |
|
370 | 370 | : false; |
371 | 371 | } |
372 | 372 | |
@@ -381,11 +381,11 @@ discard block |
||
381 | 381 | */ |
382 | 382 | protected function verifyDataNotExisting($key) |
383 | 383 | { |
384 | - if (isset($this->jsdata[ $key ])) { |
|
385 | - if (! $this->debug()) { |
|
384 | + if (isset($this->jsdata[$key])) { |
|
385 | + if ( ! $this->debug()) { |
|
386 | 386 | return false; |
387 | 387 | } |
388 | - if (is_array($this->jsdata[ $key ])) { |
|
388 | + if (is_array($this->jsdata[$key])) { |
|
389 | 389 | throw new InvalidArgumentException( |
390 | 390 | sprintf( |
391 | 391 | __( |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | */ |
472 | 472 | private function addRegisteredScriptHandlesWithData($script_handle) |
473 | 473 | { |
474 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
474 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | |
@@ -497,23 +497,23 @@ discard block |
||
497 | 497 | */ |
498 | 498 | private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
499 | 499 | { |
500 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
500 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
501 | 501 | global $wp_scripts; |
502 | 502 | $unset_handle = false; |
503 | 503 | if ($wp_scripts->get_data($script_handle, 'data')) { |
504 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
504 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
505 | 505 | $unset_handle = true; |
506 | 506 | } |
507 | 507 | //deal with inline_scripts |
508 | 508 | if ($wp_scripts->get_data($script_handle, 'before')) { |
509 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
509 | + unset($wp_scripts->registered[$script_handle]->extra['before']); |
|
510 | 510 | $unset_handle = true; |
511 | 511 | } |
512 | 512 | if ($wp_scripts->get_data($script_handle, 'after')) { |
513 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
513 | + unset($wp_scripts->registered[$script_handle]->extra['after']); |
|
514 | 514 | } |
515 | 515 | if ($unset_handle) { |
516 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
516 | + unset($this->script_handles_with_data[$script_handle]); |
|
517 | 517 | } |
518 | 518 | } |
519 | 519 | } |
@@ -11,102 +11,102 @@ |
||
11 | 11 | |
12 | 12 | class BaristaFactory implements FactoryInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * @var AssetManifestFactory |
|
16 | - */ |
|
17 | - private $manifest_factory; |
|
14 | + /** |
|
15 | + * @var AssetManifestFactory |
|
16 | + */ |
|
17 | + private $manifest_factory; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var BaristaInterface[] |
|
21 | - */ |
|
22 | - private static $baristas = []; |
|
19 | + /** |
|
20 | + * @var BaristaInterface[] |
|
21 | + */ |
|
22 | + private static $baristas = []; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var LoaderInterface $loader |
|
26 | - */ |
|
27 | - protected $loader; |
|
24 | + /** |
|
25 | + * @var LoaderInterface $loader |
|
26 | + */ |
|
27 | + protected $loader; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * BaristaFactory constructor. |
|
32 | - * |
|
33 | - * @param AssetManifestFactory $manifest_factory |
|
34 | - * @param LoaderInterface $loader |
|
35 | - */ |
|
36 | - public function __construct(AssetManifestFactory $manifest_factory, LoaderInterface $loader) |
|
37 | - { |
|
38 | - $this->manifest_factory = $manifest_factory; |
|
39 | - $this->loader = $loader; |
|
40 | - } |
|
30 | + /** |
|
31 | + * BaristaFactory constructor. |
|
32 | + * |
|
33 | + * @param AssetManifestFactory $manifest_factory |
|
34 | + * @param LoaderInterface $loader |
|
35 | + */ |
|
36 | + public function __construct(AssetManifestFactory $manifest_factory, LoaderInterface $loader) |
|
37 | + { |
|
38 | + $this->manifest_factory = $manifest_factory; |
|
39 | + $this->loader = $loader; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @param DomainInterface $domain |
|
45 | - * @return BaristaInterface |
|
46 | - */ |
|
47 | - public function createFromDomainObject(DomainInterface $domain) |
|
48 | - { |
|
49 | - $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
50 | - return $this->getBaristaForDomain($asset_manifest, $domain); |
|
51 | - } |
|
43 | + /** |
|
44 | + * @param DomainInterface $domain |
|
45 | + * @return BaristaInterface |
|
46 | + */ |
|
47 | + public function createFromDomainObject(DomainInterface $domain) |
|
48 | + { |
|
49 | + $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
50 | + return $this->getBaristaForDomain($asset_manifest, $domain); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
56 | - * @param array $domain_arguments arguments required by the applicable DomainInterface class |
|
57 | - * @return BaristaInterface |
|
58 | - */ |
|
59 | - public function create($domain_fqcn = '', array $domain_arguments = []) |
|
60 | - { |
|
61 | - $domain = $this->getDomain($domain_fqcn, $domain_arguments); |
|
62 | - $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
63 | - return $this->getBaristaForDomain($asset_manifest, $domain); |
|
64 | - } |
|
54 | + /** |
|
55 | + * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
56 | + * @param array $domain_arguments arguments required by the applicable DomainInterface class |
|
57 | + * @return BaristaInterface |
|
58 | + */ |
|
59 | + public function create($domain_fqcn = '', array $domain_arguments = []) |
|
60 | + { |
|
61 | + $domain = $this->getDomain($domain_fqcn, $domain_arguments); |
|
62 | + $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
63 | + return $this->getBaristaForDomain($asset_manifest, $domain); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * @param AssetManifestInterface $asset_manifest |
|
69 | - * @param DomainInterface $domain |
|
70 | - * @return BaristaInterface |
|
71 | - */ |
|
72 | - private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
|
73 | - { |
|
74 | - $domain_fqcn = get_class($domain); |
|
75 | - if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
76 | - $barista = new Barista($asset_manifest); |
|
77 | - // we still need to share this with the core loader to facilitate automatic dependency injection |
|
78 | - $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
|
79 | - BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
80 | - } |
|
81 | - return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
82 | - } |
|
67 | + /** |
|
68 | + * @param AssetManifestInterface $asset_manifest |
|
69 | + * @param DomainInterface $domain |
|
70 | + * @return BaristaInterface |
|
71 | + */ |
|
72 | + private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
|
73 | + { |
|
74 | + $domain_fqcn = get_class($domain); |
|
75 | + if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
76 | + $barista = new Barista($asset_manifest); |
|
77 | + // we still need to share this with the core loader to facilitate automatic dependency injection |
|
78 | + $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
|
79 | + BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
80 | + } |
|
81 | + return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
82 | + } |
|
83 | 83 | |
84 | 84 | |
85 | - /** |
|
86 | - * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
87 | - * @param array $arguments |
|
88 | - * @return DomainInterface |
|
89 | - */ |
|
90 | - private function getDomain($domain_fqcn, array $arguments = []) |
|
91 | - { |
|
92 | - // if no FQCN is supplied for the domain, then we are loading the defaults for core |
|
93 | - // add-ons will always have to supply their domain FQCN and arguments to retrieve their manifest |
|
94 | - $domain = empty($domain_fqcn) |
|
95 | - ? DomainFactory::getEventEspressoCoreDomain() |
|
96 | - : DomainFactory::getShared(new FullyQualifiedName($domain_fqcn), $arguments); |
|
97 | - if ($domain instanceof DomainInterface) { |
|
98 | - return $domain; |
|
99 | - } |
|
100 | - throw new DomainException( |
|
101 | - sprintf( |
|
102 | - esc_html__( |
|
103 | - 'BaristaFactory::create() requires a fully qualified class name (FQCN) for the currently applicable Domain object. |
|
85 | + /** |
|
86 | + * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
87 | + * @param array $arguments |
|
88 | + * @return DomainInterface |
|
89 | + */ |
|
90 | + private function getDomain($domain_fqcn, array $arguments = []) |
|
91 | + { |
|
92 | + // if no FQCN is supplied for the domain, then we are loading the defaults for core |
|
93 | + // add-ons will always have to supply their domain FQCN and arguments to retrieve their manifest |
|
94 | + $domain = empty($domain_fqcn) |
|
95 | + ? DomainFactory::getEventEspressoCoreDomain() |
|
96 | + : DomainFactory::getShared(new FullyQualifiedName($domain_fqcn), $arguments); |
|
97 | + if ($domain instanceof DomainInterface) { |
|
98 | + return $domain; |
|
99 | + } |
|
100 | + throw new DomainException( |
|
101 | + sprintf( |
|
102 | + esc_html__( |
|
103 | + 'BaristaFactory::create() requires a fully qualified class name (FQCN) for the currently applicable Domain object. |
|
104 | 104 | %1$sThe supplied FQCN ("%2$s") is either invalid or the class is missing.', |
105 | - 'event_espresso' |
|
106 | - ), |
|
107 | - '<br />', |
|
108 | - $domain_fqcn |
|
109 | - ) |
|
110 | - ); |
|
111 | - } |
|
105 | + 'event_espresso' |
|
106 | + ), |
|
107 | + '<br />', |
|
108 | + $domain_fqcn |
|
109 | + ) |
|
110 | + ); |
|
111 | + } |
|
112 | 112 | } |
@@ -72,13 +72,13 @@ |
||
72 | 72 | private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
73 | 73 | { |
74 | 74 | $domain_fqcn = get_class($domain); |
75 | - if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
75 | + if ( ! isset(BaristaFactory::$baristas[$domain_fqcn])) { |
|
76 | 76 | $barista = new Barista($asset_manifest); |
77 | 77 | // we still need to share this with the core loader to facilitate automatic dependency injection |
78 | 78 | $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
79 | - BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
79 | + BaristaFactory::$baristas[$domain_fqcn] = $barista; |
|
80 | 80 | } |
81 | - return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
81 | + return BaristaFactory::$baristas[$domain_fqcn]; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 |
@@ -21,1001 +21,1001 @@ |
||
21 | 21 | class EE_Dependency_Map |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * This means that the requested class dependency is not present in the dependency map |
|
26 | - */ |
|
27 | - const not_registered = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | - */ |
|
32 | - const load_new_object = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | - */ |
|
38 | - const load_from_cache = 2; |
|
39 | - |
|
40 | - /** |
|
41 | - * When registering a dependency, |
|
42 | - * this indicates to keep any existing dependencies that already exist, |
|
43 | - * and simply discard any new dependencies declared in the incoming data |
|
44 | - */ |
|
45 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | - |
|
47 | - /** |
|
48 | - * When registering a dependency, |
|
49 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | - */ |
|
51 | - const OVERWRITE_DEPENDENCIES = 1; |
|
52 | - |
|
53 | - /** |
|
54 | - * @type EE_Dependency_Map $_instance |
|
55 | - */ |
|
56 | - protected static $_instance; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var ClassInterfaceCache $class_cache |
|
60 | - */ |
|
61 | - private $class_cache; |
|
62 | - |
|
63 | - /** |
|
64 | - * @type RequestInterface $request |
|
65 | - */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** |
|
69 | - * @type LegacyRequestInterface $legacy_request |
|
70 | - */ |
|
71 | - protected $legacy_request; |
|
72 | - |
|
73 | - /** |
|
74 | - * @type ResponseInterface $response |
|
75 | - */ |
|
76 | - protected $response; |
|
77 | - |
|
78 | - /** |
|
79 | - * @type LoaderInterface $loader |
|
80 | - */ |
|
81 | - protected $loader; |
|
82 | - |
|
83 | - /** |
|
84 | - * @type array $_dependency_map |
|
85 | - */ |
|
86 | - protected $_dependency_map = []; |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = []; |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * EE_Dependency_Map constructor. |
|
96 | - * |
|
97 | - * @param ClassInterfaceCache $class_cache |
|
98 | - */ |
|
99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | - { |
|
101 | - $this->class_cache = $class_cache; |
|
102 | - do_action('EE_Dependency_Map____construct', $this); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return void |
|
108 | - * @throws InvalidAliasException |
|
109 | - */ |
|
110 | - public function initialize() |
|
111 | - { |
|
112 | - $this->_register_core_dependencies(); |
|
113 | - $this->_register_core_class_loaders(); |
|
114 | - $this->_register_core_aliases(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @singleton method used to instantiate class object |
|
120 | - * @param ClassInterfaceCache|null $class_cache |
|
121 | - * @return EE_Dependency_Map |
|
122 | - */ |
|
123 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
124 | - { |
|
125 | - // check if class object is instantiated, and instantiated properly |
|
126 | - if (! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
127 | - && $class_cache instanceof ClassInterfaceCache |
|
128 | - ) { |
|
129 | - EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
130 | - } |
|
131 | - return EE_Dependency_Map::$_instance; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param RequestInterface $request |
|
137 | - */ |
|
138 | - public function setRequest(RequestInterface $request) |
|
139 | - { |
|
140 | - $this->request = $request; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param LegacyRequestInterface $legacy_request |
|
146 | - */ |
|
147 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
148 | - { |
|
149 | - $this->legacy_request = $legacy_request; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param ResponseInterface $response |
|
155 | - */ |
|
156 | - public function setResponse(ResponseInterface $response) |
|
157 | - { |
|
158 | - $this->response = $response; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param LoaderInterface $loader |
|
164 | - */ |
|
165 | - public function setLoader(LoaderInterface $loader) |
|
166 | - { |
|
167 | - $this->loader = $loader; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param string $class |
|
173 | - * @param array $dependencies |
|
174 | - * @param int $overwrite |
|
175 | - * @return bool |
|
176 | - */ |
|
177 | - public static function register_dependencies( |
|
178 | - $class, |
|
179 | - array $dependencies, |
|
180 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
181 | - ) { |
|
182 | - return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
188 | - * to the class specified by the first parameter. |
|
189 | - * IMPORTANT !!! |
|
190 | - * The order of elements in the incoming $dependencies array MUST match |
|
191 | - * the order of the constructor parameters for the class in question. |
|
192 | - * This is especially important when overriding any existing dependencies that are registered. |
|
193 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
194 | - * |
|
195 | - * @param string $class |
|
196 | - * @param array $dependencies |
|
197 | - * @param int $overwrite |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function registerDependencies( |
|
201 | - $class, |
|
202 | - array $dependencies, |
|
203 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
204 | - ) { |
|
205 | - $class = trim($class, '\\'); |
|
206 | - $registered = false; |
|
207 | - if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
208 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
209 | - } |
|
210 | - // we need to make sure that any aliases used when registering a dependency |
|
211 | - // get resolved to the correct class name |
|
212 | - foreach ($dependencies as $dependency => $load_source) { |
|
213 | - $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
214 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
215 | - || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
216 | - ) { |
|
217 | - unset($dependencies[ $dependency ]); |
|
218 | - $dependencies[ $alias ] = $load_source; |
|
219 | - $registered = true; |
|
220 | - } |
|
221 | - } |
|
222 | - // now add our two lists of dependencies together. |
|
223 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
224 | - // so $dependencies is NOT overwritten because it is listed first |
|
225 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
226 | - // Union is way faster than array_merge() but should be used with caution... |
|
227 | - // especially with numerically indexed arrays |
|
228 | - $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
229 | - // now we need to ensure that the resulting dependencies |
|
230 | - // array only has the entries that are required for the class |
|
231 | - // so first count how many dependencies were originally registered for the class |
|
232 | - $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
233 | - // if that count is non-zero (meaning dependencies were already registered) |
|
234 | - EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
235 | - // then truncate the final array to match that count |
|
236 | - ? array_slice($dependencies, 0, $dependency_count) |
|
237 | - // otherwise just take the incoming array because nothing previously existed |
|
238 | - : $dependencies; |
|
239 | - return $registered; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string $class_name |
|
245 | - * @param string $loader |
|
246 | - * @return bool |
|
247 | - * @throws DomainException |
|
248 | - */ |
|
249 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
250 | - { |
|
251 | - return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $class_name |
|
257 | - * @param string $loader |
|
258 | - * @return bool |
|
259 | - * @throws DomainException |
|
260 | - */ |
|
261 | - public function registerClassLoader($class_name, $loader = 'load_core') |
|
262 | - { |
|
263 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
264 | - throw new DomainException( |
|
265 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
266 | - ); |
|
267 | - } |
|
268 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
269 | - if (! is_callable($loader) |
|
270 | - && ( |
|
271 | - strpos($loader, 'load_') !== 0 |
|
272 | - || ! method_exists('EE_Registry', $loader) |
|
273 | - ) |
|
274 | - ) { |
|
275 | - throw new DomainException( |
|
276 | - sprintf( |
|
277 | - esc_html__( |
|
278 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
279 | - 'event_espresso' |
|
280 | - ), |
|
281 | - $loader |
|
282 | - ) |
|
283 | - ); |
|
284 | - } |
|
285 | - $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
286 | - if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
287 | - EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
288 | - return true; |
|
289 | - } |
|
290 | - return false; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @return array |
|
296 | - */ |
|
297 | - public function dependency_map() |
|
298 | - { |
|
299 | - return $this->_dependency_map; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
305 | - * |
|
306 | - * @param string $class_name |
|
307 | - * @return boolean |
|
308 | - */ |
|
309 | - public function has($class_name = '') |
|
310 | - { |
|
311 | - // all legacy models have the same dependencies |
|
312 | - if (strpos($class_name, 'EEM_') === 0) { |
|
313 | - $class_name = 'LEGACY_MODELS'; |
|
314 | - } |
|
315 | - return isset($this->_dependency_map[ $class_name ]); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
321 | - * |
|
322 | - * @param string $class_name |
|
323 | - * @param string $dependency |
|
324 | - * @return bool |
|
325 | - */ |
|
326 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
327 | - { |
|
328 | - // all legacy models have the same dependencies |
|
329 | - if (strpos($class_name, 'EEM_') === 0) { |
|
330 | - $class_name = 'LEGACY_MODELS'; |
|
331 | - } |
|
332 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
333 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
339 | - * |
|
340 | - * @param string $class_name |
|
341 | - * @param string $dependency |
|
342 | - * @return int |
|
343 | - */ |
|
344 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
345 | - { |
|
346 | - // all legacy models have the same dependencies |
|
347 | - if (strpos($class_name, 'EEM_') === 0) { |
|
348 | - $class_name = 'LEGACY_MODELS'; |
|
349 | - } |
|
350 | - $dependency = $this->getFqnForAlias($dependency); |
|
351 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
352 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
353 | - : EE_Dependency_Map::not_registered; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param string $class_name |
|
359 | - * @return string | Closure |
|
360 | - */ |
|
361 | - public function class_loader($class_name) |
|
362 | - { |
|
363 | - // all legacy models use load_model() |
|
364 | - if (strpos($class_name, 'EEM_') === 0) { |
|
365 | - return 'load_model'; |
|
366 | - } |
|
367 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
368 | - // perform strpos() first to avoid loading regex every time we load a class |
|
369 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
370 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
371 | - ) { |
|
372 | - return 'load_core'; |
|
373 | - } |
|
374 | - $class_name = $this->getFqnForAlias($class_name); |
|
375 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return array |
|
381 | - */ |
|
382 | - public function class_loaders() |
|
383 | - { |
|
384 | - return $this->_class_loaders; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * adds an alias for a classname |
|
390 | - * |
|
391 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
392 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
393 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
394 | - * @throws InvalidAliasException |
|
395 | - */ |
|
396 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
397 | - { |
|
398 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
404 | - * WHY? |
|
405 | - * Because if a class is type hinting for a concretion, |
|
406 | - * then why would we need to find another class to supply it? |
|
407 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
408 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
409 | - * Don't go looking for some substitute. |
|
410 | - * Whereas if a class is type hinting for an interface... |
|
411 | - * then we need to find an actual class to use. |
|
412 | - * So the interface IS the alias for some other FQN, |
|
413 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
414 | - * represents some other class. |
|
415 | - * |
|
416 | - * @param string $fqn |
|
417 | - * @param string $for_class |
|
418 | - * @return bool |
|
419 | - */ |
|
420 | - public function isAlias($fqn = '', $for_class = '') |
|
421 | - { |
|
422 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
428 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
429 | - * for example: |
|
430 | - * if the following two entries were added to the _aliases array: |
|
431 | - * array( |
|
432 | - * 'interface_alias' => 'some\namespace\interface' |
|
433 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
434 | - * ) |
|
435 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
436 | - * to load an instance of 'some\namespace\classname' |
|
437 | - * |
|
438 | - * @param string $alias |
|
439 | - * @param string $for_class |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
443 | - { |
|
444 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
450 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
451 | - * This is done by using the following class constants: |
|
452 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
453 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
454 | - */ |
|
455 | - protected function _register_core_dependencies() |
|
456 | - { |
|
457 | - $this->_dependency_map = [ |
|
458 | - 'EE_Request_Handler' => [ |
|
459 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
460 | - ], |
|
461 | - 'EE_System' => [ |
|
462 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
463 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
464 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
465 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
466 | - 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
467 | - ], |
|
468 | - 'EE_Admin' => [ |
|
469 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
470 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
471 | - ], |
|
472 | - 'EE_Cart' => [ |
|
473 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
474 | - ], |
|
475 | - 'EE_Messenger_Collection_Loader' => [ |
|
476 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
477 | - ], |
|
478 | - 'EE_Message_Type_Collection_Loader' => [ |
|
479 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
480 | - ], |
|
481 | - 'EE_Message_Resource_Manager' => [ |
|
482 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
483 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
484 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
485 | - ], |
|
486 | - 'EE_Message_Factory' => [ |
|
487 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
488 | - ], |
|
489 | - 'EE_messages' => [ |
|
490 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
491 | - ], |
|
492 | - 'EE_Messages_Generator' => [ |
|
493 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
494 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
495 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
496 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
497 | - ], |
|
498 | - 'EE_Messages_Processor' => [ |
|
499 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
500 | - ], |
|
501 | - 'EE_Messages_Queue' => [ |
|
502 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
503 | - ], |
|
504 | - 'EE_Messages_Template_Defaults' => [ |
|
505 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
506 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
507 | - ], |
|
508 | - 'EE_Message_To_Generate_From_Request' => [ |
|
509 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
511 | - ], |
|
512 | - 'EventEspresso\core\services\commands\CommandBus' => [ |
|
513 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
514 | - ], |
|
515 | - 'EventEspresso\services\commands\CommandHandler' => [ |
|
516 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
517 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
518 | - ], |
|
519 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
520 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
521 | - ], |
|
522 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
523 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
524 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
525 | - ], |
|
526 | - 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
527 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
528 | - ], |
|
529 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
530 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
531 | - ], |
|
532 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
533 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
534 | - ], |
|
535 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
536 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
537 | - ], |
|
538 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
539 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
540 | - ], |
|
541 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
542 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
543 | - ], |
|
544 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
545 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
546 | - ], |
|
547 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
548 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
549 | - ], |
|
550 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
551 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
552 | - ], |
|
553 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
554 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
555 | - ], |
|
556 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
557 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
558 | - ], |
|
559 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
560 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
561 | - ], |
|
562 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
563 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
564 | - ], |
|
565 | - 'EventEspresso\core\services\database\TableManager' => [ |
|
566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | - ], |
|
568 | - 'EE_Data_Migration_Class_Base' => [ |
|
569 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
570 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
571 | - ], |
|
572 | - 'EE_DMS_Core_4_1_0' => [ |
|
573 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
574 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
575 | - ], |
|
576 | - 'EE_DMS_Core_4_2_0' => [ |
|
577 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
578 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
579 | - ], |
|
580 | - 'EE_DMS_Core_4_3_0' => [ |
|
581 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
582 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
583 | - ], |
|
584 | - 'EE_DMS_Core_4_4_0' => [ |
|
585 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
586 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
587 | - ], |
|
588 | - 'EE_DMS_Core_4_5_0' => [ |
|
589 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
590 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
591 | - ], |
|
592 | - 'EE_DMS_Core_4_6_0' => [ |
|
593 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
594 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
595 | - ], |
|
596 | - 'EE_DMS_Core_4_7_0' => [ |
|
597 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
598 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
599 | - ], |
|
600 | - 'EE_DMS_Core_4_8_0' => [ |
|
601 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
602 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
603 | - ], |
|
604 | - 'EE_DMS_Core_4_9_0' => [ |
|
605 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
606 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
607 | - ], |
|
608 | - 'EE_DMS_Core_4_10_0' => [ |
|
609 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
610 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
611 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
612 | - ], |
|
613 | - 'EventEspresso\core\services\assets\I18nRegistry' => [ |
|
614 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
615 | - 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
616 | - [], |
|
617 | - ], |
|
618 | - 'EventEspresso\core\services\assets\Registry' => [ |
|
619 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
620 | - 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
621 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
622 | - ], |
|
623 | - 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
624 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
625 | - ], |
|
626 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
627 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
628 | - ], |
|
629 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
630 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
631 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
632 | - ], |
|
633 | - 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
634 | - null, |
|
635 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
636 | - ], |
|
637 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
638 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
639 | - ], |
|
640 | - 'LEGACY_MODELS' => [ |
|
641 | - null, |
|
642 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
643 | - ], |
|
644 | - 'EE_Module_Request_Router' => [ |
|
645 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
646 | - ], |
|
647 | - 'EE_Registration_Processor' => [ |
|
648 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
649 | - ], |
|
650 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
651 | - null, |
|
652 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
653 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
654 | - ], |
|
655 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
656 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
657 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
658 | - ], |
|
659 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
660 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
661 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
662 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
663 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
664 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
665 | - ], |
|
666 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
667 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
668 | - ], |
|
669 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
670 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
671 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
672 | - ], |
|
673 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
674 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
675 | - ], |
|
676 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
677 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
678 | - ], |
|
679 | - 'EE_CPT_Strategy' => [ |
|
680 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
681 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
682 | - ], |
|
683 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
684 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
685 | - ], |
|
686 | - 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
687 | - null, |
|
688 | - null, |
|
689 | - null, |
|
690 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
691 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
692 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
693 | - ], |
|
694 | - 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
695 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
696 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
697 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
698 | - ], |
|
699 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
700 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
701 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
702 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
703 | - ], |
|
704 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
705 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
706 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
707 | - ], |
|
708 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
709 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
710 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
711 | - ], |
|
712 | - 'EE_URL_Validation_Strategy' => [ |
|
713 | - null, |
|
714 | - null, |
|
715 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
716 | - ], |
|
717 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
718 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
719 | - ], |
|
720 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
721 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
722 | - ], |
|
723 | - 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
724 | - 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
725 | - 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
726 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
727 | - null, |
|
728 | - ], |
|
729 | - 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
730 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
731 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
732 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
733 | - 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
734 | - ], |
|
735 | - 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
736 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
737 | - ], |
|
738 | - 'EventEspresso\core\services\routing\Router' => [ |
|
739 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
740 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
741 | - 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
742 | - ], |
|
743 | - 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
744 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
745 | - ], |
|
746 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
747 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
748 | - ], |
|
749 | - 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
750 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
751 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
752 | - ], |
|
753 | - ]; |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * Registers how core classes are loaded. |
|
759 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
760 | - * 'EE_Request_Handler' => 'load_core' |
|
761 | - * 'EE_Messages_Queue' => 'load_lib' |
|
762 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
763 | - * or, if greater control is required, by providing a custom closure. For example: |
|
764 | - * 'Some_Class' => function () { |
|
765 | - * return new Some_Class(); |
|
766 | - * }, |
|
767 | - * This is required for instantiating dependencies |
|
768 | - * where an interface has been type hinted in a class constructor. For example: |
|
769 | - * 'Required_Interface' => function () { |
|
770 | - * return new A_Class_That_Implements_Required_Interface(); |
|
771 | - * }, |
|
772 | - */ |
|
773 | - protected function _register_core_class_loaders() |
|
774 | - { |
|
775 | - $this->_class_loaders = [ |
|
776 | - // load_core |
|
777 | - 'EE_Dependency_Map' => function () { |
|
778 | - return $this; |
|
779 | - }, |
|
780 | - 'EE_Capabilities' => 'load_core', |
|
781 | - 'EE_Encryption' => 'load_core', |
|
782 | - 'EE_Front_Controller' => 'load_core', |
|
783 | - 'EE_Module_Request_Router' => 'load_core', |
|
784 | - 'EE_Registry' => 'load_core', |
|
785 | - 'EE_Request' => function () { |
|
786 | - return $this->legacy_request; |
|
787 | - }, |
|
788 | - 'EventEspresso\core\services\request\Request' => function () { |
|
789 | - return $this->request; |
|
790 | - }, |
|
791 | - 'EventEspresso\core\services\request\Response' => function () { |
|
792 | - return $this->response; |
|
793 | - }, |
|
794 | - 'EE_Base' => 'load_core', |
|
795 | - 'EE_Request_Handler' => 'load_core', |
|
796 | - 'EE_Session' => 'load_core', |
|
797 | - 'EE_Cron_Tasks' => 'load_core', |
|
798 | - 'EE_System' => 'load_core', |
|
799 | - 'EE_Maintenance_Mode' => 'load_core', |
|
800 | - 'EE_Register_CPTs' => 'load_core', |
|
801 | - 'EE_Admin' => 'load_core', |
|
802 | - 'EE_CPT_Strategy' => 'load_core', |
|
803 | - // load_class |
|
804 | - 'EE_Registration_Processor' => 'load_class', |
|
805 | - // load_lib |
|
806 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
807 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
808 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
809 | - 'EE_Messenger_Collection' => 'load_lib', |
|
810 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
811 | - 'EE_Messages_Processor' => 'load_lib', |
|
812 | - 'EE_Message_Repository' => 'load_lib', |
|
813 | - 'EE_Messages_Queue' => 'load_lib', |
|
814 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
815 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
816 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
817 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
818 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
819 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
820 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
821 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
822 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
823 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
824 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
825 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
826 | - 'EE_Messages_Generator' => static function () { |
|
827 | - return EE_Registry::instance()->load_lib( |
|
828 | - 'Messages_Generator', |
|
829 | - [], |
|
830 | - false, |
|
831 | - false |
|
832 | - ); |
|
833 | - }, |
|
834 | - 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
835 | - return EE_Registry::instance()->load_lib( |
|
836 | - 'Messages_Template_Defaults', |
|
837 | - $arguments, |
|
838 | - false, |
|
839 | - false |
|
840 | - ); |
|
841 | - }, |
|
842 | - // load_helper |
|
843 | - 'EEH_Parse_Shortcodes' => static function () { |
|
844 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
845 | - return new EEH_Parse_Shortcodes(); |
|
846 | - } |
|
847 | - return null; |
|
848 | - }, |
|
849 | - 'EE_Template_Config' => static function () { |
|
850 | - return EE_Config::instance()->template_settings; |
|
851 | - }, |
|
852 | - 'EE_Currency_Config' => static function () { |
|
853 | - return EE_Config::instance()->currency; |
|
854 | - }, |
|
855 | - 'EE_Registration_Config' => static function () { |
|
856 | - return EE_Config::instance()->registration; |
|
857 | - }, |
|
858 | - 'EE_Core_Config' => static function () { |
|
859 | - return EE_Config::instance()->core; |
|
860 | - }, |
|
861 | - 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
862 | - return LoaderFactory::getLoader(); |
|
863 | - }, |
|
864 | - 'EE_Network_Config' => static function () { |
|
865 | - return EE_Network_Config::instance(); |
|
866 | - }, |
|
867 | - 'EE_Config' => static function () { |
|
868 | - return EE_Config::instance(); |
|
869 | - }, |
|
870 | - 'EventEspresso\core\domain\Domain' => static function () { |
|
871 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
872 | - }, |
|
873 | - 'EE_Admin_Config' => static function () { |
|
874 | - return EE_Config::instance()->admin; |
|
875 | - }, |
|
876 | - 'EE_Organization_Config' => static function () { |
|
877 | - return EE_Config::instance()->organization; |
|
878 | - }, |
|
879 | - 'EE_Network_Core_Config' => static function () { |
|
880 | - return EE_Network_Config::instance()->core; |
|
881 | - }, |
|
882 | - 'EE_Environment_Config' => static function () { |
|
883 | - return EE_Config::instance()->environment; |
|
884 | - }, |
|
885 | - 'EED_Core_Rest_Api' => static function () { |
|
886 | - return EED_Core_Rest_Api::instance(); |
|
887 | - }, |
|
888 | - 'WP_REST_Server' => static function () { |
|
889 | - return rest_get_server(); |
|
890 | - }, |
|
891 | - ]; |
|
892 | - } |
|
893 | - |
|
894 | - |
|
895 | - /** |
|
896 | - * can be used for supplying alternate names for classes, |
|
897 | - * or for connecting interface names to instantiable classes |
|
898 | - * |
|
899 | - * @throws InvalidAliasException |
|
900 | - */ |
|
901 | - protected function _register_core_aliases() |
|
902 | - { |
|
903 | - $aliases = [ |
|
904 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
905 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
906 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
907 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
908 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
909 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
910 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
911 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
912 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
913 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
914 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
915 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
916 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
917 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
918 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
919 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
920 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
921 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
922 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
923 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
924 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
925 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
926 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
927 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
928 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
929 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
930 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
931 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
932 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
933 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
934 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
935 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
936 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
937 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
938 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
939 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
940 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
941 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
942 | - 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
943 | - ]; |
|
944 | - foreach ($aliases as $alias => $fqn) { |
|
945 | - if (is_array($fqn)) { |
|
946 | - foreach ($fqn as $class => $for_class) { |
|
947 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
948 | - } |
|
949 | - continue; |
|
950 | - } |
|
951 | - $this->class_cache->addAlias($fqn, $alias); |
|
952 | - } |
|
953 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
954 | - $this->class_cache->addAlias( |
|
955 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
956 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
957 | - ); |
|
958 | - } |
|
959 | - } |
|
960 | - |
|
961 | - |
|
962 | - /** |
|
963 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
964 | - * request Primarily used by unit tests. |
|
965 | - */ |
|
966 | - public function reset() |
|
967 | - { |
|
968 | - $this->_register_core_class_loaders(); |
|
969 | - $this->_register_core_dependencies(); |
|
970 | - } |
|
971 | - |
|
972 | - |
|
973 | - /** |
|
974 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
975 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
976 | - * WHY? |
|
977 | - * Because if a class is type hinting for a concretion, |
|
978 | - * then why would we need to find another class to supply it? |
|
979 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
980 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
981 | - * Don't go looking for some substitute. |
|
982 | - * Whereas if a class is type hinting for an interface... |
|
983 | - * then we need to find an actual class to use. |
|
984 | - * So the interface IS the alias for some other FQN, |
|
985 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
986 | - * represents some other class. |
|
987 | - * |
|
988 | - * @param string $fqn |
|
989 | - * @param string $for_class |
|
990 | - * @return bool |
|
991 | - * @deprecated 4.9.62.p |
|
992 | - */ |
|
993 | - public function has_alias($fqn = '', $for_class = '') |
|
994 | - { |
|
995 | - return $this->isAlias($fqn, $for_class); |
|
996 | - } |
|
997 | - |
|
998 | - |
|
999 | - /** |
|
1000 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1001 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1002 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1003 | - * for example: |
|
1004 | - * if the following two entries were added to the _aliases array: |
|
1005 | - * array( |
|
1006 | - * 'interface_alias' => 'some\namespace\interface' |
|
1007 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1008 | - * ) |
|
1009 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1010 | - * to load an instance of 'some\namespace\classname' |
|
1011 | - * |
|
1012 | - * @param string $alias |
|
1013 | - * @param string $for_class |
|
1014 | - * @return string |
|
1015 | - * @deprecated 4.9.62.p |
|
1016 | - */ |
|
1017 | - public function get_alias($alias = '', $for_class = '') |
|
1018 | - { |
|
1019 | - return $this->getFqnForAlias($alias, $for_class); |
|
1020 | - } |
|
24 | + /** |
|
25 | + * This means that the requested class dependency is not present in the dependency map |
|
26 | + */ |
|
27 | + const not_registered = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
31 | + */ |
|
32 | + const load_new_object = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
36 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
37 | + */ |
|
38 | + const load_from_cache = 2; |
|
39 | + |
|
40 | + /** |
|
41 | + * When registering a dependency, |
|
42 | + * this indicates to keep any existing dependencies that already exist, |
|
43 | + * and simply discard any new dependencies declared in the incoming data |
|
44 | + */ |
|
45 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
46 | + |
|
47 | + /** |
|
48 | + * When registering a dependency, |
|
49 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
50 | + */ |
|
51 | + const OVERWRITE_DEPENDENCIES = 1; |
|
52 | + |
|
53 | + /** |
|
54 | + * @type EE_Dependency_Map $_instance |
|
55 | + */ |
|
56 | + protected static $_instance; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var ClassInterfaceCache $class_cache |
|
60 | + */ |
|
61 | + private $class_cache; |
|
62 | + |
|
63 | + /** |
|
64 | + * @type RequestInterface $request |
|
65 | + */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** |
|
69 | + * @type LegacyRequestInterface $legacy_request |
|
70 | + */ |
|
71 | + protected $legacy_request; |
|
72 | + |
|
73 | + /** |
|
74 | + * @type ResponseInterface $response |
|
75 | + */ |
|
76 | + protected $response; |
|
77 | + |
|
78 | + /** |
|
79 | + * @type LoaderInterface $loader |
|
80 | + */ |
|
81 | + protected $loader; |
|
82 | + |
|
83 | + /** |
|
84 | + * @type array $_dependency_map |
|
85 | + */ |
|
86 | + protected $_dependency_map = []; |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = []; |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * EE_Dependency_Map constructor. |
|
96 | + * |
|
97 | + * @param ClassInterfaceCache $class_cache |
|
98 | + */ |
|
99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | + { |
|
101 | + $this->class_cache = $class_cache; |
|
102 | + do_action('EE_Dependency_Map____construct', $this); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return void |
|
108 | + * @throws InvalidAliasException |
|
109 | + */ |
|
110 | + public function initialize() |
|
111 | + { |
|
112 | + $this->_register_core_dependencies(); |
|
113 | + $this->_register_core_class_loaders(); |
|
114 | + $this->_register_core_aliases(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @singleton method used to instantiate class object |
|
120 | + * @param ClassInterfaceCache|null $class_cache |
|
121 | + * @return EE_Dependency_Map |
|
122 | + */ |
|
123 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
124 | + { |
|
125 | + // check if class object is instantiated, and instantiated properly |
|
126 | + if (! EE_Dependency_Map::$_instance instanceof EE_Dependency_Map |
|
127 | + && $class_cache instanceof ClassInterfaceCache |
|
128 | + ) { |
|
129 | + EE_Dependency_Map::$_instance = new EE_Dependency_Map($class_cache); |
|
130 | + } |
|
131 | + return EE_Dependency_Map::$_instance; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param RequestInterface $request |
|
137 | + */ |
|
138 | + public function setRequest(RequestInterface $request) |
|
139 | + { |
|
140 | + $this->request = $request; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param LegacyRequestInterface $legacy_request |
|
146 | + */ |
|
147 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
148 | + { |
|
149 | + $this->legacy_request = $legacy_request; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param ResponseInterface $response |
|
155 | + */ |
|
156 | + public function setResponse(ResponseInterface $response) |
|
157 | + { |
|
158 | + $this->response = $response; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param LoaderInterface $loader |
|
164 | + */ |
|
165 | + public function setLoader(LoaderInterface $loader) |
|
166 | + { |
|
167 | + $this->loader = $loader; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param string $class |
|
173 | + * @param array $dependencies |
|
174 | + * @param int $overwrite |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | + public static function register_dependencies( |
|
178 | + $class, |
|
179 | + array $dependencies, |
|
180 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
181 | + ) { |
|
182 | + return EE_Dependency_Map::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
188 | + * to the class specified by the first parameter. |
|
189 | + * IMPORTANT !!! |
|
190 | + * The order of elements in the incoming $dependencies array MUST match |
|
191 | + * the order of the constructor parameters for the class in question. |
|
192 | + * This is especially important when overriding any existing dependencies that are registered. |
|
193 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
194 | + * |
|
195 | + * @param string $class |
|
196 | + * @param array $dependencies |
|
197 | + * @param int $overwrite |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function registerDependencies( |
|
201 | + $class, |
|
202 | + array $dependencies, |
|
203 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
204 | + ) { |
|
205 | + $class = trim($class, '\\'); |
|
206 | + $registered = false; |
|
207 | + if (empty(EE_Dependency_Map::$_instance->_dependency_map[ $class ])) { |
|
208 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = []; |
|
209 | + } |
|
210 | + // we need to make sure that any aliases used when registering a dependency |
|
211 | + // get resolved to the correct class name |
|
212 | + foreach ($dependencies as $dependency => $load_source) { |
|
213 | + $alias = EE_Dependency_Map::$_instance->getFqnForAlias($dependency); |
|
214 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
215 | + || ! isset(EE_Dependency_Map::$_instance->_dependency_map[ $class ][ $alias ]) |
|
216 | + ) { |
|
217 | + unset($dependencies[ $dependency ]); |
|
218 | + $dependencies[ $alias ] = $load_source; |
|
219 | + $registered = true; |
|
220 | + } |
|
221 | + } |
|
222 | + // now add our two lists of dependencies together. |
|
223 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
224 | + // so $dependencies is NOT overwritten because it is listed first |
|
225 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
226 | + // Union is way faster than array_merge() but should be used with caution... |
|
227 | + // especially with numerically indexed arrays |
|
228 | + $dependencies += EE_Dependency_Map::$_instance->_dependency_map[ $class ]; |
|
229 | + // now we need to ensure that the resulting dependencies |
|
230 | + // array only has the entries that are required for the class |
|
231 | + // so first count how many dependencies were originally registered for the class |
|
232 | + $dependency_count = count(EE_Dependency_Map::$_instance->_dependency_map[ $class ]); |
|
233 | + // if that count is non-zero (meaning dependencies were already registered) |
|
234 | + EE_Dependency_Map::$_instance->_dependency_map[ $class ] = $dependency_count |
|
235 | + // then truncate the final array to match that count |
|
236 | + ? array_slice($dependencies, 0, $dependency_count) |
|
237 | + // otherwise just take the incoming array because nothing previously existed |
|
238 | + : $dependencies; |
|
239 | + return $registered; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string $class_name |
|
245 | + * @param string $loader |
|
246 | + * @return bool |
|
247 | + * @throws DomainException |
|
248 | + */ |
|
249 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
250 | + { |
|
251 | + return EE_Dependency_Map::$_instance->registerClassLoader($class_name, $loader); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $class_name |
|
257 | + * @param string $loader |
|
258 | + * @return bool |
|
259 | + * @throws DomainException |
|
260 | + */ |
|
261 | + public function registerClassLoader($class_name, $loader = 'load_core') |
|
262 | + { |
|
263 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
264 | + throw new DomainException( |
|
265 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
266 | + ); |
|
267 | + } |
|
268 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
269 | + if (! is_callable($loader) |
|
270 | + && ( |
|
271 | + strpos($loader, 'load_') !== 0 |
|
272 | + || ! method_exists('EE_Registry', $loader) |
|
273 | + ) |
|
274 | + ) { |
|
275 | + throw new DomainException( |
|
276 | + sprintf( |
|
277 | + esc_html__( |
|
278 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
279 | + 'event_espresso' |
|
280 | + ), |
|
281 | + $loader |
|
282 | + ) |
|
283 | + ); |
|
284 | + } |
|
285 | + $class_name = EE_Dependency_Map::$_instance->getFqnForAlias($class_name); |
|
286 | + if (! isset(EE_Dependency_Map::$_instance->_class_loaders[ $class_name ])) { |
|
287 | + EE_Dependency_Map::$_instance->_class_loaders[ $class_name ] = $loader; |
|
288 | + return true; |
|
289 | + } |
|
290 | + return false; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @return array |
|
296 | + */ |
|
297 | + public function dependency_map() |
|
298 | + { |
|
299 | + return $this->_dependency_map; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
305 | + * |
|
306 | + * @param string $class_name |
|
307 | + * @return boolean |
|
308 | + */ |
|
309 | + public function has($class_name = '') |
|
310 | + { |
|
311 | + // all legacy models have the same dependencies |
|
312 | + if (strpos($class_name, 'EEM_') === 0) { |
|
313 | + $class_name = 'LEGACY_MODELS'; |
|
314 | + } |
|
315 | + return isset($this->_dependency_map[ $class_name ]); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
321 | + * |
|
322 | + * @param string $class_name |
|
323 | + * @param string $dependency |
|
324 | + * @return bool |
|
325 | + */ |
|
326 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
327 | + { |
|
328 | + // all legacy models have the same dependencies |
|
329 | + if (strpos($class_name, 'EEM_') === 0) { |
|
330 | + $class_name = 'LEGACY_MODELS'; |
|
331 | + } |
|
332 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
333 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
339 | + * |
|
340 | + * @param string $class_name |
|
341 | + * @param string $dependency |
|
342 | + * @return int |
|
343 | + */ |
|
344 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
345 | + { |
|
346 | + // all legacy models have the same dependencies |
|
347 | + if (strpos($class_name, 'EEM_') === 0) { |
|
348 | + $class_name = 'LEGACY_MODELS'; |
|
349 | + } |
|
350 | + $dependency = $this->getFqnForAlias($dependency); |
|
351 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
352 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
353 | + : EE_Dependency_Map::not_registered; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param string $class_name |
|
359 | + * @return string | Closure |
|
360 | + */ |
|
361 | + public function class_loader($class_name) |
|
362 | + { |
|
363 | + // all legacy models use load_model() |
|
364 | + if (strpos($class_name, 'EEM_') === 0) { |
|
365 | + return 'load_model'; |
|
366 | + } |
|
367 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
368 | + // perform strpos() first to avoid loading regex every time we load a class |
|
369 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
370 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
371 | + ) { |
|
372 | + return 'load_core'; |
|
373 | + } |
|
374 | + $class_name = $this->getFqnForAlias($class_name); |
|
375 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return array |
|
381 | + */ |
|
382 | + public function class_loaders() |
|
383 | + { |
|
384 | + return $this->_class_loaders; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * adds an alias for a classname |
|
390 | + * |
|
391 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
392 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
393 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
394 | + * @throws InvalidAliasException |
|
395 | + */ |
|
396 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
397 | + { |
|
398 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
404 | + * WHY? |
|
405 | + * Because if a class is type hinting for a concretion, |
|
406 | + * then why would we need to find another class to supply it? |
|
407 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
408 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
409 | + * Don't go looking for some substitute. |
|
410 | + * Whereas if a class is type hinting for an interface... |
|
411 | + * then we need to find an actual class to use. |
|
412 | + * So the interface IS the alias for some other FQN, |
|
413 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
414 | + * represents some other class. |
|
415 | + * |
|
416 | + * @param string $fqn |
|
417 | + * @param string $for_class |
|
418 | + * @return bool |
|
419 | + */ |
|
420 | + public function isAlias($fqn = '', $for_class = '') |
|
421 | + { |
|
422 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
428 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
429 | + * for example: |
|
430 | + * if the following two entries were added to the _aliases array: |
|
431 | + * array( |
|
432 | + * 'interface_alias' => 'some\namespace\interface' |
|
433 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
434 | + * ) |
|
435 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
436 | + * to load an instance of 'some\namespace\classname' |
|
437 | + * |
|
438 | + * @param string $alias |
|
439 | + * @param string $for_class |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
443 | + { |
|
444 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
450 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
451 | + * This is done by using the following class constants: |
|
452 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
453 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
454 | + */ |
|
455 | + protected function _register_core_dependencies() |
|
456 | + { |
|
457 | + $this->_dependency_map = [ |
|
458 | + 'EE_Request_Handler' => [ |
|
459 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
460 | + ], |
|
461 | + 'EE_System' => [ |
|
462 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
463 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
464 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
465 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
466 | + 'EventEspresso\core\services\routing\Router' => EE_Dependency_Map::load_from_cache, |
|
467 | + ], |
|
468 | + 'EE_Admin' => [ |
|
469 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
470 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
471 | + ], |
|
472 | + 'EE_Cart' => [ |
|
473 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
474 | + ], |
|
475 | + 'EE_Messenger_Collection_Loader' => [ |
|
476 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
477 | + ], |
|
478 | + 'EE_Message_Type_Collection_Loader' => [ |
|
479 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
480 | + ], |
|
481 | + 'EE_Message_Resource_Manager' => [ |
|
482 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
483 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
484 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
485 | + ], |
|
486 | + 'EE_Message_Factory' => [ |
|
487 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
488 | + ], |
|
489 | + 'EE_messages' => [ |
|
490 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
491 | + ], |
|
492 | + 'EE_Messages_Generator' => [ |
|
493 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
494 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
495 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
496 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
497 | + ], |
|
498 | + 'EE_Messages_Processor' => [ |
|
499 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
500 | + ], |
|
501 | + 'EE_Messages_Queue' => [ |
|
502 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
503 | + ], |
|
504 | + 'EE_Messages_Template_Defaults' => [ |
|
505 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
506 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
507 | + ], |
|
508 | + 'EE_Message_To_Generate_From_Request' => [ |
|
509 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
511 | + ], |
|
512 | + 'EventEspresso\core\services\commands\CommandBus' => [ |
|
513 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
514 | + ], |
|
515 | + 'EventEspresso\services\commands\CommandHandler' => [ |
|
516 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
517 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
518 | + ], |
|
519 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => [ |
|
520 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
521 | + ], |
|
522 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => [ |
|
523 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
524 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
525 | + ], |
|
526 | + 'EventEspresso\core\services\commands\CommandFactory' => [ |
|
527 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
528 | + ], |
|
529 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => [ |
|
530 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
531 | + ], |
|
532 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => [ |
|
533 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
534 | + ], |
|
535 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => [ |
|
536 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
537 | + ], |
|
538 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => [ |
|
539 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
540 | + ], |
|
541 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => [ |
|
542 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
543 | + ], |
|
544 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => [ |
|
545 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
546 | + ], |
|
547 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => [ |
|
548 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
549 | + ], |
|
550 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => [ |
|
551 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
552 | + ], |
|
553 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => [ |
|
554 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
555 | + ], |
|
556 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => [ |
|
557 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
558 | + ], |
|
559 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => [ |
|
560 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
561 | + ], |
|
562 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => [ |
|
563 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
564 | + ], |
|
565 | + 'EventEspresso\core\services\database\TableManager' => [ |
|
566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | + ], |
|
568 | + 'EE_Data_Migration_Class_Base' => [ |
|
569 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
570 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
571 | + ], |
|
572 | + 'EE_DMS_Core_4_1_0' => [ |
|
573 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
574 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
575 | + ], |
|
576 | + 'EE_DMS_Core_4_2_0' => [ |
|
577 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
578 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
579 | + ], |
|
580 | + 'EE_DMS_Core_4_3_0' => [ |
|
581 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
582 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
583 | + ], |
|
584 | + 'EE_DMS_Core_4_4_0' => [ |
|
585 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
586 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
587 | + ], |
|
588 | + 'EE_DMS_Core_4_5_0' => [ |
|
589 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
590 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
591 | + ], |
|
592 | + 'EE_DMS_Core_4_6_0' => [ |
|
593 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
594 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
595 | + ], |
|
596 | + 'EE_DMS_Core_4_7_0' => [ |
|
597 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
598 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
599 | + ], |
|
600 | + 'EE_DMS_Core_4_8_0' => [ |
|
601 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
602 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
603 | + ], |
|
604 | + 'EE_DMS_Core_4_9_0' => [ |
|
605 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
606 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
607 | + ], |
|
608 | + 'EE_DMS_Core_4_10_0' => [ |
|
609 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
610 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
611 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
612 | + ], |
|
613 | + 'EventEspresso\core\services\assets\I18nRegistry' => [ |
|
614 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
615 | + 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
616 | + [], |
|
617 | + ], |
|
618 | + 'EventEspresso\core\services\assets\Registry' => [ |
|
619 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
620 | + 'EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache, |
|
621 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
622 | + ], |
|
623 | + 'EventEspresso\core\services\cache\BasicCacheManager' => [ |
|
624 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
625 | + ], |
|
626 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => [ |
|
627 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
628 | + ], |
|
629 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => [ |
|
630 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
631 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
632 | + ], |
|
633 | + 'EventEspresso\core\domain\values\EmailAddress' => [ |
|
634 | + null, |
|
635 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
636 | + ], |
|
637 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => [ |
|
638 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
639 | + ], |
|
640 | + 'LEGACY_MODELS' => [ |
|
641 | + null, |
|
642 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
643 | + ], |
|
644 | + 'EE_Module_Request_Router' => [ |
|
645 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
646 | + ], |
|
647 | + 'EE_Registration_Processor' => [ |
|
648 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
649 | + ], |
|
650 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => [ |
|
651 | + null, |
|
652 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
653 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
654 | + ], |
|
655 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => [ |
|
656 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
657 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
658 | + ], |
|
659 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => [ |
|
660 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
661 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
662 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
663 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
664 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
665 | + ], |
|
666 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => [ |
|
667 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
668 | + ], |
|
669 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => [ |
|
670 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
671 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
672 | + ], |
|
673 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => [ |
|
674 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
675 | + ], |
|
676 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => [ |
|
677 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
678 | + ], |
|
679 | + 'EE_CPT_Strategy' => [ |
|
680 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
681 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
682 | + ], |
|
683 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => [ |
|
684 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
685 | + ], |
|
686 | + 'EventEspresso\core\CPTs\CptQueryModifier' => [ |
|
687 | + null, |
|
688 | + null, |
|
689 | + null, |
|
690 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
691 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
692 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
693 | + ], |
|
694 | + 'EventEspresso\core\services\dependencies\DependencyResolver' => [ |
|
695 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
696 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
697 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
698 | + ], |
|
699 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => [ |
|
700 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
701 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
702 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
703 | + ], |
|
704 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => [ |
|
705 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
706 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
707 | + ], |
|
708 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => [ |
|
709 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
710 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
711 | + ], |
|
712 | + 'EE_URL_Validation_Strategy' => [ |
|
713 | + null, |
|
714 | + null, |
|
715 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache, |
|
716 | + ], |
|
717 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => [ |
|
718 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
719 | + ], |
|
720 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
721 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
722 | + ], |
|
723 | + 'EventEspresso\core\domain\services\converters\RestApiSpoofer' => [ |
|
724 | + 'WP_REST_Server' => EE_Dependency_Map::load_from_cache, |
|
725 | + 'EED_Core_Rest_Api' => EE_Dependency_Map::load_from_cache, |
|
726 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => EE_Dependency_Map::load_from_cache, |
|
727 | + null, |
|
728 | + ], |
|
729 | + 'EventEspresso\core\services\routing\RouteHandler' => [ |
|
730 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => EE_Dependency_Map::load_from_cache, |
|
731 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
732 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
733 | + 'EventEspresso\core\services\routing\RouteCollection' => EE_Dependency_Map::load_from_cache, |
|
734 | + ], |
|
735 | + 'EventEspresso\core\services\json\JsonDataNodeHandler' => [ |
|
736 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
737 | + ], |
|
738 | + 'EventEspresso\core\services\routing\Router' => [ |
|
739 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
740 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
741 | + 'EventEspresso\core\services\routing\RouteHandler' => EE_Dependency_Map::load_from_cache, |
|
742 | + ], |
|
743 | + 'EventEspresso\core\services\assets\AssetManifest' => [ |
|
744 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
745 | + ], |
|
746 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => [ |
|
747 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
748 | + ], |
|
749 | + 'EventEspresso\core\services\assets\BaristaFactory' => [ |
|
750 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache, |
|
751 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
752 | + ], |
|
753 | + ]; |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * Registers how core classes are loaded. |
|
759 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
760 | + * 'EE_Request_Handler' => 'load_core' |
|
761 | + * 'EE_Messages_Queue' => 'load_lib' |
|
762 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
763 | + * or, if greater control is required, by providing a custom closure. For example: |
|
764 | + * 'Some_Class' => function () { |
|
765 | + * return new Some_Class(); |
|
766 | + * }, |
|
767 | + * This is required for instantiating dependencies |
|
768 | + * where an interface has been type hinted in a class constructor. For example: |
|
769 | + * 'Required_Interface' => function () { |
|
770 | + * return new A_Class_That_Implements_Required_Interface(); |
|
771 | + * }, |
|
772 | + */ |
|
773 | + protected function _register_core_class_loaders() |
|
774 | + { |
|
775 | + $this->_class_loaders = [ |
|
776 | + // load_core |
|
777 | + 'EE_Dependency_Map' => function () { |
|
778 | + return $this; |
|
779 | + }, |
|
780 | + 'EE_Capabilities' => 'load_core', |
|
781 | + 'EE_Encryption' => 'load_core', |
|
782 | + 'EE_Front_Controller' => 'load_core', |
|
783 | + 'EE_Module_Request_Router' => 'load_core', |
|
784 | + 'EE_Registry' => 'load_core', |
|
785 | + 'EE_Request' => function () { |
|
786 | + return $this->legacy_request; |
|
787 | + }, |
|
788 | + 'EventEspresso\core\services\request\Request' => function () { |
|
789 | + return $this->request; |
|
790 | + }, |
|
791 | + 'EventEspresso\core\services\request\Response' => function () { |
|
792 | + return $this->response; |
|
793 | + }, |
|
794 | + 'EE_Base' => 'load_core', |
|
795 | + 'EE_Request_Handler' => 'load_core', |
|
796 | + 'EE_Session' => 'load_core', |
|
797 | + 'EE_Cron_Tasks' => 'load_core', |
|
798 | + 'EE_System' => 'load_core', |
|
799 | + 'EE_Maintenance_Mode' => 'load_core', |
|
800 | + 'EE_Register_CPTs' => 'load_core', |
|
801 | + 'EE_Admin' => 'load_core', |
|
802 | + 'EE_CPT_Strategy' => 'load_core', |
|
803 | + // load_class |
|
804 | + 'EE_Registration_Processor' => 'load_class', |
|
805 | + // load_lib |
|
806 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
807 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
808 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
809 | + 'EE_Messenger_Collection' => 'load_lib', |
|
810 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
811 | + 'EE_Messages_Processor' => 'load_lib', |
|
812 | + 'EE_Message_Repository' => 'load_lib', |
|
813 | + 'EE_Messages_Queue' => 'load_lib', |
|
814 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
815 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
816 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
817 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
818 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
819 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
820 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
821 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
822 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
823 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
824 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
825 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
826 | + 'EE_Messages_Generator' => static function () { |
|
827 | + return EE_Registry::instance()->load_lib( |
|
828 | + 'Messages_Generator', |
|
829 | + [], |
|
830 | + false, |
|
831 | + false |
|
832 | + ); |
|
833 | + }, |
|
834 | + 'EE_Messages_Template_Defaults' => static function ($arguments = []) { |
|
835 | + return EE_Registry::instance()->load_lib( |
|
836 | + 'Messages_Template_Defaults', |
|
837 | + $arguments, |
|
838 | + false, |
|
839 | + false |
|
840 | + ); |
|
841 | + }, |
|
842 | + // load_helper |
|
843 | + 'EEH_Parse_Shortcodes' => static function () { |
|
844 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
845 | + return new EEH_Parse_Shortcodes(); |
|
846 | + } |
|
847 | + return null; |
|
848 | + }, |
|
849 | + 'EE_Template_Config' => static function () { |
|
850 | + return EE_Config::instance()->template_settings; |
|
851 | + }, |
|
852 | + 'EE_Currency_Config' => static function () { |
|
853 | + return EE_Config::instance()->currency; |
|
854 | + }, |
|
855 | + 'EE_Registration_Config' => static function () { |
|
856 | + return EE_Config::instance()->registration; |
|
857 | + }, |
|
858 | + 'EE_Core_Config' => static function () { |
|
859 | + return EE_Config::instance()->core; |
|
860 | + }, |
|
861 | + 'EventEspresso\core\services\loaders\Loader' => static function () { |
|
862 | + return LoaderFactory::getLoader(); |
|
863 | + }, |
|
864 | + 'EE_Network_Config' => static function () { |
|
865 | + return EE_Network_Config::instance(); |
|
866 | + }, |
|
867 | + 'EE_Config' => static function () { |
|
868 | + return EE_Config::instance(); |
|
869 | + }, |
|
870 | + 'EventEspresso\core\domain\Domain' => static function () { |
|
871 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
872 | + }, |
|
873 | + 'EE_Admin_Config' => static function () { |
|
874 | + return EE_Config::instance()->admin; |
|
875 | + }, |
|
876 | + 'EE_Organization_Config' => static function () { |
|
877 | + return EE_Config::instance()->organization; |
|
878 | + }, |
|
879 | + 'EE_Network_Core_Config' => static function () { |
|
880 | + return EE_Network_Config::instance()->core; |
|
881 | + }, |
|
882 | + 'EE_Environment_Config' => static function () { |
|
883 | + return EE_Config::instance()->environment; |
|
884 | + }, |
|
885 | + 'EED_Core_Rest_Api' => static function () { |
|
886 | + return EED_Core_Rest_Api::instance(); |
|
887 | + }, |
|
888 | + 'WP_REST_Server' => static function () { |
|
889 | + return rest_get_server(); |
|
890 | + }, |
|
891 | + ]; |
|
892 | + } |
|
893 | + |
|
894 | + |
|
895 | + /** |
|
896 | + * can be used for supplying alternate names for classes, |
|
897 | + * or for connecting interface names to instantiable classes |
|
898 | + * |
|
899 | + * @throws InvalidAliasException |
|
900 | + */ |
|
901 | + protected function _register_core_aliases() |
|
902 | + { |
|
903 | + $aliases = [ |
|
904 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
905 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
906 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
907 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
908 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
909 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
910 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
911 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
912 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
913 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
914 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
915 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
916 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
917 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
918 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
919 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
920 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
921 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
922 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
923 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
924 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
925 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
926 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
927 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
928 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
929 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
930 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
931 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
932 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
933 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
934 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
935 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
936 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
937 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
938 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
939 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
940 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
941 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
942 | + 'EventEspresso\core\services\assets\AssetManifestInterface' => 'EventEspresso\core\services\assets\AssetManifest', |
|
943 | + ]; |
|
944 | + foreach ($aliases as $alias => $fqn) { |
|
945 | + if (is_array($fqn)) { |
|
946 | + foreach ($fqn as $class => $for_class) { |
|
947 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
948 | + } |
|
949 | + continue; |
|
950 | + } |
|
951 | + $this->class_cache->addAlias($fqn, $alias); |
|
952 | + } |
|
953 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
954 | + $this->class_cache->addAlias( |
|
955 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
956 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
957 | + ); |
|
958 | + } |
|
959 | + } |
|
960 | + |
|
961 | + |
|
962 | + /** |
|
963 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
964 | + * request Primarily used by unit tests. |
|
965 | + */ |
|
966 | + public function reset() |
|
967 | + { |
|
968 | + $this->_register_core_class_loaders(); |
|
969 | + $this->_register_core_dependencies(); |
|
970 | + } |
|
971 | + |
|
972 | + |
|
973 | + /** |
|
974 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
975 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
976 | + * WHY? |
|
977 | + * Because if a class is type hinting for a concretion, |
|
978 | + * then why would we need to find another class to supply it? |
|
979 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
980 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
981 | + * Don't go looking for some substitute. |
|
982 | + * Whereas if a class is type hinting for an interface... |
|
983 | + * then we need to find an actual class to use. |
|
984 | + * So the interface IS the alias for some other FQN, |
|
985 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
986 | + * represents some other class. |
|
987 | + * |
|
988 | + * @param string $fqn |
|
989 | + * @param string $for_class |
|
990 | + * @return bool |
|
991 | + * @deprecated 4.9.62.p |
|
992 | + */ |
|
993 | + public function has_alias($fqn = '', $for_class = '') |
|
994 | + { |
|
995 | + return $this->isAlias($fqn, $for_class); |
|
996 | + } |
|
997 | + |
|
998 | + |
|
999 | + /** |
|
1000 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1001 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1002 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1003 | + * for example: |
|
1004 | + * if the following two entries were added to the _aliases array: |
|
1005 | + * array( |
|
1006 | + * 'interface_alias' => 'some\namespace\interface' |
|
1007 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1008 | + * ) |
|
1009 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1010 | + * to load an instance of 'some\namespace\classname' |
|
1011 | + * |
|
1012 | + * @param string $alias |
|
1013 | + * @param string $for_class |
|
1014 | + * @return string |
|
1015 | + * @deprecated 4.9.62.p |
|
1016 | + */ |
|
1017 | + public function get_alias($alias = '', $for_class = '') |
|
1018 | + { |
|
1019 | + return $this->getFqnForAlias($alias, $for_class); |
|
1020 | + } |
|
1021 | 1021 | } |
@@ -19,208 +19,208 @@ |
||
19 | 19 | */ |
20 | 20 | class GQLRequests extends Route |
21 | 21 | { |
22 | - /** |
|
23 | - * @var AssetManifestFactory |
|
24 | - */ |
|
25 | - private $manifest_factory; |
|
22 | + /** |
|
23 | + * @var AssetManifestFactory |
|
24 | + */ |
|
25 | + private $manifest_factory; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * AssetRequests constructor. |
|
30 | - * |
|
31 | - * @param EE_Dependency_Map $dependency_map |
|
32 | - * @param LoaderInterface $loader |
|
33 | - * @param RequestInterface $request |
|
34 | - * @param AssetManifestFactory $manifest_factory |
|
35 | - */ |
|
36 | - public function __construct( |
|
37 | - EE_Dependency_Map $dependency_map, |
|
38 | - LoaderInterface $loader, |
|
39 | - RequestInterface $request, |
|
40 | - AssetManifestFactory $manifest_factory |
|
41 | - ) { |
|
42 | - $this->manifest_factory = $manifest_factory; |
|
43 | - parent::__construct($dependency_map, $loader, $request); |
|
44 | - } |
|
28 | + /** |
|
29 | + * AssetRequests constructor. |
|
30 | + * |
|
31 | + * @param EE_Dependency_Map $dependency_map |
|
32 | + * @param LoaderInterface $loader |
|
33 | + * @param RequestInterface $request |
|
34 | + * @param AssetManifestFactory $manifest_factory |
|
35 | + */ |
|
36 | + public function __construct( |
|
37 | + EE_Dependency_Map $dependency_map, |
|
38 | + LoaderInterface $loader, |
|
39 | + RequestInterface $request, |
|
40 | + AssetManifestFactory $manifest_factory |
|
41 | + ) { |
|
42 | + $this->manifest_factory = $manifest_factory; |
|
43 | + parent::__construct($dependency_map, $loader, $request); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * returns true if the current request matches this route |
|
49 | - * |
|
50 | - * @return bool |
|
51 | - * @since $VID:$ |
|
52 | - */ |
|
53 | - public function matchesCurrentRequest() |
|
54 | - { |
|
55 | - global $pagenow; |
|
56 | - return PHP_VERSION_ID > 70000 |
|
57 | - && ( |
|
58 | - $this->request->isGQL() |
|
59 | - || $this->request->isUnitTesting() |
|
60 | - || ( |
|
61 | - $this->request->isAdmin() |
|
62 | - && $this->request->getRequestParam('page') === 'espresso_events' |
|
63 | - && ( |
|
64 | - $this->request->getRequestParam('action') === 'create_new' |
|
65 | - || $this->request->getRequestParam('action') === 'edit' |
|
66 | - ) |
|
67 | - ) |
|
68 | - || ( |
|
69 | - $pagenow |
|
70 | - && ( |
|
71 | - $pagenow === 'post-new.php' |
|
72 | - || ( |
|
73 | - $pagenow === 'post.php' |
|
74 | - && $this->request->getRequestParam('action') === 'edit' |
|
75 | - ) |
|
76 | - ) |
|
77 | - ) |
|
78 | - ); |
|
79 | - } |
|
47 | + /** |
|
48 | + * returns true if the current request matches this route |
|
49 | + * |
|
50 | + * @return bool |
|
51 | + * @since $VID:$ |
|
52 | + */ |
|
53 | + public function matchesCurrentRequest() |
|
54 | + { |
|
55 | + global $pagenow; |
|
56 | + return PHP_VERSION_ID > 70000 |
|
57 | + && ( |
|
58 | + $this->request->isGQL() |
|
59 | + || $this->request->isUnitTesting() |
|
60 | + || ( |
|
61 | + $this->request->isAdmin() |
|
62 | + && $this->request->getRequestParam('page') === 'espresso_events' |
|
63 | + && ( |
|
64 | + $this->request->getRequestParam('action') === 'create_new' |
|
65 | + || $this->request->getRequestParam('action') === 'edit' |
|
66 | + ) |
|
67 | + ) |
|
68 | + || ( |
|
69 | + $pagenow |
|
70 | + && ( |
|
71 | + $pagenow === 'post-new.php' |
|
72 | + || ( |
|
73 | + $pagenow === 'post.php' |
|
74 | + && $this->request->getRequestParam('action') === 'edit' |
|
75 | + ) |
|
76 | + ) |
|
77 | + ) |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * @since $VID:$ |
|
84 | - */ |
|
85 | - protected function registerDependencies() |
|
86 | - { |
|
87 | - $this->dependency_map->registerDependencies( |
|
88 | - 'EventEspresso\core\services\graphql\GraphQLManager', |
|
89 | - [ |
|
90 | - 'EventEspresso\core\services\graphql\ConnectionsManager' => EE_Dependency_Map::load_from_cache, |
|
91 | - 'EventEspresso\core\services\graphql\DataLoaderManager' => EE_Dependency_Map::load_from_cache, |
|
92 | - 'EventEspresso\core\services\graphql\EnumsManager' => EE_Dependency_Map::load_from_cache, |
|
93 | - 'EventEspresso\core\services\graphql\InputsManager' => EE_Dependency_Map::load_from_cache, |
|
94 | - 'EventEspresso\core\services\graphql\TypesManager' => EE_Dependency_Map::load_from_cache, |
|
95 | - ] |
|
96 | - ); |
|
97 | - $this->dependency_map->registerDependencies( |
|
98 | - 'EventEspresso\core\services\graphql\TypesManager', |
|
99 | - [ |
|
100 | - 'EventEspresso\core\services\graphql\types\TypeCollection' => EE_Dependency_Map::load_from_cache, |
|
101 | - ] |
|
102 | - ); |
|
103 | - $this->dependency_map->registerDependencies( |
|
104 | - 'EventEspresso\core\services\graphql\InputsManager', |
|
105 | - [ |
|
106 | - 'EventEspresso\core\services\graphql\inputs\InputCollection' => EE_Dependency_Map::load_from_cache, |
|
107 | - ] |
|
108 | - ); |
|
109 | - $this->dependency_map->registerDependencies( |
|
110 | - 'EventEspresso\core\services\graphql\EnumsManager', |
|
111 | - [ |
|
112 | - 'EventEspresso\core\services\graphql\enums\EnumCollection' => EE_Dependency_Map::load_from_cache, |
|
113 | - ] |
|
114 | - ); |
|
115 | - $this->dependency_map->registerDependencies( |
|
116 | - 'EventEspresso\core\services\graphql\ConnectionsManager', |
|
117 | - [ |
|
118 | - 'EventEspresso\core\services\graphql\connections\ConnectionCollection' => EE_Dependency_Map::load_from_cache, |
|
119 | - ] |
|
120 | - ); |
|
121 | - $this->dependency_map->registerDependencies( |
|
122 | - 'EventEspresso\core\services\graphql\DataLoaderManager', |
|
123 | - [ |
|
124 | - 'EventEspresso\core\services\graphql\loaders\DataLoaderCollection' => EE_Dependency_Map::load_from_cache, |
|
125 | - ] |
|
126 | - ); |
|
127 | - $this->dependency_map->registerDependencies( |
|
128 | - 'EventEspresso\core\domain\services\graphql\types\Datetime', |
|
129 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
130 | - ); |
|
131 | - $this->dependency_map->registerDependencies( |
|
132 | - 'EventEspresso\core\domain\services\graphql\types\Attendee', |
|
133 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
134 | - ); |
|
135 | - $this->dependency_map->registerDependencies( |
|
136 | - 'EventEspresso\core\domain\services\graphql\types\Event', |
|
137 | - ['EEM_Event' => EE_Dependency_Map::load_from_cache] |
|
138 | - ); |
|
139 | - $this->dependency_map->registerDependencies( |
|
140 | - 'EventEspresso\core\domain\services\graphql\types\Ticket', |
|
141 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
142 | - ); |
|
143 | - $this->dependency_map->registerDependencies( |
|
144 | - 'EventEspresso\core\domain\services\graphql\types\Price', |
|
145 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
146 | - ); |
|
147 | - $this->dependency_map->registerDependencies( |
|
148 | - 'EventEspresso\core\domain\services\graphql\types\PriceType', |
|
149 | - ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
150 | - ); |
|
151 | - $this->dependency_map->registerDependencies( |
|
152 | - 'EventEspresso\core\domain\services\graphql\types\Venue', |
|
153 | - ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
154 | - ); |
|
155 | - $this->dependency_map->registerDependencies( |
|
156 | - 'EventEspresso\core\domain\services\graphql\types\State', |
|
157 | - ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
158 | - ); |
|
159 | - $this->dependency_map->registerDependencies( |
|
160 | - 'EventEspresso\core\domain\services\graphql\types\Country', |
|
161 | - ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
162 | - ); |
|
163 | - $this->dependency_map->registerDependencies( |
|
164 | - 'EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection', |
|
165 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
166 | - ); |
|
167 | - $this->dependency_map->registerDependencies( |
|
168 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryDatetimesConnection', |
|
169 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
170 | - ); |
|
171 | - $this->dependency_map->registerDependencies( |
|
172 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryAttendeesConnection', |
|
173 | - ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
174 | - ); |
|
175 | - $this->dependency_map->registerDependencies( |
|
176 | - 'EventEspresso\core\domain\services\graphql\connections\DatetimeTicketsConnection', |
|
177 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
178 | - ); |
|
179 | - $this->dependency_map->registerDependencies( |
|
180 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryTicketsConnection', |
|
181 | - ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
182 | - ); |
|
183 | - $this->dependency_map->registerDependencies( |
|
184 | - 'EventEspresso\core\domain\services\graphql\connections\TicketPricesConnection', |
|
185 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
186 | - ); |
|
187 | - $this->dependency_map->registerDependencies( |
|
188 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryPricesConnection', |
|
189 | - ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
190 | - ); |
|
191 | - $this->dependency_map->registerDependencies( |
|
192 | - 'EventEspresso\core\domain\services\graphql\connections\RootQueryPriceTypesConnection', |
|
193 | - ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
194 | - ); |
|
195 | - $this->dependency_map->registerDependencies( |
|
196 | - 'EventEspresso\core\domain\services\graphql\connections\TicketDatetimesConnection', |
|
197 | - ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
198 | - ); |
|
199 | - $this->dependency_map->registerDependencies( |
|
200 | - 'EventEspresso\core\domain\services\graphql\connections\EventVenuesConnection', |
|
201 | - ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
202 | - ); |
|
203 | - } |
|
82 | + /** |
|
83 | + * @since $VID:$ |
|
84 | + */ |
|
85 | + protected function registerDependencies() |
|
86 | + { |
|
87 | + $this->dependency_map->registerDependencies( |
|
88 | + 'EventEspresso\core\services\graphql\GraphQLManager', |
|
89 | + [ |
|
90 | + 'EventEspresso\core\services\graphql\ConnectionsManager' => EE_Dependency_Map::load_from_cache, |
|
91 | + 'EventEspresso\core\services\graphql\DataLoaderManager' => EE_Dependency_Map::load_from_cache, |
|
92 | + 'EventEspresso\core\services\graphql\EnumsManager' => EE_Dependency_Map::load_from_cache, |
|
93 | + 'EventEspresso\core\services\graphql\InputsManager' => EE_Dependency_Map::load_from_cache, |
|
94 | + 'EventEspresso\core\services\graphql\TypesManager' => EE_Dependency_Map::load_from_cache, |
|
95 | + ] |
|
96 | + ); |
|
97 | + $this->dependency_map->registerDependencies( |
|
98 | + 'EventEspresso\core\services\graphql\TypesManager', |
|
99 | + [ |
|
100 | + 'EventEspresso\core\services\graphql\types\TypeCollection' => EE_Dependency_Map::load_from_cache, |
|
101 | + ] |
|
102 | + ); |
|
103 | + $this->dependency_map->registerDependencies( |
|
104 | + 'EventEspresso\core\services\graphql\InputsManager', |
|
105 | + [ |
|
106 | + 'EventEspresso\core\services\graphql\inputs\InputCollection' => EE_Dependency_Map::load_from_cache, |
|
107 | + ] |
|
108 | + ); |
|
109 | + $this->dependency_map->registerDependencies( |
|
110 | + 'EventEspresso\core\services\graphql\EnumsManager', |
|
111 | + [ |
|
112 | + 'EventEspresso\core\services\graphql\enums\EnumCollection' => EE_Dependency_Map::load_from_cache, |
|
113 | + ] |
|
114 | + ); |
|
115 | + $this->dependency_map->registerDependencies( |
|
116 | + 'EventEspresso\core\services\graphql\ConnectionsManager', |
|
117 | + [ |
|
118 | + 'EventEspresso\core\services\graphql\connections\ConnectionCollection' => EE_Dependency_Map::load_from_cache, |
|
119 | + ] |
|
120 | + ); |
|
121 | + $this->dependency_map->registerDependencies( |
|
122 | + 'EventEspresso\core\services\graphql\DataLoaderManager', |
|
123 | + [ |
|
124 | + 'EventEspresso\core\services\graphql\loaders\DataLoaderCollection' => EE_Dependency_Map::load_from_cache, |
|
125 | + ] |
|
126 | + ); |
|
127 | + $this->dependency_map->registerDependencies( |
|
128 | + 'EventEspresso\core\domain\services\graphql\types\Datetime', |
|
129 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
130 | + ); |
|
131 | + $this->dependency_map->registerDependencies( |
|
132 | + 'EventEspresso\core\domain\services\graphql\types\Attendee', |
|
133 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
134 | + ); |
|
135 | + $this->dependency_map->registerDependencies( |
|
136 | + 'EventEspresso\core\domain\services\graphql\types\Event', |
|
137 | + ['EEM_Event' => EE_Dependency_Map::load_from_cache] |
|
138 | + ); |
|
139 | + $this->dependency_map->registerDependencies( |
|
140 | + 'EventEspresso\core\domain\services\graphql\types\Ticket', |
|
141 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
142 | + ); |
|
143 | + $this->dependency_map->registerDependencies( |
|
144 | + 'EventEspresso\core\domain\services\graphql\types\Price', |
|
145 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
146 | + ); |
|
147 | + $this->dependency_map->registerDependencies( |
|
148 | + 'EventEspresso\core\domain\services\graphql\types\PriceType', |
|
149 | + ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
150 | + ); |
|
151 | + $this->dependency_map->registerDependencies( |
|
152 | + 'EventEspresso\core\domain\services\graphql\types\Venue', |
|
153 | + ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
154 | + ); |
|
155 | + $this->dependency_map->registerDependencies( |
|
156 | + 'EventEspresso\core\domain\services\graphql\types\State', |
|
157 | + ['EEM_State' => EE_Dependency_Map::load_from_cache] |
|
158 | + ); |
|
159 | + $this->dependency_map->registerDependencies( |
|
160 | + 'EventEspresso\core\domain\services\graphql\types\Country', |
|
161 | + ['EEM_Country' => EE_Dependency_Map::load_from_cache] |
|
162 | + ); |
|
163 | + $this->dependency_map->registerDependencies( |
|
164 | + 'EventEspresso\core\domain\services\graphql\connections\EventDatetimesConnection', |
|
165 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
166 | + ); |
|
167 | + $this->dependency_map->registerDependencies( |
|
168 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryDatetimesConnection', |
|
169 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
170 | + ); |
|
171 | + $this->dependency_map->registerDependencies( |
|
172 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryAttendeesConnection', |
|
173 | + ['EEM_Attendee' => EE_Dependency_Map::load_from_cache] |
|
174 | + ); |
|
175 | + $this->dependency_map->registerDependencies( |
|
176 | + 'EventEspresso\core\domain\services\graphql\connections\DatetimeTicketsConnection', |
|
177 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
178 | + ); |
|
179 | + $this->dependency_map->registerDependencies( |
|
180 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryTicketsConnection', |
|
181 | + ['EEM_Ticket' => EE_Dependency_Map::load_from_cache] |
|
182 | + ); |
|
183 | + $this->dependency_map->registerDependencies( |
|
184 | + 'EventEspresso\core\domain\services\graphql\connections\TicketPricesConnection', |
|
185 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
186 | + ); |
|
187 | + $this->dependency_map->registerDependencies( |
|
188 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryPricesConnection', |
|
189 | + ['EEM_Price' => EE_Dependency_Map::load_from_cache] |
|
190 | + ); |
|
191 | + $this->dependency_map->registerDependencies( |
|
192 | + 'EventEspresso\core\domain\services\graphql\connections\RootQueryPriceTypesConnection', |
|
193 | + ['EEM_Price_Type' => EE_Dependency_Map::load_from_cache] |
|
194 | + ); |
|
195 | + $this->dependency_map->registerDependencies( |
|
196 | + 'EventEspresso\core\domain\services\graphql\connections\TicketDatetimesConnection', |
|
197 | + ['EEM_Datetime' => EE_Dependency_Map::load_from_cache] |
|
198 | + ); |
|
199 | + $this->dependency_map->registerDependencies( |
|
200 | + 'EventEspresso\core\domain\services\graphql\connections\EventVenuesConnection', |
|
201 | + ['EEM_Venue' => EE_Dependency_Map::load_from_cache] |
|
202 | + ); |
|
203 | + } |
|
204 | 204 | |
205 | 205 | |
206 | - /** |
|
207 | - * implements logic required to run during request |
|
208 | - * |
|
209 | - * @return bool |
|
210 | - * @since $VID:$ |
|
211 | - */ |
|
212 | - protected function requestHandler() |
|
213 | - { |
|
214 | - if (! class_exists('WPGraphQL')) { |
|
215 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
216 | - } |
|
217 | - // load handler for EE GraphQL requests |
|
218 | - $graphQL_manager = $this->loader->getShared( |
|
219 | - 'EventEspresso\core\services\graphql\GraphQLManager' |
|
220 | - ); |
|
221 | - $graphQL_manager->init(); |
|
222 | - $manifest = $this->manifest_factory->createFromDomainObject(DomainFactory::getEventEspressoCoreDomain()); |
|
223 | - $manifest->initialize(); |
|
224 | - return true; |
|
225 | - } |
|
206 | + /** |
|
207 | + * implements logic required to run during request |
|
208 | + * |
|
209 | + * @return bool |
|
210 | + * @since $VID:$ |
|
211 | + */ |
|
212 | + protected function requestHandler() |
|
213 | + { |
|
214 | + if (! class_exists('WPGraphQL')) { |
|
215 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
216 | + } |
|
217 | + // load handler for EE GraphQL requests |
|
218 | + $graphQL_manager = $this->loader->getShared( |
|
219 | + 'EventEspresso\core\services\graphql\GraphQLManager' |
|
220 | + ); |
|
221 | + $graphQL_manager->init(); |
|
222 | + $manifest = $this->manifest_factory->createFromDomainObject(DomainFactory::getEventEspressoCoreDomain()); |
|
223 | + $manifest->initialize(); |
|
224 | + return true; |
|
225 | + } |
|
226 | 226 | } |
@@ -23,147 +23,147 @@ |
||
23 | 23 | class AssetRequests extends Route |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var BaristaFactory $barista_factory |
|
28 | - */ |
|
29 | - protected $barista_factory; |
|
26 | + /** |
|
27 | + * @var BaristaFactory $barista_factory |
|
28 | + */ |
|
29 | + protected $barista_factory; |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * AssetRequests constructor. |
|
34 | - * |
|
35 | - * @param EE_Dependency_Map $dependency_map |
|
36 | - * @param LoaderInterface $loader |
|
37 | - * @param RequestInterface $request |
|
38 | - * @param BaristaFactory $barista_factory |
|
39 | - */ |
|
40 | - public function __construct( |
|
41 | - EE_Dependency_Map $dependency_map, |
|
42 | - LoaderInterface $loader, |
|
43 | - RequestInterface $request, |
|
44 | - BaristaFactory $barista_factory |
|
45 | - ) { |
|
46 | - $this->barista_factory = $barista_factory; |
|
47 | - parent::__construct($dependency_map, $loader, $request); |
|
48 | - } |
|
32 | + /** |
|
33 | + * AssetRequests constructor. |
|
34 | + * |
|
35 | + * @param EE_Dependency_Map $dependency_map |
|
36 | + * @param LoaderInterface $loader |
|
37 | + * @param RequestInterface $request |
|
38 | + * @param BaristaFactory $barista_factory |
|
39 | + */ |
|
40 | + public function __construct( |
|
41 | + EE_Dependency_Map $dependency_map, |
|
42 | + LoaderInterface $loader, |
|
43 | + RequestInterface $request, |
|
44 | + BaristaFactory $barista_factory |
|
45 | + ) { |
|
46 | + $this->barista_factory = $barista_factory; |
|
47 | + parent::__construct($dependency_map, $loader, $request); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * returns true if the current request matches this route |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - * @since $VID:$ |
|
56 | - */ |
|
57 | - public function matchesCurrentRequest() |
|
58 | - { |
|
59 | - return $this->request->isAdmin() |
|
60 | - || $this->request->isFrontend() |
|
61 | - || $this->request->isIframe() |
|
62 | - || $this->request->isWordPressApi(); |
|
63 | - } |
|
51 | + /** |
|
52 | + * returns true if the current request matches this route |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + * @since $VID:$ |
|
56 | + */ |
|
57 | + public function matchesCurrentRequest() |
|
58 | + { |
|
59 | + return $this->request->isAdmin() |
|
60 | + || $this->request->isFrontend() |
|
61 | + || $this->request->isIframe() |
|
62 | + || $this->request->isWordPressApi(); |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * @since $VID:$ |
|
68 | - */ |
|
69 | - protected function registerDependencies() |
|
70 | - { |
|
71 | - $default_dependencies = [ |
|
72 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
73 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
74 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
75 | - ]; |
|
76 | - $this->dependency_map->registerDependencies(JqueryAssetManager::class, $default_dependencies); |
|
77 | - $this->dependency_map->registerDependencies(ReactAssetManager::class, $default_dependencies); |
|
78 | - $this->dependency_map->registerDependencies( |
|
79 | - CoreAssetManager::class, |
|
80 | - [ |
|
81 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
82 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
83 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
84 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
85 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
86 | - ] |
|
87 | - ); |
|
88 | - $this->dependency_map->registerDependencies( |
|
89 | - 'EventEspresso\core\services\editor\BlockRegistrationManager', |
|
90 | - [ |
|
91 | - 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
92 | - 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
93 | - 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
94 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
95 | - ] |
|
96 | - ); |
|
97 | - $this->dependency_map->registerDependencies( |
|
98 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager', |
|
99 | - [ |
|
100 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
101 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
102 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
103 | - ] |
|
104 | - ); |
|
105 | - $this->dependency_map->registerDependencies( |
|
106 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer', |
|
107 | - [ |
|
108 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
109 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
110 | - ] |
|
111 | - ); |
|
112 | - $this->dependency_map->registerDependencies( |
|
113 | - 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees', |
|
114 | - [ |
|
115 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => EE_Dependency_Map::load_from_cache, |
|
116 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
117 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => EE_Dependency_Map::load_from_cache, |
|
118 | - ] |
|
119 | - ); |
|
120 | - if (apply_filters('FHEE__load_Barista', true)) { |
|
121 | - $this->dependency_map->registerDependencies( |
|
122 | - 'EventEspresso\core\services\assets\Barista', |
|
123 | - ['EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache] |
|
124 | - ); |
|
125 | - } |
|
126 | - } |
|
66 | + /** |
|
67 | + * @since $VID:$ |
|
68 | + */ |
|
69 | + protected function registerDependencies() |
|
70 | + { |
|
71 | + $default_dependencies = [ |
|
72 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
73 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
74 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
75 | + ]; |
|
76 | + $this->dependency_map->registerDependencies(JqueryAssetManager::class, $default_dependencies); |
|
77 | + $this->dependency_map->registerDependencies(ReactAssetManager::class, $default_dependencies); |
|
78 | + $this->dependency_map->registerDependencies( |
|
79 | + CoreAssetManager::class, |
|
80 | + [ |
|
81 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
82 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
83 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
84 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
85 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
86 | + ] |
|
87 | + ); |
|
88 | + $this->dependency_map->registerDependencies( |
|
89 | + 'EventEspresso\core\services\editor\BlockRegistrationManager', |
|
90 | + [ |
|
91 | + 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
92 | + 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
93 | + 'EventEspresso\core\services\routing\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
94 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
95 | + ] |
|
96 | + ); |
|
97 | + $this->dependency_map->registerDependencies( |
|
98 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager', |
|
99 | + [ |
|
100 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
101 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_new_object, |
|
102 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
103 | + ] |
|
104 | + ); |
|
105 | + $this->dependency_map->registerDependencies( |
|
106 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer', |
|
107 | + [ |
|
108 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
109 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
110 | + ] |
|
111 | + ); |
|
112 | + $this->dependency_map->registerDependencies( |
|
113 | + 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees', |
|
114 | + [ |
|
115 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => EE_Dependency_Map::load_from_cache, |
|
116 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
117 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => EE_Dependency_Map::load_from_cache, |
|
118 | + ] |
|
119 | + ); |
|
120 | + if (apply_filters('FHEE__load_Barista', true)) { |
|
121 | + $this->dependency_map->registerDependencies( |
|
122 | + 'EventEspresso\core\services\assets\Barista', |
|
123 | + ['EventEspresso\core\services\assets\AssetManifest' => EE_Dependency_Map::load_from_cache] |
|
124 | + ); |
|
125 | + } |
|
126 | + } |
|
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * implements logic required to run during request |
|
131 | - * |
|
132 | - * @return bool |
|
133 | - * @since $VID:$ |
|
134 | - */ |
|
135 | - protected function requestHandler() |
|
136 | - { |
|
137 | - if (apply_filters('FHEE__load_Barista', true)) { |
|
138 | - $barista = $this->barista_factory->create(); |
|
139 | - if ($barista instanceof BaristaInterface) { |
|
140 | - $barista->initialize(); |
|
141 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
142 | - } |
|
143 | - } |
|
144 | - $this->loader->getShared(JqueryAssetManager::class); |
|
145 | - $this->loader->getShared(CoreAssetManager::class); |
|
146 | - if ($this->canLoadBlocks()) { |
|
147 | - $this->loader->getShared( |
|
148 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
149 | - ); |
|
150 | - } |
|
151 | - return true; |
|
152 | - } |
|
129 | + /** |
|
130 | + * implements logic required to run during request |
|
131 | + * |
|
132 | + * @return bool |
|
133 | + * @since $VID:$ |
|
134 | + */ |
|
135 | + protected function requestHandler() |
|
136 | + { |
|
137 | + if (apply_filters('FHEE__load_Barista', true)) { |
|
138 | + $barista = $this->barista_factory->create(); |
|
139 | + if ($barista instanceof BaristaInterface) { |
|
140 | + $barista->initialize(); |
|
141 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
142 | + } |
|
143 | + } |
|
144 | + $this->loader->getShared(JqueryAssetManager::class); |
|
145 | + $this->loader->getShared(CoreAssetManager::class); |
|
146 | + if ($this->canLoadBlocks()) { |
|
147 | + $this->loader->getShared( |
|
148 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
149 | + ); |
|
150 | + } |
|
151 | + return true; |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * Return whether blocks can be registered/loaded or not. |
|
157 | - * |
|
158 | - * @return bool |
|
159 | - * @since $VID:$ |
|
160 | - */ |
|
161 | - private function canLoadBlocks() |
|
162 | - { |
|
163 | - return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
164 | - && function_exists('register_block_type') |
|
165 | - // don't load blocks if in the Divi page builder editor context |
|
166 | - // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
167 | - && ! $this->request->getRequestParam('et_fb', false); |
|
168 | - } |
|
155 | + /** |
|
156 | + * Return whether blocks can be registered/loaded or not. |
|
157 | + * |
|
158 | + * @return bool |
|
159 | + * @since $VID:$ |
|
160 | + */ |
|
161 | + private function canLoadBlocks() |
|
162 | + { |
|
163 | + return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
164 | + && function_exists('register_block_type') |
|
165 | + // don't load blocks if in the Divi page builder editor context |
|
166 | + // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
167 | + && ! $this->request->getRequestParam('et_fb', false); |
|
168 | + } |
|
169 | 169 | } |
@@ -17,134 +17,134 @@ |
||
17 | 17 | class RegularRequests extends PrimaryRoute |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * called just before matchesCurrentRequest() |
|
22 | - * and allows Route to perform any setup required such as calling setSpecification() |
|
23 | - * |
|
24 | - * @since $VID:$ |
|
25 | - */ |
|
26 | - public function initialize() |
|
27 | - { |
|
28 | - $basic_nodes = [ |
|
29 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api', |
|
30 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser', |
|
31 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale', |
|
32 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls', |
|
33 | - ]; |
|
34 | - foreach ($basic_nodes as $basic_node) { |
|
35 | - $this->dependency_map->registerDependencies( |
|
36 | - $basic_node, |
|
37 | - ['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache] |
|
38 | - ); |
|
39 | - } |
|
40 | - $this->dependency_map->registerDependencies( |
|
41 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings', |
|
42 | - [ |
|
43 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
44 | - 'EventEspresso\core\services\converters\date_time_formats\PhpToUnicode' => EE_Dependency_Map::load_from_cache, |
|
45 | - ] |
|
46 | - ); |
|
47 | - $this->dependency_map->registerDependencies( |
|
48 | - 'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData', |
|
49 | - [ |
|
50 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api' => EE_Dependency_Map::load_from_cache, |
|
51 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache, |
|
52 | - 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
53 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
54 | - ] |
|
55 | - ); |
|
56 | - $this->dependency_map->registerDependencies( |
|
57 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config', |
|
58 | - [ |
|
59 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
60 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache, |
|
61 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings' => EE_Dependency_Map::load_from_cache, |
|
62 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale' => EE_Dependency_Map::load_from_cache, |
|
63 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency' => EE_Dependency_Map::load_from_cache, |
|
64 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls' => EE_Dependency_Map::load_from_cache, |
|
65 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
66 | - ] |
|
67 | - ); |
|
68 | - $this->dependency_map->registerDependencies( |
|
69 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain', |
|
70 | - [ |
|
71 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
72 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
73 | - ] |
|
74 | - ); |
|
75 | - $this->dependency_map->registerDependencies( |
|
76 | - 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency', |
|
77 | - [ |
|
78 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
79 | - 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
80 | - ] |
|
81 | - ); |
|
82 | - $this->setDataNode( |
|
83 | - $this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData') |
|
84 | - ); |
|
85 | - } |
|
20 | + /** |
|
21 | + * called just before matchesCurrentRequest() |
|
22 | + * and allows Route to perform any setup required such as calling setSpecification() |
|
23 | + * |
|
24 | + * @since $VID:$ |
|
25 | + */ |
|
26 | + public function initialize() |
|
27 | + { |
|
28 | + $basic_nodes = [ |
|
29 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api', |
|
30 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser', |
|
31 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale', |
|
32 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls', |
|
33 | + ]; |
|
34 | + foreach ($basic_nodes as $basic_node) { |
|
35 | + $this->dependency_map->registerDependencies( |
|
36 | + $basic_node, |
|
37 | + ['EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache] |
|
38 | + ); |
|
39 | + } |
|
40 | + $this->dependency_map->registerDependencies( |
|
41 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings', |
|
42 | + [ |
|
43 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
44 | + 'EventEspresso\core\services\converters\date_time_formats\PhpToUnicode' => EE_Dependency_Map::load_from_cache, |
|
45 | + ] |
|
46 | + ); |
|
47 | + $this->dependency_map->registerDependencies( |
|
48 | + 'EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData', |
|
49 | + [ |
|
50 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Api' => EE_Dependency_Map::load_from_cache, |
|
51 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config' => EE_Dependency_Map::load_from_cache, |
|
52 | + 'EventEspresso\core\services\assets\JedLocaleData' => EE_Dependency_Map::load_from_cache, |
|
53 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
54 | + ] |
|
55 | + ); |
|
56 | + $this->dependency_map->registerDependencies( |
|
57 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Config', |
|
58 | + [ |
|
59 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\CurrentUser' => EE_Dependency_Map::load_from_cache, |
|
60 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain' => EE_Dependency_Map::load_from_cache, |
|
61 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\GeneralSettings' => EE_Dependency_Map::load_from_cache, |
|
62 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\Locale' => EE_Dependency_Map::load_from_cache, |
|
63 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency' => EE_Dependency_Map::load_from_cache, |
|
64 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteUrls' => EE_Dependency_Map::load_from_cache, |
|
65 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
66 | + ] |
|
67 | + ); |
|
68 | + $this->dependency_map->registerDependencies( |
|
69 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\EspressoCoreDomain', |
|
70 | + [ |
|
71 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
72 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
73 | + ] |
|
74 | + ); |
|
75 | + $this->dependency_map->registerDependencies( |
|
76 | + 'EventEspresso\core\domain\entities\routing\data_nodes\core\SiteCurrency', |
|
77 | + [ |
|
78 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
79 | + 'EventEspresso\core\services\json\JsonDataNodeValidator' => EE_Dependency_Map::load_from_cache, |
|
80 | + ] |
|
81 | + ); |
|
82 | + $this->setDataNode( |
|
83 | + $this->loader->getShared('EventEspresso\core\domain\entities\routing\data_nodes\EventEspressoData') |
|
84 | + ); |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * returns true if the current request matches this route |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - * @since $VID:$ |
|
93 | - */ |
|
94 | - public function matchesCurrentRequest() |
|
95 | - { |
|
96 | - return ! $this->request->isActivation() || $this->request->isUnitTesting(); |
|
97 | - } |
|
88 | + /** |
|
89 | + * returns true if the current request matches this route |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + * @since $VID:$ |
|
93 | + */ |
|
94 | + public function matchesCurrentRequest() |
|
95 | + { |
|
96 | + return ! $this->request->isActivation() || $this->request->isUnitTesting(); |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - /** |
|
101 | - * @since $VID:$ |
|
102 | - */ |
|
103 | - protected function registerDependencies() |
|
104 | - { |
|
105 | - $admin = ['EE_Admin_Config' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies; |
|
106 | - $public = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies; |
|
107 | - $default_with_barista = [ |
|
108 | - 'EventEspresso\core\services\assets\BaristaFactory' => EE_Dependency_Map::load_from_cache |
|
109 | - ] + Route::$default_dependencies; |
|
110 | - $default_with_manifest = [ |
|
111 | - 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache |
|
112 | - ] + Route::$default_dependencies; |
|
113 | - $default_routes = [ |
|
114 | - // default dependencies |
|
115 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests' => Route::$default_dependencies, |
|
116 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage' => Route::$default_dependencies, |
|
117 | - 'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests' => Route::$default_dependencies, |
|
118 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests' => Route::$default_dependencies, |
|
119 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests' => Route::$default_dependencies, |
|
120 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat' => Route::$default_dependencies, |
|
121 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests' => $default_with_barista, |
|
122 | - 'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests' => $default_with_manifest, |
|
123 | - // admin dependencies |
|
124 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute' => $admin, |
|
125 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin' => $admin, |
|
126 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor' => $admin, |
|
127 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin' => $admin, |
|
128 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor' => $admin, |
|
129 | - // public dependencies |
|
130 | - 'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests' => $public, |
|
131 | - 'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests' => $public, |
|
132 | - ]; |
|
133 | - foreach ($default_routes as $route => $dependencies) { |
|
134 | - $this->dependency_map->registerDependencies($route, $dependencies); |
|
135 | - } |
|
136 | - } |
|
100 | + /** |
|
101 | + * @since $VID:$ |
|
102 | + */ |
|
103 | + protected function registerDependencies() |
|
104 | + { |
|
105 | + $admin = ['EE_Admin_Config' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies; |
|
106 | + $public = ['EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache] + Route::$default_dependencies; |
|
107 | + $default_with_barista = [ |
|
108 | + 'EventEspresso\core\services\assets\BaristaFactory' => EE_Dependency_Map::load_from_cache |
|
109 | + ] + Route::$default_dependencies; |
|
110 | + $default_with_manifest = [ |
|
111 | + 'EventEspresso\core\services\assets\AssetManifestFactory' => EE_Dependency_Map::load_from_cache |
|
112 | + ] + Route::$default_dependencies; |
|
113 | + $default_routes = [ |
|
114 | + // default dependencies |
|
115 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\PueRequests' => Route::$default_dependencies, |
|
116 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\WordPressPluginsPage' => Route::$default_dependencies, |
|
117 | + 'EventEspresso\core\domain\entities\routing\handlers\frontend\ShortcodeRequests' => Route::$default_dependencies, |
|
118 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\RestApiRequests' => Route::$default_dependencies, |
|
119 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\SessionRequests' => Route::$default_dependencies, |
|
120 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\WordPressHeartbeat' => Route::$default_dependencies, |
|
121 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\AssetRequests' => $default_with_barista, |
|
122 | + 'EventEspresso\core\domain\entities\routing\handlers\shared\GQLRequests' => $default_with_manifest, |
|
123 | + // admin dependencies |
|
124 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\AdminRoute' => $admin, |
|
125 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventsAdmin' => $admin, |
|
126 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoEventEditor' => $admin, |
|
127 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\EspressoLegacyAdmin' => $admin, |
|
128 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\GutenbergEditor' => $admin, |
|
129 | + // public dependencies |
|
130 | + 'EventEspresso\core\domain\entities\routing\handlers\admin\PersonalDataRequests' => $public, |
|
131 | + 'EventEspresso\core\domain\entities\routing\handlers\frontend\FrontendRequests' => $public, |
|
132 | + ]; |
|
133 | + foreach ($default_routes as $route => $dependencies) { |
|
134 | + $this->dependency_map->registerDependencies($route, $dependencies); |
|
135 | + } |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * implements logic required to run during request |
|
141 | - * |
|
142 | - * @return bool |
|
143 | - * @since $VID:$ |
|
144 | - */ |
|
145 | - protected function requestHandler() |
|
146 | - { |
|
147 | - $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR); |
|
148 | - return true; |
|
149 | - } |
|
139 | + /** |
|
140 | + * implements logic required to run during request |
|
141 | + * |
|
142 | + * @return bool |
|
143 | + * @since $VID:$ |
|
144 | + */ |
|
145 | + protected function requestHandler() |
|
146 | + { |
|
147 | + $this->setRouteRequestType(PrimaryRoute::ROUTE_REQUEST_TYPE_REGULAR); |
|
148 | + return true; |
|
149 | + } |
|
150 | 150 | } |
@@ -18,215 +18,215 @@ |
||
18 | 18 | abstract class DomainBase implements DomainInterface |
19 | 19 | { |
20 | 20 | |
21 | - const ASSETS_FOLDER = 'assets/'; |
|
22 | - |
|
23 | - /** |
|
24 | - * Equivalent to `__FILE__` for main plugin file. |
|
25 | - * |
|
26 | - * @var FilePath |
|
27 | - */ |
|
28 | - private $plugin_file; |
|
29 | - |
|
30 | - /** |
|
31 | - * String indicating version for plugin |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - private $version; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string $plugin_basename |
|
39 | - */ |
|
40 | - private $plugin_basename; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string $plugin_path |
|
44 | - */ |
|
45 | - private $plugin_path; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string $plugin_url |
|
49 | - */ |
|
50 | - private $plugin_url; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string $asset_namespace |
|
54 | - */ |
|
55 | - private $asset_namespace; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var string $assets_path |
|
59 | - */ |
|
60 | - private $assets_path; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var bool |
|
64 | - */ |
|
65 | - protected $initialized = false; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Initializes internal properties. |
|
70 | - * |
|
71 | - * @param FilePath $plugin_file |
|
72 | - * @param Version $version |
|
73 | - * @param string $asset_namespace |
|
74 | - */ |
|
75 | - public function __construct(FilePath $plugin_file, Version $version, $asset_namespace = 'eventespresso') |
|
76 | - { |
|
77 | - $this->plugin_file = $plugin_file; |
|
78 | - $this->version = $version; |
|
79 | - $this->initialize($asset_namespace); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $asset_namespace |
|
85 | - * @return void |
|
86 | - * @since $VID:$ |
|
87 | - */ |
|
88 | - public function initialize($asset_namespace = 'eventespresso') |
|
89 | - { |
|
90 | - if (! $this->initialized) { |
|
91 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
92 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
93 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
94 | - $this->setAssetNamespace($asset_namespace); |
|
95 | - $this->setDistributionAssetsPath(); |
|
96 | - $this->initialized = true; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $asset_namespace |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public function setAssetNamespace($asset_namespace = 'eventespresso') |
|
106 | - { |
|
107 | - if (! $this->asset_namespace) { |
|
108 | - $this->asset_namespace = sanitize_key( |
|
109 | - // convert directory separators to dashes and remove file extension |
|
110 | - str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
|
111 | - ); |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @throws DomainException |
|
118 | - * @since $VID:$ |
|
119 | - */ |
|
120 | - private function setDistributionAssetsPath() |
|
121 | - { |
|
122 | - $assets_path = $this->pluginPath() . DomainBase::ASSETS_FOLDER; |
|
123 | - if (! is_readable($assets_path)) { |
|
124 | - throw new DomainException( |
|
125 | - sprintf( |
|
126 | - esc_html__( |
|
127 | - 'The assets distribution folder was not found or is not readable. Please verify that "%1$s" exists and has valid permissions.', |
|
128 | - 'event_espresso' |
|
129 | - ), |
|
130 | - $assets_path |
|
131 | - ) |
|
132 | - ); |
|
133 | - } |
|
134 | - $this->assets_path = trailingslashit($assets_path); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function pluginFile() |
|
142 | - { |
|
143 | - return (string) $this->plugin_file; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - public function pluginBasename() |
|
151 | - { |
|
152 | - return $this->plugin_basename; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @return string |
|
158 | - */ |
|
159 | - public function pluginPath() |
|
160 | - { |
|
161 | - return $this->plugin_path; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function pluginUrl() |
|
169 | - { |
|
170 | - return $this->plugin_url; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function version() |
|
178 | - { |
|
179 | - return (string) $this->version; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @return Version |
|
185 | - */ |
|
186 | - public function versionValueObject() |
|
187 | - { |
|
188 | - return $this->version; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * @return string |
|
194 | - */ |
|
195 | - public function distributionAssetsFolder() |
|
196 | - { |
|
197 | - return DomainBase::ASSETS_FOLDER; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $additional_path |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - public function distributionAssetsPath($additional_path = '') |
|
206 | - { |
|
207 | - return is_string($additional_path) && $additional_path !== '' |
|
208 | - ? $this->assets_path . $additional_path |
|
209 | - : $this->assets_path; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @param string $additional_path |
|
215 | - * @return string |
|
216 | - */ |
|
217 | - public function distributionAssetsUrl($additional_path = '') |
|
218 | - { |
|
219 | - return is_string($additional_path) && $additional_path !== '' |
|
220 | - ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
221 | - : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function assetNamespace() |
|
229 | - { |
|
230 | - return $this->asset_namespace; |
|
231 | - } |
|
21 | + const ASSETS_FOLDER = 'assets/'; |
|
22 | + |
|
23 | + /** |
|
24 | + * Equivalent to `__FILE__` for main plugin file. |
|
25 | + * |
|
26 | + * @var FilePath |
|
27 | + */ |
|
28 | + private $plugin_file; |
|
29 | + |
|
30 | + /** |
|
31 | + * String indicating version for plugin |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + private $version; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string $plugin_basename |
|
39 | + */ |
|
40 | + private $plugin_basename; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string $plugin_path |
|
44 | + */ |
|
45 | + private $plugin_path; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string $plugin_url |
|
49 | + */ |
|
50 | + private $plugin_url; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string $asset_namespace |
|
54 | + */ |
|
55 | + private $asset_namespace; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var string $assets_path |
|
59 | + */ |
|
60 | + private $assets_path; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var bool |
|
64 | + */ |
|
65 | + protected $initialized = false; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Initializes internal properties. |
|
70 | + * |
|
71 | + * @param FilePath $plugin_file |
|
72 | + * @param Version $version |
|
73 | + * @param string $asset_namespace |
|
74 | + */ |
|
75 | + public function __construct(FilePath $plugin_file, Version $version, $asset_namespace = 'eventespresso') |
|
76 | + { |
|
77 | + $this->plugin_file = $plugin_file; |
|
78 | + $this->version = $version; |
|
79 | + $this->initialize($asset_namespace); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $asset_namespace |
|
85 | + * @return void |
|
86 | + * @since $VID:$ |
|
87 | + */ |
|
88 | + public function initialize($asset_namespace = 'eventespresso') |
|
89 | + { |
|
90 | + if (! $this->initialized) { |
|
91 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
92 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
93 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
94 | + $this->setAssetNamespace($asset_namespace); |
|
95 | + $this->setDistributionAssetsPath(); |
|
96 | + $this->initialized = true; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $asset_namespace |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public function setAssetNamespace($asset_namespace = 'eventespresso') |
|
106 | + { |
|
107 | + if (! $this->asset_namespace) { |
|
108 | + $this->asset_namespace = sanitize_key( |
|
109 | + // convert directory separators to dashes and remove file extension |
|
110 | + str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
|
111 | + ); |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @throws DomainException |
|
118 | + * @since $VID:$ |
|
119 | + */ |
|
120 | + private function setDistributionAssetsPath() |
|
121 | + { |
|
122 | + $assets_path = $this->pluginPath() . DomainBase::ASSETS_FOLDER; |
|
123 | + if (! is_readable($assets_path)) { |
|
124 | + throw new DomainException( |
|
125 | + sprintf( |
|
126 | + esc_html__( |
|
127 | + 'The assets distribution folder was not found or is not readable. Please verify that "%1$s" exists and has valid permissions.', |
|
128 | + 'event_espresso' |
|
129 | + ), |
|
130 | + $assets_path |
|
131 | + ) |
|
132 | + ); |
|
133 | + } |
|
134 | + $this->assets_path = trailingslashit($assets_path); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function pluginFile() |
|
142 | + { |
|
143 | + return (string) $this->plugin_file; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + public function pluginBasename() |
|
151 | + { |
|
152 | + return $this->plugin_basename; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @return string |
|
158 | + */ |
|
159 | + public function pluginPath() |
|
160 | + { |
|
161 | + return $this->plugin_path; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function pluginUrl() |
|
169 | + { |
|
170 | + return $this->plugin_url; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function version() |
|
178 | + { |
|
179 | + return (string) $this->version; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @return Version |
|
185 | + */ |
|
186 | + public function versionValueObject() |
|
187 | + { |
|
188 | + return $this->version; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * @return string |
|
194 | + */ |
|
195 | + public function distributionAssetsFolder() |
|
196 | + { |
|
197 | + return DomainBase::ASSETS_FOLDER; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $additional_path |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + public function distributionAssetsPath($additional_path = '') |
|
206 | + { |
|
207 | + return is_string($additional_path) && $additional_path !== '' |
|
208 | + ? $this->assets_path . $additional_path |
|
209 | + : $this->assets_path; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @param string $additional_path |
|
215 | + * @return string |
|
216 | + */ |
|
217 | + public function distributionAssetsUrl($additional_path = '') |
|
218 | + { |
|
219 | + return is_string($additional_path) && $additional_path !== '' |
|
220 | + ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
221 | + : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function assetNamespace() |
|
229 | + { |
|
230 | + return $this->asset_namespace; |
|
231 | + } |
|
232 | 232 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function initialize($asset_namespace = 'eventespresso') |
89 | 89 | { |
90 | - if (! $this->initialized) { |
|
90 | + if ( ! $this->initialized) { |
|
91 | 91 | $this->plugin_basename = plugin_basename($this->pluginFile()); |
92 | 92 | $this->plugin_path = plugin_dir_path($this->pluginFile()); |
93 | 93 | $this->plugin_url = plugin_dir_url($this->pluginFile()); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function setAssetNamespace($asset_namespace = 'eventespresso') |
106 | 106 | { |
107 | - if (! $this->asset_namespace) { |
|
107 | + if ( ! $this->asset_namespace) { |
|
108 | 108 | $this->asset_namespace = sanitize_key( |
109 | 109 | // convert directory separators to dashes and remove file extension |
110 | 110 | str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | */ |
120 | 120 | private function setDistributionAssetsPath() |
121 | 121 | { |
122 | - $assets_path = $this->pluginPath() . DomainBase::ASSETS_FOLDER; |
|
123 | - if (! is_readable($assets_path)) { |
|
122 | + $assets_path = $this->pluginPath().DomainBase::ASSETS_FOLDER; |
|
123 | + if ( ! is_readable($assets_path)) { |
|
124 | 124 | throw new DomainException( |
125 | 125 | sprintf( |
126 | 126 | esc_html__( |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | public function distributionAssetsPath($additional_path = '') |
206 | 206 | { |
207 | 207 | return is_string($additional_path) && $additional_path !== '' |
208 | - ? $this->assets_path . $additional_path |
|
208 | + ? $this->assets_path.$additional_path |
|
209 | 209 | : $this->assets_path; |
210 | 210 | } |
211 | 211 | |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | public function distributionAssetsUrl($additional_path = '') |
218 | 218 | { |
219 | 219 | return is_string($additional_path) && $additional_path !== '' |
220 | - ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
221 | - : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
220 | + ? $this->plugin_url.DomainBase::ASSETS_FOLDER.$additional_path |
|
221 | + : $this->plugin_url.DomainBase::ASSETS_FOLDER; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 |