@@ -21,192 +21,192 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * AssetCollection constructor |
|
26 | - * |
|
27 | - * @throws InvalidInterfaceException |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @return StylesheetAsset[] |
|
37 | - * @since 4.9.62.p |
|
38 | - */ |
|
39 | - public function getStylesheetAssets() |
|
40 | - { |
|
41 | - return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return JavascriptAsset[] |
|
47 | - * @since 4.9.62.p |
|
48 | - */ |
|
49 | - public function getJavascriptAssets() |
|
50 | - { |
|
51 | - return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return ManifestFile[] |
|
57 | - * @since 4.9.62.p |
|
58 | - */ |
|
59 | - public function getManifestFiles() |
|
60 | - { |
|
61 | - return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param $type |
|
67 | - * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[] |
|
68 | - * @since 4.9.62.p |
|
69 | - */ |
|
70 | - protected function getAssetsOfType($type) |
|
71 | - { |
|
72 | - $files = array(); |
|
73 | - $this->rewind(); |
|
74 | - while ($this->valid()) { |
|
75 | - /** @var Asset $asset */ |
|
76 | - $asset = $this->current(); |
|
77 | - if ($asset->type() === $type) { |
|
78 | - $files[ $asset->handle() ] = $asset; |
|
79 | - } |
|
80 | - $this->next(); |
|
81 | - } |
|
82 | - $this->rewind(); |
|
83 | - return $files; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return JavascriptAsset[] |
|
89 | - * @since 4.9.62.p |
|
90 | - */ |
|
91 | - public function getJavascriptAssetsWithData() |
|
92 | - { |
|
93 | - $files = array(); |
|
94 | - $this->rewind(); |
|
95 | - while ($this->valid()) { |
|
96 | - /** @var JavascriptAsset $asset */ |
|
97 | - $asset = $this->current(); |
|
98 | - if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
|
99 | - $files[ $asset->handle() ] = $asset; |
|
100 | - } |
|
101 | - $this->next(); |
|
102 | - } |
|
103 | - $this->rewind(); |
|
104 | - return $files; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * returns TRUE or FALSE |
|
110 | - * depending on whether the object is within the Collection |
|
111 | - * based on the supplied $identifier and type |
|
112 | - * |
|
113 | - * @param mixed $identifier |
|
114 | - * @param string $type |
|
115 | - * @return bool |
|
116 | - * @since $VID:$ |
|
117 | - */ |
|
118 | - public function hasAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
119 | - { |
|
120 | - $this->rewind(); |
|
121 | - while ($this->valid()) { |
|
122 | - if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
123 | - $this->rewind(); |
|
124 | - return true; |
|
125 | - } |
|
126 | - $this->next(); |
|
127 | - } |
|
128 | - return false; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * returns TRUE or FALSE |
|
134 | - * depending on whether the Javascript Asset is within the Collection |
|
135 | - * based on the supplied $identifier |
|
136 | - * |
|
137 | - * @param mixed $identifier |
|
138 | - * @return bool |
|
139 | - * @since $VID:$ |
|
140 | - */ |
|
141 | - public function hasJavascriptAsset($identifier) |
|
142 | - { |
|
143 | - return $this->hasAssetOfType($identifier, Asset::TYPE_JS); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * returns TRUE or FALSE |
|
149 | - * depending on whether the Stylesheet Asset is within the Collection |
|
150 | - * based on the supplied $identifier |
|
151 | - * |
|
152 | - * @param mixed $identifier |
|
153 | - * @return bool |
|
154 | - * @since $VID:$ |
|
155 | - */ |
|
156 | - public function hasStylesheetAsset($identifier) |
|
157 | - { |
|
158 | - return $this->hasAssetOfType($identifier, Asset::TYPE_CSS); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * returns the object from the Collection |
|
163 | - * based on the supplied $identifier and type |
|
164 | - * |
|
165 | - * @param mixed $identifier |
|
166 | - * @param string $type |
|
167 | - * @return JavascriptAsset|StylesheetAsset |
|
168 | - * @since $VID:$ |
|
169 | - */ |
|
170 | - public function getAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
171 | - { |
|
172 | - $this->rewind(); |
|
173 | - while ($this->valid()) { |
|
174 | - if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
175 | - /** @var JavascriptAsset|StylesheetAsset $object */ |
|
176 | - $object = $this->current(); |
|
177 | - $this->rewind(); |
|
178 | - return $object; |
|
179 | - } |
|
180 | - $this->next(); |
|
181 | - } |
|
182 | - return null; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * returns the Stylesheet Asset from the Collection |
|
188 | - * based on the supplied $identifier |
|
189 | - * |
|
190 | - * @param mixed $identifier |
|
191 | - * @return StylesheetAsset |
|
192 | - * @since $VID:$ |
|
193 | - */ |
|
194 | - public function getStylesheetAsset($identifier) |
|
195 | - { |
|
196 | - return $this->getAssetOfType($identifier, Asset::TYPE_CSS); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * returns the Javascript Asset from the Collection |
|
202 | - * based on the supplied $identifier |
|
203 | - * |
|
204 | - * @param mixed $identifier |
|
205 | - * @return JavascriptAsset |
|
206 | - * @since $VID:$ |
|
207 | - */ |
|
208 | - public function getJavascriptAsset($identifier) |
|
209 | - { |
|
210 | - return $this->getAssetOfType($identifier, Asset::TYPE_JS); |
|
211 | - } |
|
24 | + /** |
|
25 | + * AssetCollection constructor |
|
26 | + * |
|
27 | + * @throws InvalidInterfaceException |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @return StylesheetAsset[] |
|
37 | + * @since 4.9.62.p |
|
38 | + */ |
|
39 | + public function getStylesheetAssets() |
|
40 | + { |
|
41 | + return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return JavascriptAsset[] |
|
47 | + * @since 4.9.62.p |
|
48 | + */ |
|
49 | + public function getJavascriptAssets() |
|
50 | + { |
|
51 | + return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return ManifestFile[] |
|
57 | + * @since 4.9.62.p |
|
58 | + */ |
|
59 | + public function getManifestFiles() |
|
60 | + { |
|
61 | + return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param $type |
|
67 | + * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[] |
|
68 | + * @since 4.9.62.p |
|
69 | + */ |
|
70 | + protected function getAssetsOfType($type) |
|
71 | + { |
|
72 | + $files = array(); |
|
73 | + $this->rewind(); |
|
74 | + while ($this->valid()) { |
|
75 | + /** @var Asset $asset */ |
|
76 | + $asset = $this->current(); |
|
77 | + if ($asset->type() === $type) { |
|
78 | + $files[ $asset->handle() ] = $asset; |
|
79 | + } |
|
80 | + $this->next(); |
|
81 | + } |
|
82 | + $this->rewind(); |
|
83 | + return $files; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return JavascriptAsset[] |
|
89 | + * @since 4.9.62.p |
|
90 | + */ |
|
91 | + public function getJavascriptAssetsWithData() |
|
92 | + { |
|
93 | + $files = array(); |
|
94 | + $this->rewind(); |
|
95 | + while ($this->valid()) { |
|
96 | + /** @var JavascriptAsset $asset */ |
|
97 | + $asset = $this->current(); |
|
98 | + if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) { |
|
99 | + $files[ $asset->handle() ] = $asset; |
|
100 | + } |
|
101 | + $this->next(); |
|
102 | + } |
|
103 | + $this->rewind(); |
|
104 | + return $files; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * returns TRUE or FALSE |
|
110 | + * depending on whether the object is within the Collection |
|
111 | + * based on the supplied $identifier and type |
|
112 | + * |
|
113 | + * @param mixed $identifier |
|
114 | + * @param string $type |
|
115 | + * @return bool |
|
116 | + * @since $VID:$ |
|
117 | + */ |
|
118 | + public function hasAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
119 | + { |
|
120 | + $this->rewind(); |
|
121 | + while ($this->valid()) { |
|
122 | + if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
123 | + $this->rewind(); |
|
124 | + return true; |
|
125 | + } |
|
126 | + $this->next(); |
|
127 | + } |
|
128 | + return false; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * returns TRUE or FALSE |
|
134 | + * depending on whether the Javascript Asset is within the Collection |
|
135 | + * based on the supplied $identifier |
|
136 | + * |
|
137 | + * @param mixed $identifier |
|
138 | + * @return bool |
|
139 | + * @since $VID:$ |
|
140 | + */ |
|
141 | + public function hasJavascriptAsset($identifier) |
|
142 | + { |
|
143 | + return $this->hasAssetOfType($identifier, Asset::TYPE_JS); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * returns TRUE or FALSE |
|
149 | + * depending on whether the Stylesheet Asset is within the Collection |
|
150 | + * based on the supplied $identifier |
|
151 | + * |
|
152 | + * @param mixed $identifier |
|
153 | + * @return bool |
|
154 | + * @since $VID:$ |
|
155 | + */ |
|
156 | + public function hasStylesheetAsset($identifier) |
|
157 | + { |
|
158 | + return $this->hasAssetOfType($identifier, Asset::TYPE_CSS); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * returns the object from the Collection |
|
163 | + * based on the supplied $identifier and type |
|
164 | + * |
|
165 | + * @param mixed $identifier |
|
166 | + * @param string $type |
|
167 | + * @return JavascriptAsset|StylesheetAsset |
|
168 | + * @since $VID:$ |
|
169 | + */ |
|
170 | + public function getAssetOfType($identifier, $type = Asset::TYPE_JS) |
|
171 | + { |
|
172 | + $this->rewind(); |
|
173 | + while ($this->valid()) { |
|
174 | + if ($this->getInfo() === $identifier && $this->current()->type() === $type) { |
|
175 | + /** @var JavascriptAsset|StylesheetAsset $object */ |
|
176 | + $object = $this->current(); |
|
177 | + $this->rewind(); |
|
178 | + return $object; |
|
179 | + } |
|
180 | + $this->next(); |
|
181 | + } |
|
182 | + return null; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * returns the Stylesheet Asset from the Collection |
|
188 | + * based on the supplied $identifier |
|
189 | + * |
|
190 | + * @param mixed $identifier |
|
191 | + * @return StylesheetAsset |
|
192 | + * @since $VID:$ |
|
193 | + */ |
|
194 | + public function getStylesheetAsset($identifier) |
|
195 | + { |
|
196 | + return $this->getAssetOfType($identifier, Asset::TYPE_CSS); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * returns the Javascript Asset from the Collection |
|
202 | + * based on the supplied $identifier |
|
203 | + * |
|
204 | + * @param mixed $identifier |
|
205 | + * @return JavascriptAsset |
|
206 | + * @since $VID:$ |
|
207 | + */ |
|
208 | + public function getJavascriptAsset($identifier) |
|
209 | + { |
|
210 | + return $this->getAssetOfType($identifier, Asset::TYPE_JS); |
|
211 | + } |
|
212 | 212 | } |
@@ -28,569 +28,569 @@ |
||
28 | 28 | class CptQueryModifier |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @var string $post_type |
|
33 | - */ |
|
34 | - protected $post_type = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * CPT details from CustomPostTypeDefinitions for specific post type |
|
38 | - * |
|
39 | - * @var array $cpt_details |
|
40 | - */ |
|
41 | - protected $cpt_details = array(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EE_Table_Base[] $model_tables |
|
45 | - */ |
|
46 | - protected $model_tables = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array $taxonomies |
|
50 | - */ |
|
51 | - protected $taxonomies = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * meta table for the related CPT |
|
55 | - * |
|
56 | - * @var EE_Secondary_Table $meta_table |
|
57 | - */ |
|
58 | - protected $meta_table; |
|
59 | - |
|
60 | - /** |
|
61 | - * EEM_CPT_Base model for the related CPT |
|
62 | - * |
|
63 | - * @var EEM_CPT_Base $model |
|
64 | - */ |
|
65 | - protected $model; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var EE_Request_Handler $request_handler |
|
69 | - */ |
|
70 | - protected $request_handler; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var WP_Query $wp_query |
|
74 | - */ |
|
75 | - protected $wp_query; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var LoaderInterface $loader |
|
79 | - */ |
|
80 | - protected $loader; |
|
81 | - |
|
82 | - /** |
|
83 | - * @var RequestInterface $request |
|
84 | - */ |
|
85 | - protected $request; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * CptQueryModifier constructor |
|
90 | - * |
|
91 | - * @param string $post_type |
|
92 | - * @param array $cpt_details |
|
93 | - * @param WP_Query $WP_Query |
|
94 | - * @param EE_Request_Handler $request_handler |
|
95 | - * @param RequestInterface $request |
|
96 | - * @param LoaderInterface $loader |
|
97 | - * @throws EE_Error |
|
98 | - */ |
|
99 | - public function __construct( |
|
100 | - $post_type, |
|
101 | - array $cpt_details, |
|
102 | - WP_Query $WP_Query, |
|
103 | - EE_Request_Handler $request_handler, |
|
104 | - RequestInterface $request, |
|
105 | - LoaderInterface $loader |
|
106 | - ) { |
|
107 | - $this->loader = $loader; |
|
108 | - $this->request = $request; |
|
109 | - $this->request_handler = $request_handler; |
|
110 | - $this->setWpQuery($WP_Query); |
|
111 | - $this->setPostType($post_type); |
|
112 | - $this->setCptDetails($cpt_details); |
|
113 | - $this->init(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function postType() |
|
121 | - { |
|
122 | - return $this->post_type; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $post_type |
|
128 | - */ |
|
129 | - protected function setPostType($post_type) |
|
130 | - { |
|
131 | - $this->post_type = $post_type; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @return array |
|
137 | - */ |
|
138 | - public function cptDetails() |
|
139 | - { |
|
140 | - return $this->cpt_details; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param array $cpt_details |
|
146 | - */ |
|
147 | - protected function setCptDetails($cpt_details) |
|
148 | - { |
|
149 | - $this->cpt_details = $cpt_details; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @return EE_Table_Base[] |
|
155 | - */ |
|
156 | - public function modelTables() |
|
157 | - { |
|
158 | - return $this->model_tables; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param EE_Table_Base[] $model_tables |
|
164 | - */ |
|
165 | - protected function setModelTables($model_tables) |
|
166 | - { |
|
167 | - $this->model_tables = $model_tables; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return array |
|
173 | - * @throws InvalidArgumentException |
|
174 | - * @throws InvalidDataTypeException |
|
175 | - * @throws InvalidInterfaceException |
|
176 | - */ |
|
177 | - public function taxonomies() |
|
178 | - { |
|
179 | - if (empty($this->taxonomies)) { |
|
180 | - $this->initializeTaxonomies(); |
|
181 | - } |
|
182 | - return $this->taxonomies; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param array $taxonomies |
|
188 | - */ |
|
189 | - protected function setTaxonomies(array $taxonomies) |
|
190 | - { |
|
191 | - $this->taxonomies = $taxonomies; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @return EE_Secondary_Table |
|
197 | - */ |
|
198 | - public function metaTable() |
|
199 | - { |
|
200 | - return $this->meta_table; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param EE_Secondary_Table $meta_table |
|
206 | - */ |
|
207 | - public function setMetaTable(EE_Secondary_Table $meta_table) |
|
208 | - { |
|
209 | - $this->meta_table = $meta_table; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @return EEM_Base |
|
215 | - */ |
|
216 | - public function model() |
|
217 | - { |
|
218 | - return $this->model; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param EEM_Base $CPT_model |
|
224 | - */ |
|
225 | - protected function setModel(EEM_Base $CPT_model) |
|
226 | - { |
|
227 | - $this->model = $CPT_model; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * @deprecated $VID:$ |
|
233 | - * @return EE_Request_Handler |
|
234 | - */ |
|
235 | - public function request() |
|
236 | - { |
|
237 | - return $this->request_handler; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - |
|
242 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @return WP_Query |
|
247 | - */ |
|
248 | - public function WpQuery() |
|
249 | - { |
|
250 | - return $this->wp_query; |
|
251 | - } |
|
252 | - // phpcs:enable |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param WP_Query $wp_query |
|
257 | - */ |
|
258 | - public function setWpQuery(WP_Query $wp_query) |
|
259 | - { |
|
260 | - $this->wp_query = $wp_query; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @return void |
|
266 | - * @throws InvalidDataTypeException |
|
267 | - * @throws InvalidInterfaceException |
|
268 | - * @throws InvalidArgumentException |
|
269 | - */ |
|
270 | - protected function initializeTaxonomies() |
|
271 | - { |
|
272 | - // check if taxonomies have already been set and that this CPT has taxonomies registered for it |
|
273 | - if (empty($this->taxonomies) |
|
274 | - && isset($this->cpt_details['args']['taxonomies']) |
|
275 | - ) { |
|
276 | - // if so then grab them, but we want the taxonomy name as the key |
|
277 | - $taxonomies = array_flip($this->cpt_details['args']['taxonomies']); |
|
278 | - // then grab the list of ALL taxonomies |
|
279 | - /** @var \EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions |
|
280 | - * $taxonomy_definitions |
|
281 | - */ |
|
282 | - $taxonomy_definitions = $this->loader->getShared( |
|
283 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' |
|
284 | - ); |
|
285 | - $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions(); |
|
286 | - foreach ($taxonomies as $taxonomy => &$details) { |
|
287 | - // add details to our taxonomies if they exist |
|
288 | - $details = isset($all_taxonomies[ $taxonomy ]) |
|
289 | - ? $all_taxonomies[ $taxonomy ] |
|
290 | - : array(); |
|
291 | - } |
|
292 | - // ALWAYS unset() variables that were passed by reference |
|
293 | - unset($details); |
|
294 | - $this->setTaxonomies($taxonomies); |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @since $VID:$ |
|
301 | - * @throws EE_Error |
|
302 | - */ |
|
303 | - protected function init() |
|
304 | - { |
|
305 | - $this->setAdditionalCptDetails(); |
|
306 | - $this->setRequestVarsIfCpt(); |
|
307 | - // convert post_type to model name |
|
308 | - $model_name = str_replace('EE_', '', $this->cpt_details['class_name']); |
|
309 | - // load all tables related to CPT |
|
310 | - $this->setupModelsAndTables($model_name); |
|
311 | - // load and instantiate CPT_*_Strategy |
|
312 | - $CPT_Strategy = $this->cptStrategyClass($model_name); |
|
313 | - // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
|
314 | - // here's the list of available filters in the WP_Query object |
|
315 | - // 'posts_where_paged' |
|
316 | - // 'posts_groupby' |
|
317 | - // 'posts_join_paged' |
|
318 | - // 'posts_orderby' |
|
319 | - // 'posts_distinct' |
|
320 | - // 'post_limits' |
|
321 | - // 'posts_fields' |
|
322 | - // 'posts_join' |
|
323 | - add_filter('posts_fields', array($this, 'postsFields')); |
|
324 | - add_filter('posts_join', array($this, 'postsJoin')); |
|
325 | - add_filter( |
|
326 | - 'get_' . $this->post_type . '_metadata', |
|
327 | - array($CPT_Strategy, 'get_EE_post_type_metadata'), |
|
328 | - 1, |
|
329 | - 4 |
|
330 | - ); |
|
331 | - add_filter('the_posts', array($this, 'thePosts'), 1, 1); |
|
332 | - if ($this->wp_query->is_main_query()) { |
|
333 | - add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2); |
|
334 | - $this->addTemplateFilters(); |
|
335 | - } |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * sets some basic query vars that pertain to the CPT |
|
341 | - * |
|
342 | - * @access protected |
|
343 | - * @return void |
|
344 | - */ |
|
345 | - protected function setAdditionalCptDetails() |
|
346 | - { |
|
347 | - // the post or category or term that is triggering EE |
|
348 | - $this->cpt_details['espresso_page'] = $this->request_handler->is_espresso_page(); |
|
349 | - // requested post name |
|
350 | - $this->cpt_details['post_name'] = $this->request->getRequestParam('post_name'); |
|
351 | - // add support for viewing 'private', 'draft', or 'pending' posts |
|
352 | - if (isset($this->wp_query->query_vars['p']) |
|
353 | - && $this->wp_query->query_vars['p'] !== 0 |
|
354 | - && is_user_logged_in() |
|
355 | - && current_user_can('edit_post', $this->wp_query->query_vars['p']) |
|
356 | - ) { |
|
357 | - // we can just inject directly into the WP_Query object |
|
358 | - $this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending'); |
|
359 | - // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s) |
|
360 | - $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']); |
|
361 | - } |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var. |
|
367 | - * If so, sets the 'ee' request variable |
|
368 | - * so other parts of EE can know what CPT is getting queried. |
|
369 | - * To Mike's knowledge, this must be called from during or after the pre_get_posts hook |
|
370 | - * in order for is_archive() and is_single() methods to work properly. |
|
371 | - * |
|
372 | - * @return void |
|
373 | - */ |
|
374 | - public function setRequestVarsIfCpt() |
|
375 | - { |
|
376 | - // check if ee action var has been set |
|
377 | - if (! $this->request->requestParamIsSet('ee')) { |
|
378 | - // check that route exists for CPT archive slug |
|
379 | - if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) { |
|
380 | - // ie: set "ee" to "events" |
|
381 | - $this->request->setRequestParam('ee', $this->cpt_details['plural_slug']); |
|
382 | - // or does it match a single page CPT like /event/ |
|
383 | - } elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) { |
|
384 | - // ie: set "ee" to "event" |
|
385 | - $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']); |
|
386 | - } |
|
387 | - } |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * setupModelsAndTables |
|
393 | - * |
|
394 | - * @access protected |
|
395 | - * @param string $model_name |
|
396 | - * @throws EE_Error |
|
397 | - */ |
|
398 | - protected function setupModelsAndTables($model_name) |
|
399 | - { |
|
400 | - // get CPT table data via CPT Model |
|
401 | - $full_model_name = strpos($model_name, 'EEM_') !== 0 |
|
402 | - ? 'EEM_' . $model_name |
|
403 | - : $model_name; |
|
404 | - $model = $this->loader->getShared($full_model_name); |
|
405 | - if (! $model instanceof EEM_Base) { |
|
406 | - throw new EE_Error( |
|
407 | - sprintf( |
|
408 | - __( |
|
409 | - 'The "%1$s" model could not be loaded.', |
|
410 | - 'event_espresso' |
|
411 | - ), |
|
412 | - $full_model_name |
|
413 | - ) |
|
414 | - ); |
|
415 | - } |
|
416 | - $this->setModel($model); |
|
417 | - $this->setModelTables($this->model->get_tables()); |
|
418 | - $meta_model = $model_name . '_Meta'; |
|
419 | - // is there a Meta Table for this CPT? |
|
420 | - if (isset($this->cpt_details['tables'][ $meta_model ]) |
|
421 | - && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table |
|
422 | - ) { |
|
423 | - $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]); |
|
424 | - } |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * cptStrategyClass |
|
430 | - * |
|
431 | - * @access protected |
|
432 | - * @param string $model_name |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - protected function cptStrategyClass($model_name) |
|
436 | - { |
|
437 | - // creates classname like: CPT_Event_Strategy |
|
438 | - $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy'; |
|
439 | - // load and instantiate |
|
440 | - $CPT_Strategy = $this->loader->getShared( |
|
441 | - $CPT_Strategy_class_name, |
|
442 | - array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details) |
|
443 | - ); |
|
444 | - if ($CPT_Strategy === null) { |
|
445 | - $CPT_Strategy = $this->loader->getShared( |
|
446 | - 'EE_CPT_Default_Strategy', |
|
447 | - array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details) |
|
448 | - ); |
|
449 | - } |
|
450 | - return $CPT_Strategy; |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * postsFields |
|
456 | - * |
|
457 | - * @access public |
|
458 | - * @param $SQL |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public function postsFields($SQL) |
|
462 | - { |
|
463 | - // does this CPT have a meta table ? |
|
464 | - if ($this->meta_table instanceof EE_Secondary_Table) { |
|
465 | - // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement |
|
466 | - $SQL .= ', ' . $this->meta_table->get_table_name() . '.* '; |
|
467 | - } |
|
468 | - remove_filter('posts_fields', array($this, 'postsFields')); |
|
469 | - return $SQL; |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * postsJoin |
|
475 | - * |
|
476 | - * @access public |
|
477 | - * @param $SQL |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public function postsJoin($SQL) |
|
481 | - { |
|
482 | - // does this CPT have a meta table ? |
|
483 | - if ($this->meta_table instanceof EE_Secondary_Table) { |
|
484 | - global $wpdb; |
|
485 | - // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement |
|
486 | - $SQL .= ' LEFT JOIN ' |
|
487 | - . $this->meta_table->get_table_name() |
|
488 | - . ' ON ( ' |
|
489 | - . $this->meta_table->get_table_name() |
|
490 | - . '.' |
|
491 | - . $this->meta_table->get_fk_on_table() |
|
492 | - . ' = ' |
|
493 | - . $wpdb->posts |
|
494 | - . '.ID ) '; |
|
495 | - } |
|
496 | - remove_filter('posts_join', array($this, 'postsJoin')); |
|
497 | - return $SQL; |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * thePosts |
|
503 | - * |
|
504 | - * @access public |
|
505 | - * @param WP_Post[] $posts |
|
506 | - * @return WP_Post[] |
|
507 | - */ |
|
508 | - public function thePosts($posts) |
|
509 | - { |
|
510 | - $CPT_class = $this->cpt_details['class_name']; |
|
511 | - // loop thru posts |
|
512 | - if (is_array($posts) && $this->model instanceof EEM_CPT_Base) { |
|
513 | - foreach ($posts as $key => $post) { |
|
514 | - if ($post->post_type === $this->post_type) { |
|
515 | - $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post); |
|
516 | - } |
|
517 | - } |
|
518 | - } |
|
519 | - remove_filter('the_posts', array($this, 'thePosts'), 1); |
|
520 | - return $posts; |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * @param $url |
|
526 | - * @param $ID |
|
527 | - * @return string |
|
528 | - */ |
|
529 | - public function getEditPostLink($url, $ID) |
|
530 | - { |
|
531 | - // need to make sure we only edit links if our cpt |
|
532 | - global $post; |
|
533 | - // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui |
|
534 | - // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin. |
|
535 | - if (! $post instanceof WP_Post |
|
536 | - || $post->post_type !== $this->post_type |
|
537 | - || ( |
|
538 | - isset($this->cpt_details['args']['show_ee_ui']) |
|
539 | - && ! $this->cpt_details['args']['show_ee_ui'] |
|
540 | - ) |
|
541 | - ) { |
|
542 | - return $url; |
|
543 | - } |
|
544 | - // k made it here so all is good. |
|
545 | - return wp_nonce_url( |
|
546 | - add_query_arg( |
|
547 | - array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'), |
|
548 | - admin_url('admin.php') |
|
549 | - ), |
|
550 | - 'edit', |
|
551 | - 'edit_nonce' |
|
552 | - ); |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * Execute any template filters. |
|
558 | - * This method is only called if in main query. |
|
559 | - * |
|
560 | - * @return void |
|
561 | - */ |
|
562 | - public function addTemplateFilters() |
|
563 | - { |
|
564 | - // if requested cpt supports page_templates and it's the main query |
|
565 | - if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) { |
|
566 | - // then let's hook into the appropriate query_template hook |
|
567 | - add_filter('single_template', array($this, 'singleCptTemplate')); |
|
568 | - } |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * Callback for single_template wp filter. |
|
574 | - * This is used to load the set page_template for a single ee cpt if its set. If "default" then we load the normal |
|
575 | - * hierarchy. |
|
576 | - * |
|
577 | - * @access public |
|
578 | - * @param string $current_template Existing default template path derived for this page call. |
|
579 | - * @return string the path to the full template file. |
|
580 | - */ |
|
581 | - public function singleCptTemplate($current_template) |
|
582 | - { |
|
583 | - $object = get_queried_object(); |
|
584 | - // does this called object HAVE a page template set that is something other than the default. |
|
585 | - $template = get_post_meta($object->ID, '_wp_page_template', true); |
|
586 | - // exit early if default or not set or invalid path (accounts for theme changes) |
|
587 | - if ($template === 'default' |
|
588 | - || empty($template) |
|
589 | - || ! is_readable(get_stylesheet_directory() . '/' . $template) |
|
590 | - ) { |
|
591 | - return $current_template; |
|
592 | - } |
|
593 | - // made it here so we SHOULD be able to just locate the template and then return it. |
|
594 | - return locate_template(array($template)); |
|
595 | - } |
|
31 | + /** |
|
32 | + * @var string $post_type |
|
33 | + */ |
|
34 | + protected $post_type = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * CPT details from CustomPostTypeDefinitions for specific post type |
|
38 | + * |
|
39 | + * @var array $cpt_details |
|
40 | + */ |
|
41 | + protected $cpt_details = array(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EE_Table_Base[] $model_tables |
|
45 | + */ |
|
46 | + protected $model_tables = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array $taxonomies |
|
50 | + */ |
|
51 | + protected $taxonomies = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * meta table for the related CPT |
|
55 | + * |
|
56 | + * @var EE_Secondary_Table $meta_table |
|
57 | + */ |
|
58 | + protected $meta_table; |
|
59 | + |
|
60 | + /** |
|
61 | + * EEM_CPT_Base model for the related CPT |
|
62 | + * |
|
63 | + * @var EEM_CPT_Base $model |
|
64 | + */ |
|
65 | + protected $model; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var EE_Request_Handler $request_handler |
|
69 | + */ |
|
70 | + protected $request_handler; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var WP_Query $wp_query |
|
74 | + */ |
|
75 | + protected $wp_query; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var LoaderInterface $loader |
|
79 | + */ |
|
80 | + protected $loader; |
|
81 | + |
|
82 | + /** |
|
83 | + * @var RequestInterface $request |
|
84 | + */ |
|
85 | + protected $request; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * CptQueryModifier constructor |
|
90 | + * |
|
91 | + * @param string $post_type |
|
92 | + * @param array $cpt_details |
|
93 | + * @param WP_Query $WP_Query |
|
94 | + * @param EE_Request_Handler $request_handler |
|
95 | + * @param RequestInterface $request |
|
96 | + * @param LoaderInterface $loader |
|
97 | + * @throws EE_Error |
|
98 | + */ |
|
99 | + public function __construct( |
|
100 | + $post_type, |
|
101 | + array $cpt_details, |
|
102 | + WP_Query $WP_Query, |
|
103 | + EE_Request_Handler $request_handler, |
|
104 | + RequestInterface $request, |
|
105 | + LoaderInterface $loader |
|
106 | + ) { |
|
107 | + $this->loader = $loader; |
|
108 | + $this->request = $request; |
|
109 | + $this->request_handler = $request_handler; |
|
110 | + $this->setWpQuery($WP_Query); |
|
111 | + $this->setPostType($post_type); |
|
112 | + $this->setCptDetails($cpt_details); |
|
113 | + $this->init(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function postType() |
|
121 | + { |
|
122 | + return $this->post_type; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $post_type |
|
128 | + */ |
|
129 | + protected function setPostType($post_type) |
|
130 | + { |
|
131 | + $this->post_type = $post_type; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @return array |
|
137 | + */ |
|
138 | + public function cptDetails() |
|
139 | + { |
|
140 | + return $this->cpt_details; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param array $cpt_details |
|
146 | + */ |
|
147 | + protected function setCptDetails($cpt_details) |
|
148 | + { |
|
149 | + $this->cpt_details = $cpt_details; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @return EE_Table_Base[] |
|
155 | + */ |
|
156 | + public function modelTables() |
|
157 | + { |
|
158 | + return $this->model_tables; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param EE_Table_Base[] $model_tables |
|
164 | + */ |
|
165 | + protected function setModelTables($model_tables) |
|
166 | + { |
|
167 | + $this->model_tables = $model_tables; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return array |
|
173 | + * @throws InvalidArgumentException |
|
174 | + * @throws InvalidDataTypeException |
|
175 | + * @throws InvalidInterfaceException |
|
176 | + */ |
|
177 | + public function taxonomies() |
|
178 | + { |
|
179 | + if (empty($this->taxonomies)) { |
|
180 | + $this->initializeTaxonomies(); |
|
181 | + } |
|
182 | + return $this->taxonomies; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param array $taxonomies |
|
188 | + */ |
|
189 | + protected function setTaxonomies(array $taxonomies) |
|
190 | + { |
|
191 | + $this->taxonomies = $taxonomies; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @return EE_Secondary_Table |
|
197 | + */ |
|
198 | + public function metaTable() |
|
199 | + { |
|
200 | + return $this->meta_table; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param EE_Secondary_Table $meta_table |
|
206 | + */ |
|
207 | + public function setMetaTable(EE_Secondary_Table $meta_table) |
|
208 | + { |
|
209 | + $this->meta_table = $meta_table; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @return EEM_Base |
|
215 | + */ |
|
216 | + public function model() |
|
217 | + { |
|
218 | + return $this->model; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param EEM_Base $CPT_model |
|
224 | + */ |
|
225 | + protected function setModel(EEM_Base $CPT_model) |
|
226 | + { |
|
227 | + $this->model = $CPT_model; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * @deprecated $VID:$ |
|
233 | + * @return EE_Request_Handler |
|
234 | + */ |
|
235 | + public function request() |
|
236 | + { |
|
237 | + return $this->request_handler; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + |
|
242 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @return WP_Query |
|
247 | + */ |
|
248 | + public function WpQuery() |
|
249 | + { |
|
250 | + return $this->wp_query; |
|
251 | + } |
|
252 | + // phpcs:enable |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param WP_Query $wp_query |
|
257 | + */ |
|
258 | + public function setWpQuery(WP_Query $wp_query) |
|
259 | + { |
|
260 | + $this->wp_query = $wp_query; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @return void |
|
266 | + * @throws InvalidDataTypeException |
|
267 | + * @throws InvalidInterfaceException |
|
268 | + * @throws InvalidArgumentException |
|
269 | + */ |
|
270 | + protected function initializeTaxonomies() |
|
271 | + { |
|
272 | + // check if taxonomies have already been set and that this CPT has taxonomies registered for it |
|
273 | + if (empty($this->taxonomies) |
|
274 | + && isset($this->cpt_details['args']['taxonomies']) |
|
275 | + ) { |
|
276 | + // if so then grab them, but we want the taxonomy name as the key |
|
277 | + $taxonomies = array_flip($this->cpt_details['args']['taxonomies']); |
|
278 | + // then grab the list of ALL taxonomies |
|
279 | + /** @var \EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions |
|
280 | + * $taxonomy_definitions |
|
281 | + */ |
|
282 | + $taxonomy_definitions = $this->loader->getShared( |
|
283 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' |
|
284 | + ); |
|
285 | + $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions(); |
|
286 | + foreach ($taxonomies as $taxonomy => &$details) { |
|
287 | + // add details to our taxonomies if they exist |
|
288 | + $details = isset($all_taxonomies[ $taxonomy ]) |
|
289 | + ? $all_taxonomies[ $taxonomy ] |
|
290 | + : array(); |
|
291 | + } |
|
292 | + // ALWAYS unset() variables that were passed by reference |
|
293 | + unset($details); |
|
294 | + $this->setTaxonomies($taxonomies); |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @since $VID:$ |
|
301 | + * @throws EE_Error |
|
302 | + */ |
|
303 | + protected function init() |
|
304 | + { |
|
305 | + $this->setAdditionalCptDetails(); |
|
306 | + $this->setRequestVarsIfCpt(); |
|
307 | + // convert post_type to model name |
|
308 | + $model_name = str_replace('EE_', '', $this->cpt_details['class_name']); |
|
309 | + // load all tables related to CPT |
|
310 | + $this->setupModelsAndTables($model_name); |
|
311 | + // load and instantiate CPT_*_Strategy |
|
312 | + $CPT_Strategy = $this->cptStrategyClass($model_name); |
|
313 | + // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
|
314 | + // here's the list of available filters in the WP_Query object |
|
315 | + // 'posts_where_paged' |
|
316 | + // 'posts_groupby' |
|
317 | + // 'posts_join_paged' |
|
318 | + // 'posts_orderby' |
|
319 | + // 'posts_distinct' |
|
320 | + // 'post_limits' |
|
321 | + // 'posts_fields' |
|
322 | + // 'posts_join' |
|
323 | + add_filter('posts_fields', array($this, 'postsFields')); |
|
324 | + add_filter('posts_join', array($this, 'postsJoin')); |
|
325 | + add_filter( |
|
326 | + 'get_' . $this->post_type . '_metadata', |
|
327 | + array($CPT_Strategy, 'get_EE_post_type_metadata'), |
|
328 | + 1, |
|
329 | + 4 |
|
330 | + ); |
|
331 | + add_filter('the_posts', array($this, 'thePosts'), 1, 1); |
|
332 | + if ($this->wp_query->is_main_query()) { |
|
333 | + add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2); |
|
334 | + $this->addTemplateFilters(); |
|
335 | + } |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * sets some basic query vars that pertain to the CPT |
|
341 | + * |
|
342 | + * @access protected |
|
343 | + * @return void |
|
344 | + */ |
|
345 | + protected function setAdditionalCptDetails() |
|
346 | + { |
|
347 | + // the post or category or term that is triggering EE |
|
348 | + $this->cpt_details['espresso_page'] = $this->request_handler->is_espresso_page(); |
|
349 | + // requested post name |
|
350 | + $this->cpt_details['post_name'] = $this->request->getRequestParam('post_name'); |
|
351 | + // add support for viewing 'private', 'draft', or 'pending' posts |
|
352 | + if (isset($this->wp_query->query_vars['p']) |
|
353 | + && $this->wp_query->query_vars['p'] !== 0 |
|
354 | + && is_user_logged_in() |
|
355 | + && current_user_can('edit_post', $this->wp_query->query_vars['p']) |
|
356 | + ) { |
|
357 | + // we can just inject directly into the WP_Query object |
|
358 | + $this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending'); |
|
359 | + // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s) |
|
360 | + $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']); |
|
361 | + } |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var. |
|
367 | + * If so, sets the 'ee' request variable |
|
368 | + * so other parts of EE can know what CPT is getting queried. |
|
369 | + * To Mike's knowledge, this must be called from during or after the pre_get_posts hook |
|
370 | + * in order for is_archive() and is_single() methods to work properly. |
|
371 | + * |
|
372 | + * @return void |
|
373 | + */ |
|
374 | + public function setRequestVarsIfCpt() |
|
375 | + { |
|
376 | + // check if ee action var has been set |
|
377 | + if (! $this->request->requestParamIsSet('ee')) { |
|
378 | + // check that route exists for CPT archive slug |
|
379 | + if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) { |
|
380 | + // ie: set "ee" to "events" |
|
381 | + $this->request->setRequestParam('ee', $this->cpt_details['plural_slug']); |
|
382 | + // or does it match a single page CPT like /event/ |
|
383 | + } elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) { |
|
384 | + // ie: set "ee" to "event" |
|
385 | + $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']); |
|
386 | + } |
|
387 | + } |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * setupModelsAndTables |
|
393 | + * |
|
394 | + * @access protected |
|
395 | + * @param string $model_name |
|
396 | + * @throws EE_Error |
|
397 | + */ |
|
398 | + protected function setupModelsAndTables($model_name) |
|
399 | + { |
|
400 | + // get CPT table data via CPT Model |
|
401 | + $full_model_name = strpos($model_name, 'EEM_') !== 0 |
|
402 | + ? 'EEM_' . $model_name |
|
403 | + : $model_name; |
|
404 | + $model = $this->loader->getShared($full_model_name); |
|
405 | + if (! $model instanceof EEM_Base) { |
|
406 | + throw new EE_Error( |
|
407 | + sprintf( |
|
408 | + __( |
|
409 | + 'The "%1$s" model could not be loaded.', |
|
410 | + 'event_espresso' |
|
411 | + ), |
|
412 | + $full_model_name |
|
413 | + ) |
|
414 | + ); |
|
415 | + } |
|
416 | + $this->setModel($model); |
|
417 | + $this->setModelTables($this->model->get_tables()); |
|
418 | + $meta_model = $model_name . '_Meta'; |
|
419 | + // is there a Meta Table for this CPT? |
|
420 | + if (isset($this->cpt_details['tables'][ $meta_model ]) |
|
421 | + && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table |
|
422 | + ) { |
|
423 | + $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]); |
|
424 | + } |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * cptStrategyClass |
|
430 | + * |
|
431 | + * @access protected |
|
432 | + * @param string $model_name |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + protected function cptStrategyClass($model_name) |
|
436 | + { |
|
437 | + // creates classname like: CPT_Event_Strategy |
|
438 | + $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy'; |
|
439 | + // load and instantiate |
|
440 | + $CPT_Strategy = $this->loader->getShared( |
|
441 | + $CPT_Strategy_class_name, |
|
442 | + array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details) |
|
443 | + ); |
|
444 | + if ($CPT_Strategy === null) { |
|
445 | + $CPT_Strategy = $this->loader->getShared( |
|
446 | + 'EE_CPT_Default_Strategy', |
|
447 | + array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details) |
|
448 | + ); |
|
449 | + } |
|
450 | + return $CPT_Strategy; |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * postsFields |
|
456 | + * |
|
457 | + * @access public |
|
458 | + * @param $SQL |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public function postsFields($SQL) |
|
462 | + { |
|
463 | + // does this CPT have a meta table ? |
|
464 | + if ($this->meta_table instanceof EE_Secondary_Table) { |
|
465 | + // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement |
|
466 | + $SQL .= ', ' . $this->meta_table->get_table_name() . '.* '; |
|
467 | + } |
|
468 | + remove_filter('posts_fields', array($this, 'postsFields')); |
|
469 | + return $SQL; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * postsJoin |
|
475 | + * |
|
476 | + * @access public |
|
477 | + * @param $SQL |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public function postsJoin($SQL) |
|
481 | + { |
|
482 | + // does this CPT have a meta table ? |
|
483 | + if ($this->meta_table instanceof EE_Secondary_Table) { |
|
484 | + global $wpdb; |
|
485 | + // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement |
|
486 | + $SQL .= ' LEFT JOIN ' |
|
487 | + . $this->meta_table->get_table_name() |
|
488 | + . ' ON ( ' |
|
489 | + . $this->meta_table->get_table_name() |
|
490 | + . '.' |
|
491 | + . $this->meta_table->get_fk_on_table() |
|
492 | + . ' = ' |
|
493 | + . $wpdb->posts |
|
494 | + . '.ID ) '; |
|
495 | + } |
|
496 | + remove_filter('posts_join', array($this, 'postsJoin')); |
|
497 | + return $SQL; |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * thePosts |
|
503 | + * |
|
504 | + * @access public |
|
505 | + * @param WP_Post[] $posts |
|
506 | + * @return WP_Post[] |
|
507 | + */ |
|
508 | + public function thePosts($posts) |
|
509 | + { |
|
510 | + $CPT_class = $this->cpt_details['class_name']; |
|
511 | + // loop thru posts |
|
512 | + if (is_array($posts) && $this->model instanceof EEM_CPT_Base) { |
|
513 | + foreach ($posts as $key => $post) { |
|
514 | + if ($post->post_type === $this->post_type) { |
|
515 | + $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post); |
|
516 | + } |
|
517 | + } |
|
518 | + } |
|
519 | + remove_filter('the_posts', array($this, 'thePosts'), 1); |
|
520 | + return $posts; |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * @param $url |
|
526 | + * @param $ID |
|
527 | + * @return string |
|
528 | + */ |
|
529 | + public function getEditPostLink($url, $ID) |
|
530 | + { |
|
531 | + // need to make sure we only edit links if our cpt |
|
532 | + global $post; |
|
533 | + // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui |
|
534 | + // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin. |
|
535 | + if (! $post instanceof WP_Post |
|
536 | + || $post->post_type !== $this->post_type |
|
537 | + || ( |
|
538 | + isset($this->cpt_details['args']['show_ee_ui']) |
|
539 | + && ! $this->cpt_details['args']['show_ee_ui'] |
|
540 | + ) |
|
541 | + ) { |
|
542 | + return $url; |
|
543 | + } |
|
544 | + // k made it here so all is good. |
|
545 | + return wp_nonce_url( |
|
546 | + add_query_arg( |
|
547 | + array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'), |
|
548 | + admin_url('admin.php') |
|
549 | + ), |
|
550 | + 'edit', |
|
551 | + 'edit_nonce' |
|
552 | + ); |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * Execute any template filters. |
|
558 | + * This method is only called if in main query. |
|
559 | + * |
|
560 | + * @return void |
|
561 | + */ |
|
562 | + public function addTemplateFilters() |
|
563 | + { |
|
564 | + // if requested cpt supports page_templates and it's the main query |
|
565 | + if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) { |
|
566 | + // then let's hook into the appropriate query_template hook |
|
567 | + add_filter('single_template', array($this, 'singleCptTemplate')); |
|
568 | + } |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * Callback for single_template wp filter. |
|
574 | + * This is used to load the set page_template for a single ee cpt if its set. If "default" then we load the normal |
|
575 | + * hierarchy. |
|
576 | + * |
|
577 | + * @access public |
|
578 | + * @param string $current_template Existing default template path derived for this page call. |
|
579 | + * @return string the path to the full template file. |
|
580 | + */ |
|
581 | + public function singleCptTemplate($current_template) |
|
582 | + { |
|
583 | + $object = get_queried_object(); |
|
584 | + // does this called object HAVE a page template set that is something other than the default. |
|
585 | + $template = get_post_meta($object->ID, '_wp_page_template', true); |
|
586 | + // exit early if default or not set or invalid path (accounts for theme changes) |
|
587 | + if ($template === 'default' |
|
588 | + || empty($template) |
|
589 | + || ! is_readable(get_stylesheet_directory() . '/' . $template) |
|
590 | + ) { |
|
591 | + return $current_template; |
|
592 | + } |
|
593 | + // made it here so we SHOULD be able to just locate the template and then return it. |
|
594 | + return locate_template(array($template)); |
|
595 | + } |
|
596 | 596 | } |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions(); |
286 | 286 | foreach ($taxonomies as $taxonomy => &$details) { |
287 | 287 | // add details to our taxonomies if they exist |
288 | - $details = isset($all_taxonomies[ $taxonomy ]) |
|
289 | - ? $all_taxonomies[ $taxonomy ] |
|
288 | + $details = isset($all_taxonomies[$taxonomy]) |
|
289 | + ? $all_taxonomies[$taxonomy] |
|
290 | 290 | : array(); |
291 | 291 | } |
292 | 292 | // ALWAYS unset() variables that were passed by reference |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | add_filter('posts_fields', array($this, 'postsFields')); |
324 | 324 | add_filter('posts_join', array($this, 'postsJoin')); |
325 | 325 | add_filter( |
326 | - 'get_' . $this->post_type . '_metadata', |
|
326 | + 'get_'.$this->post_type.'_metadata', |
|
327 | 327 | array($CPT_Strategy, 'get_EE_post_type_metadata'), |
328 | 328 | 1, |
329 | 329 | 4 |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | public function setRequestVarsIfCpt() |
375 | 375 | { |
376 | 376 | // check if ee action var has been set |
377 | - if (! $this->request->requestParamIsSet('ee')) { |
|
377 | + if ( ! $this->request->requestParamIsSet('ee')) { |
|
378 | 378 | // check that route exists for CPT archive slug |
379 | 379 | if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) { |
380 | 380 | // ie: set "ee" to "events" |
@@ -399,10 +399,10 @@ discard block |
||
399 | 399 | { |
400 | 400 | // get CPT table data via CPT Model |
401 | 401 | $full_model_name = strpos($model_name, 'EEM_') !== 0 |
402 | - ? 'EEM_' . $model_name |
|
402 | + ? 'EEM_'.$model_name |
|
403 | 403 | : $model_name; |
404 | 404 | $model = $this->loader->getShared($full_model_name); |
405 | - if (! $model instanceof EEM_Base) { |
|
405 | + if ( ! $model instanceof EEM_Base) { |
|
406 | 406 | throw new EE_Error( |
407 | 407 | sprintf( |
408 | 408 | __( |
@@ -415,12 +415,12 @@ discard block |
||
415 | 415 | } |
416 | 416 | $this->setModel($model); |
417 | 417 | $this->setModelTables($this->model->get_tables()); |
418 | - $meta_model = $model_name . '_Meta'; |
|
418 | + $meta_model = $model_name.'_Meta'; |
|
419 | 419 | // is there a Meta Table for this CPT? |
420 | - if (isset($this->cpt_details['tables'][ $meta_model ]) |
|
421 | - && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table |
|
420 | + if (isset($this->cpt_details['tables'][$meta_model]) |
|
421 | + && $this->cpt_details['tables'][$meta_model] instanceof EE_Secondary_Table |
|
422 | 422 | ) { |
423 | - $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]); |
|
423 | + $this->setMetaTable($this->cpt_details['tables'][$meta_model]); |
|
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | protected function cptStrategyClass($model_name) |
436 | 436 | { |
437 | 437 | // creates classname like: CPT_Event_Strategy |
438 | - $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy'; |
|
438 | + $CPT_Strategy_class_name = 'EE_CPT_'.$model_name.'_Strategy'; |
|
439 | 439 | // load and instantiate |
440 | 440 | $CPT_Strategy = $this->loader->getShared( |
441 | 441 | $CPT_Strategy_class_name, |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | // does this CPT have a meta table ? |
464 | 464 | if ($this->meta_table instanceof EE_Secondary_Table) { |
465 | 465 | // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement |
466 | - $SQL .= ', ' . $this->meta_table->get_table_name() . '.* '; |
|
466 | + $SQL .= ', '.$this->meta_table->get_table_name().'.* '; |
|
467 | 467 | } |
468 | 468 | remove_filter('posts_fields', array($this, 'postsFields')); |
469 | 469 | return $SQL; |
@@ -532,7 +532,7 @@ discard block |
||
532 | 532 | global $post; |
533 | 533 | // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui |
534 | 534 | // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin. |
535 | - if (! $post instanceof WP_Post |
|
535 | + if ( ! $post instanceof WP_Post |
|
536 | 536 | || $post->post_type !== $this->post_type |
537 | 537 | || ( |
538 | 538 | isset($this->cpt_details['args']['show_ee_ui']) |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | public function addTemplateFilters() |
563 | 563 | { |
564 | 564 | // if requested cpt supports page_templates and it's the main query |
565 | - if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) { |
|
565 | + if ( ! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) { |
|
566 | 566 | // then let's hook into the appropriate query_template hook |
567 | 567 | add_filter('single_template', array($this, 'singleCptTemplate')); |
568 | 568 | } |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | // exit early if default or not set or invalid path (accounts for theme changes) |
587 | 587 | if ($template === 'default' |
588 | 588 | || empty($template) |
589 | - || ! is_readable(get_stylesheet_directory() . '/' . $template) |
|
589 | + || ! is_readable(get_stylesheet_directory().'/'.$template) |
|
590 | 590 | ) { |
591 | 591 | return $current_template; |
592 | 592 | } |
@@ -16,449 +16,449 @@ |
||
16 | 16 | class EE_CPT_Strategy extends EE_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var EE_CPT_Strategy $_instance |
|
21 | - */ |
|
22 | - private static $_instance; |
|
23 | - |
|
24 | - /** |
|
25 | - * the current page, if it utilizes CPTs |
|
26 | - * |
|
27 | - * @var array $CPT |
|
28 | - */ |
|
29 | - protected $CPT; |
|
30 | - |
|
31 | - /** |
|
32 | - * return value from CustomPostTypeDefinitions::getDefinitions() |
|
33 | - * |
|
34 | - * @var array $_CPTs |
|
35 | - */ |
|
36 | - protected $_CPTs = array(); |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array $_CPT_taxonomies |
|
40 | - */ |
|
41 | - protected $_CPT_taxonomies = array(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @var array $_CPT_terms |
|
45 | - */ |
|
46 | - protected $_CPT_terms = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array $_CPT_endpoints |
|
50 | - */ |
|
51 | - protected $_CPT_endpoints = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * @var EEM_Base $CPT_model |
|
55 | - */ |
|
56 | - protected $CPT_model; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
60 | - */ |
|
61 | - protected $query_modifier; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @singleton method used to instantiate class object |
|
66 | - * @param CustomPostTypeDefinitions|null $custom_post_types |
|
67 | - * @param CustomTaxonomyDefinitions|null $taxonomies |
|
68 | - * @return EE_CPT_Strategy |
|
69 | - */ |
|
70 | - public static function instance( |
|
71 | - CustomPostTypeDefinitions $custom_post_types = null, |
|
72 | - CustomTaxonomyDefinitions $taxonomies = null |
|
73 | - ) { |
|
74 | - // check if class object is instantiated |
|
75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
76 | - && $custom_post_types instanceof CustomPostTypeDefinitions |
|
77 | - && $taxonomies instanceof CustomTaxonomyDefinitions |
|
78 | - ) { |
|
79 | - self::$_instance = new self($custom_post_types, $taxonomies); |
|
80 | - } |
|
81 | - return self::$_instance; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
87 | - * @param CustomTaxonomyDefinitions $taxonomies |
|
88 | - */ |
|
89 | - protected function __construct( |
|
90 | - CustomPostTypeDefinitions $custom_post_types, |
|
91 | - CustomTaxonomyDefinitions $taxonomies |
|
92 | - ) { |
|
93 | - // get CPT data |
|
94 | - $this->_CPTs = $custom_post_types->getDefinitions(); |
|
95 | - $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
96 | - $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
97 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function get_CPT_endpoints() |
|
105 | - { |
|
106 | - return $this->_CPT_endpoints; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public function get_CPT_taxonomies() |
|
114 | - { |
|
115 | - return $this->_CPT_taxonomies; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * add CPT "slugs" to array of default espresso "pages" |
|
121 | - * |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - private function _set_CPT_endpoints() |
|
125 | - { |
|
126 | - $_CPT_endpoints = array(); |
|
127 | - if (is_array($this->_CPTs)) { |
|
128 | - foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
129 | - $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
130 | - } |
|
131 | - } |
|
132 | - return $_CPT_endpoints; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
138 | - * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
139 | - * adding EE objects to the post to facilitate further querying of related data etc) |
|
140 | - * |
|
141 | - * @param WP_Query $WP_Query |
|
142 | - * @return void |
|
143 | - * @throws \EE_Error |
|
144 | - * @throws \InvalidArgumentException |
|
145 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
146 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
147 | - */ |
|
148 | - public function pre_get_posts($WP_Query) |
|
149 | - { |
|
150 | - // check that post-type is set |
|
151 | - if (! $WP_Query instanceof WP_Query) { |
|
152 | - return; |
|
153 | - } |
|
154 | - // add our conditionals |
|
155 | - $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
156 | - // check for terms |
|
157 | - $this->_set_post_type_for_terms($WP_Query); |
|
158 | - // make sure paging is always set |
|
159 | - $this->_set_paging($WP_Query); |
|
160 | - // is a taxonomy set ? |
|
161 | - $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
162 | - // loop thru post_types if set |
|
163 | - $this->_process_WP_Query_post_types($WP_Query); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @param WP_Query $WP_Query |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
172 | - { |
|
173 | - $WP_Query->is_espresso_event_single = false; |
|
174 | - $WP_Query->is_espresso_event_archive = false; |
|
175 | - $WP_Query->is_espresso_event_taxonomy = false; |
|
176 | - $WP_Query->is_espresso_venue_single = false; |
|
177 | - $WP_Query->is_espresso_venue_archive = false; |
|
178 | - $WP_Query->is_espresso_venue_taxonomy = false; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @return void |
|
184 | - * @throws EE_Error |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws InvalidDataTypeException |
|
187 | - * @throws InvalidInterfaceException |
|
188 | - */ |
|
189 | - private function _set_CPT_terms() |
|
190 | - { |
|
191 | - if (empty($this->_CPT_terms)) { |
|
192 | - $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
193 | - foreach ($terms as $term) { |
|
194 | - if ($term instanceof EE_Term) { |
|
195 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param WP_Query $WP_Query |
|
204 | - * @return void |
|
205 | - * @throws EE_Error |
|
206 | - * @throws InvalidArgumentException |
|
207 | - * @throws InvalidDataTypeException |
|
208 | - * @throws InvalidInterfaceException |
|
209 | - */ |
|
210 | - private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
211 | - { |
|
212 | - // is a tag set ? |
|
213 | - if (isset($WP_Query->query['tag'])) { |
|
214 | - // set post_tags |
|
215 | - $this->_set_CPT_terms(); |
|
216 | - // is this tag archive term in the list of terms used by our CPTs ? |
|
217 | - $term = isset($this->_CPT_terms[ $WP_Query->query['tag'] ]) |
|
218 | - ? $this->_CPT_terms[ $WP_Query->query['tag'] ] |
|
219 | - : null; |
|
220 | - // verify the term |
|
221 | - if ($term instanceof EE_Term) { |
|
222 | - $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
223 | - $term->post_type = apply_filters( |
|
224 | - 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
225 | - $term->post_type, |
|
226 | - $term |
|
227 | - ); |
|
228 | - // if a post type is already set |
|
229 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
230 | - // add to existing array |
|
231 | - $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
232 | - } |
|
233 | - // just set post_type to our CPT |
|
234 | - $WP_Query->set('post_type', array_unique($term->post_type)); |
|
235 | - } |
|
236 | - } |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @param WP_Query $WP_Query |
|
242 | - * @return void |
|
243 | - */ |
|
244 | - public function _set_paging($WP_Query) |
|
245 | - { |
|
246 | - if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
247 | - $page = get_query_var('page') ? get_query_var('page') : null; |
|
248 | - $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
249 | - $WP_Query->set('paged', $paged); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param \WP_Query $WP_Query |
|
256 | - */ |
|
257 | - protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
258 | - { |
|
259 | - // is a taxonomy set ? |
|
260 | - if ($WP_Query->is_tax) { |
|
261 | - // loop thru our taxonomies |
|
262 | - foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
263 | - // check if one of our taxonomies is set as a query var |
|
264 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
265 | - // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
266 | - foreach ($this->_CPTs as $post_type => $CPT) { |
|
267 | - // verify our CPT has args, is public and has taxonomies set |
|
268 | - if (isset($CPT['args']['public']) |
|
269 | - && $CPT['args']['public'] |
|
270 | - && ! empty($CPT['args']['taxonomies']) |
|
271 | - && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
272 | - ) { |
|
273 | - // if so, then add this CPT post_type to the current query's array of post_types' |
|
274 | - $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
275 | - ? (array) $WP_Query->query_vars['post_type'] |
|
276 | - : array(); |
|
277 | - $WP_Query->query_vars['post_type'][] = $post_type; |
|
278 | - switch ($post_type) { |
|
279 | - case 'espresso_events': |
|
280 | - $WP_Query->is_espresso_event_taxonomy = true; |
|
281 | - break; |
|
282 | - case 'espresso_venues': |
|
283 | - $WP_Query->is_espresso_venue_taxonomy = true; |
|
284 | - break; |
|
285 | - default: |
|
286 | - do_action( |
|
287 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
288 | - $WP_Query, |
|
289 | - $this |
|
290 | - ); |
|
291 | - } |
|
292 | - } |
|
293 | - } |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * @param \WP_Query $WP_Query |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidDataTypeException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - */ |
|
306 | - protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
307 | - { |
|
308 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
309 | - // loop thru post_types as array |
|
310 | - foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
311 | - // is current query for an EE CPT ? |
|
312 | - if (isset($this->_CPTs[ $post_type ])) { |
|
313 | - // is EE on or off ? |
|
314 | - if (EE_Maintenance_Mode::instance()->level()) { |
|
315 | - // reroute CPT template view to maintenance_mode.template.php |
|
316 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
317 | - add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
318 | - } |
|
319 | - if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
320 | - add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
321 | - } |
|
322 | - return; |
|
323 | - } |
|
324 | - $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
325 | - } |
|
326 | - } |
|
327 | - } |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @param \WP_Query $WP_Query |
|
333 | - * @param string $post_type |
|
334 | - * @throws InvalidArgumentException |
|
335 | - * @throws InvalidDataTypeException |
|
336 | - * @throws InvalidInterfaceException |
|
337 | - */ |
|
338 | - protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
339 | - { |
|
340 | - $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
341 | - 'EventEspresso\core\CPTs\CptQueryModifier', |
|
342 | - array( |
|
343 | - $post_type, |
|
344 | - $this->_CPTs[ $post_type ], |
|
345 | - $WP_Query, |
|
346 | - ) |
|
347 | - ); |
|
348 | - $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * inject_EE_shortcode_placeholder |
|
354 | - * in order to display the M-Mode notice on our CPT routes, |
|
355 | - * we need to first inject what looks like one of our shortcodes, |
|
356 | - * so that it can be replaced with the actual M-Mode notice |
|
357 | - * |
|
358 | - * @return string |
|
359 | - */ |
|
360 | - public function inject_EE_shortcode_placeholder() |
|
361 | - { |
|
362 | - return '[ESPRESSO_'; |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * @deprecated |
|
368 | - * @since 4.8.41 |
|
369 | - * @return void |
|
370 | - */ |
|
371 | - public function _possibly_set_ee_request_var() |
|
372 | - { |
|
373 | - $this->query_modifier->setRequestVarsIfCpt(); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @deprecated |
|
379 | - * @since 4.8.41 |
|
380 | - * @param $SQL |
|
381 | - * @return string |
|
382 | - */ |
|
383 | - public function posts_fields($SQL) |
|
384 | - { |
|
385 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
386 | - return $this->query_modifier->postsFields($SQL); |
|
387 | - } |
|
388 | - return $SQL; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * @deprecated |
|
394 | - * @since 4.8.41 |
|
395 | - * @param $SQL |
|
396 | - * @return string |
|
397 | - */ |
|
398 | - public function posts_join($SQL) |
|
399 | - { |
|
400 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
401 | - return $this->query_modifier->postsJoin($SQL); |
|
402 | - } |
|
403 | - return $SQL; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * @deprecated |
|
409 | - * @since 4.8.41 |
|
410 | - * @param \WP_Post[] $posts |
|
411 | - * @return \WP_Post[] |
|
412 | - */ |
|
413 | - public function the_posts($posts) |
|
414 | - { |
|
415 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
416 | - $this->query_modifier->thePosts($posts); |
|
417 | - } |
|
418 | - return $posts; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @deprecated |
|
424 | - * @since 4.8.41 |
|
425 | - * @param $url |
|
426 | - * @param $ID |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public function get_edit_post_link($url, $ID) |
|
430 | - { |
|
431 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
432 | - return $this->query_modifier->getEditPostLink($url, $ID); |
|
433 | - } |
|
434 | - return ''; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * @deprecated |
|
440 | - * @since 4.8.41 |
|
441 | - * @param null $WP_Query |
|
442 | - */ |
|
443 | - protected function _do_template_filters($WP_Query = null) |
|
444 | - { |
|
445 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
446 | - $this->query_modifier->addTemplateFilters(); |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @deprecated |
|
453 | - * @since 4.8.41 |
|
454 | - * @param string $current_template Existing default template path derived for this page call. |
|
455 | - * @return string the path to the full template file. |
|
456 | - */ |
|
457 | - public function single_cpt_template($current_template) |
|
458 | - { |
|
459 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
460 | - return $this->query_modifier->singleCptTemplate($current_template); |
|
461 | - } |
|
462 | - return $current_template; |
|
463 | - } |
|
19 | + /** |
|
20 | + * @var EE_CPT_Strategy $_instance |
|
21 | + */ |
|
22 | + private static $_instance; |
|
23 | + |
|
24 | + /** |
|
25 | + * the current page, if it utilizes CPTs |
|
26 | + * |
|
27 | + * @var array $CPT |
|
28 | + */ |
|
29 | + protected $CPT; |
|
30 | + |
|
31 | + /** |
|
32 | + * return value from CustomPostTypeDefinitions::getDefinitions() |
|
33 | + * |
|
34 | + * @var array $_CPTs |
|
35 | + */ |
|
36 | + protected $_CPTs = array(); |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array $_CPT_taxonomies |
|
40 | + */ |
|
41 | + protected $_CPT_taxonomies = array(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @var array $_CPT_terms |
|
45 | + */ |
|
46 | + protected $_CPT_terms = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array $_CPT_endpoints |
|
50 | + */ |
|
51 | + protected $_CPT_endpoints = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * @var EEM_Base $CPT_model |
|
55 | + */ |
|
56 | + protected $CPT_model; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
60 | + */ |
|
61 | + protected $query_modifier; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @singleton method used to instantiate class object |
|
66 | + * @param CustomPostTypeDefinitions|null $custom_post_types |
|
67 | + * @param CustomTaxonomyDefinitions|null $taxonomies |
|
68 | + * @return EE_CPT_Strategy |
|
69 | + */ |
|
70 | + public static function instance( |
|
71 | + CustomPostTypeDefinitions $custom_post_types = null, |
|
72 | + CustomTaxonomyDefinitions $taxonomies = null |
|
73 | + ) { |
|
74 | + // check if class object is instantiated |
|
75 | + if (! self::$_instance instanceof EE_CPT_Strategy |
|
76 | + && $custom_post_types instanceof CustomPostTypeDefinitions |
|
77 | + && $taxonomies instanceof CustomTaxonomyDefinitions |
|
78 | + ) { |
|
79 | + self::$_instance = new self($custom_post_types, $taxonomies); |
|
80 | + } |
|
81 | + return self::$_instance; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
87 | + * @param CustomTaxonomyDefinitions $taxonomies |
|
88 | + */ |
|
89 | + protected function __construct( |
|
90 | + CustomPostTypeDefinitions $custom_post_types, |
|
91 | + CustomTaxonomyDefinitions $taxonomies |
|
92 | + ) { |
|
93 | + // get CPT data |
|
94 | + $this->_CPTs = $custom_post_types->getDefinitions(); |
|
95 | + $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
96 | + $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
97 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function get_CPT_endpoints() |
|
105 | + { |
|
106 | + return $this->_CPT_endpoints; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public function get_CPT_taxonomies() |
|
114 | + { |
|
115 | + return $this->_CPT_taxonomies; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * add CPT "slugs" to array of default espresso "pages" |
|
121 | + * |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + private function _set_CPT_endpoints() |
|
125 | + { |
|
126 | + $_CPT_endpoints = array(); |
|
127 | + if (is_array($this->_CPTs)) { |
|
128 | + foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
129 | + $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
130 | + } |
|
131 | + } |
|
132 | + return $_CPT_endpoints; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
138 | + * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
139 | + * adding EE objects to the post to facilitate further querying of related data etc) |
|
140 | + * |
|
141 | + * @param WP_Query $WP_Query |
|
142 | + * @return void |
|
143 | + * @throws \EE_Error |
|
144 | + * @throws \InvalidArgumentException |
|
145 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
146 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
147 | + */ |
|
148 | + public function pre_get_posts($WP_Query) |
|
149 | + { |
|
150 | + // check that post-type is set |
|
151 | + if (! $WP_Query instanceof WP_Query) { |
|
152 | + return; |
|
153 | + } |
|
154 | + // add our conditionals |
|
155 | + $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
156 | + // check for terms |
|
157 | + $this->_set_post_type_for_terms($WP_Query); |
|
158 | + // make sure paging is always set |
|
159 | + $this->_set_paging($WP_Query); |
|
160 | + // is a taxonomy set ? |
|
161 | + $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
162 | + // loop thru post_types if set |
|
163 | + $this->_process_WP_Query_post_types($WP_Query); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @param WP_Query $WP_Query |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
172 | + { |
|
173 | + $WP_Query->is_espresso_event_single = false; |
|
174 | + $WP_Query->is_espresso_event_archive = false; |
|
175 | + $WP_Query->is_espresso_event_taxonomy = false; |
|
176 | + $WP_Query->is_espresso_venue_single = false; |
|
177 | + $WP_Query->is_espresso_venue_archive = false; |
|
178 | + $WP_Query->is_espresso_venue_taxonomy = false; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @return void |
|
184 | + * @throws EE_Error |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws InvalidDataTypeException |
|
187 | + * @throws InvalidInterfaceException |
|
188 | + */ |
|
189 | + private function _set_CPT_terms() |
|
190 | + { |
|
191 | + if (empty($this->_CPT_terms)) { |
|
192 | + $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
193 | + foreach ($terms as $term) { |
|
194 | + if ($term instanceof EE_Term) { |
|
195 | + $this->_CPT_terms[ $term->slug() ] = $term; |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param WP_Query $WP_Query |
|
204 | + * @return void |
|
205 | + * @throws EE_Error |
|
206 | + * @throws InvalidArgumentException |
|
207 | + * @throws InvalidDataTypeException |
|
208 | + * @throws InvalidInterfaceException |
|
209 | + */ |
|
210 | + private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
211 | + { |
|
212 | + // is a tag set ? |
|
213 | + if (isset($WP_Query->query['tag'])) { |
|
214 | + // set post_tags |
|
215 | + $this->_set_CPT_terms(); |
|
216 | + // is this tag archive term in the list of terms used by our CPTs ? |
|
217 | + $term = isset($this->_CPT_terms[ $WP_Query->query['tag'] ]) |
|
218 | + ? $this->_CPT_terms[ $WP_Query->query['tag'] ] |
|
219 | + : null; |
|
220 | + // verify the term |
|
221 | + if ($term instanceof EE_Term) { |
|
222 | + $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
223 | + $term->post_type = apply_filters( |
|
224 | + 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
225 | + $term->post_type, |
|
226 | + $term |
|
227 | + ); |
|
228 | + // if a post type is already set |
|
229 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
230 | + // add to existing array |
|
231 | + $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
232 | + } |
|
233 | + // just set post_type to our CPT |
|
234 | + $WP_Query->set('post_type', array_unique($term->post_type)); |
|
235 | + } |
|
236 | + } |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @param WP_Query $WP_Query |
|
242 | + * @return void |
|
243 | + */ |
|
244 | + public function _set_paging($WP_Query) |
|
245 | + { |
|
246 | + if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
247 | + $page = get_query_var('page') ? get_query_var('page') : null; |
|
248 | + $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
249 | + $WP_Query->set('paged', $paged); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param \WP_Query $WP_Query |
|
256 | + */ |
|
257 | + protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
258 | + { |
|
259 | + // is a taxonomy set ? |
|
260 | + if ($WP_Query->is_tax) { |
|
261 | + // loop thru our taxonomies |
|
262 | + foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
263 | + // check if one of our taxonomies is set as a query var |
|
264 | + if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
265 | + // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
266 | + foreach ($this->_CPTs as $post_type => $CPT) { |
|
267 | + // verify our CPT has args, is public and has taxonomies set |
|
268 | + if (isset($CPT['args']['public']) |
|
269 | + && $CPT['args']['public'] |
|
270 | + && ! empty($CPT['args']['taxonomies']) |
|
271 | + && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
272 | + ) { |
|
273 | + // if so, then add this CPT post_type to the current query's array of post_types' |
|
274 | + $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
275 | + ? (array) $WP_Query->query_vars['post_type'] |
|
276 | + : array(); |
|
277 | + $WP_Query->query_vars['post_type'][] = $post_type; |
|
278 | + switch ($post_type) { |
|
279 | + case 'espresso_events': |
|
280 | + $WP_Query->is_espresso_event_taxonomy = true; |
|
281 | + break; |
|
282 | + case 'espresso_venues': |
|
283 | + $WP_Query->is_espresso_venue_taxonomy = true; |
|
284 | + break; |
|
285 | + default: |
|
286 | + do_action( |
|
287 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
288 | + $WP_Query, |
|
289 | + $this |
|
290 | + ); |
|
291 | + } |
|
292 | + } |
|
293 | + } |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * @param \WP_Query $WP_Query |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidDataTypeException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + */ |
|
306 | + protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
307 | + { |
|
308 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
309 | + // loop thru post_types as array |
|
310 | + foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
311 | + // is current query for an EE CPT ? |
|
312 | + if (isset($this->_CPTs[ $post_type ])) { |
|
313 | + // is EE on or off ? |
|
314 | + if (EE_Maintenance_Mode::instance()->level()) { |
|
315 | + // reroute CPT template view to maintenance_mode.template.php |
|
316 | + if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
317 | + add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
318 | + } |
|
319 | + if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
320 | + add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
321 | + } |
|
322 | + return; |
|
323 | + } |
|
324 | + $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
325 | + } |
|
326 | + } |
|
327 | + } |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @param \WP_Query $WP_Query |
|
333 | + * @param string $post_type |
|
334 | + * @throws InvalidArgumentException |
|
335 | + * @throws InvalidDataTypeException |
|
336 | + * @throws InvalidInterfaceException |
|
337 | + */ |
|
338 | + protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
339 | + { |
|
340 | + $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
341 | + 'EventEspresso\core\CPTs\CptQueryModifier', |
|
342 | + array( |
|
343 | + $post_type, |
|
344 | + $this->_CPTs[ $post_type ], |
|
345 | + $WP_Query, |
|
346 | + ) |
|
347 | + ); |
|
348 | + $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * inject_EE_shortcode_placeholder |
|
354 | + * in order to display the M-Mode notice on our CPT routes, |
|
355 | + * we need to first inject what looks like one of our shortcodes, |
|
356 | + * so that it can be replaced with the actual M-Mode notice |
|
357 | + * |
|
358 | + * @return string |
|
359 | + */ |
|
360 | + public function inject_EE_shortcode_placeholder() |
|
361 | + { |
|
362 | + return '[ESPRESSO_'; |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * @deprecated |
|
368 | + * @since 4.8.41 |
|
369 | + * @return void |
|
370 | + */ |
|
371 | + public function _possibly_set_ee_request_var() |
|
372 | + { |
|
373 | + $this->query_modifier->setRequestVarsIfCpt(); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @deprecated |
|
379 | + * @since 4.8.41 |
|
380 | + * @param $SQL |
|
381 | + * @return string |
|
382 | + */ |
|
383 | + public function posts_fields($SQL) |
|
384 | + { |
|
385 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
386 | + return $this->query_modifier->postsFields($SQL); |
|
387 | + } |
|
388 | + return $SQL; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * @deprecated |
|
394 | + * @since 4.8.41 |
|
395 | + * @param $SQL |
|
396 | + * @return string |
|
397 | + */ |
|
398 | + public function posts_join($SQL) |
|
399 | + { |
|
400 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
401 | + return $this->query_modifier->postsJoin($SQL); |
|
402 | + } |
|
403 | + return $SQL; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * @deprecated |
|
409 | + * @since 4.8.41 |
|
410 | + * @param \WP_Post[] $posts |
|
411 | + * @return \WP_Post[] |
|
412 | + */ |
|
413 | + public function the_posts($posts) |
|
414 | + { |
|
415 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
416 | + $this->query_modifier->thePosts($posts); |
|
417 | + } |
|
418 | + return $posts; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @deprecated |
|
424 | + * @since 4.8.41 |
|
425 | + * @param $url |
|
426 | + * @param $ID |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public function get_edit_post_link($url, $ID) |
|
430 | + { |
|
431 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
432 | + return $this->query_modifier->getEditPostLink($url, $ID); |
|
433 | + } |
|
434 | + return ''; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * @deprecated |
|
440 | + * @since 4.8.41 |
|
441 | + * @param null $WP_Query |
|
442 | + */ |
|
443 | + protected function _do_template_filters($WP_Query = null) |
|
444 | + { |
|
445 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
446 | + $this->query_modifier->addTemplateFilters(); |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @deprecated |
|
453 | + * @since 4.8.41 |
|
454 | + * @param string $current_template Existing default template path derived for this page call. |
|
455 | + * @return string the path to the full template file. |
|
456 | + */ |
|
457 | + public function single_cpt_template($current_template) |
|
458 | + { |
|
459 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
460 | + return $this->query_modifier->singleCptTemplate($current_template); |
|
461 | + } |
|
462 | + return $current_template; |
|
463 | + } |
|
464 | 464 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | CustomTaxonomyDefinitions $taxonomies = null |
73 | 73 | ) { |
74 | 74 | // check if class object is instantiated |
75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
75 | + if ( ! self::$_instance instanceof EE_CPT_Strategy |
|
76 | 76 | && $custom_post_types instanceof CustomPostTypeDefinitions |
77 | 77 | && $taxonomies instanceof CustomTaxonomyDefinitions |
78 | 78 | ) { |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $_CPT_endpoints = array(); |
127 | 127 | if (is_array($this->_CPTs)) { |
128 | 128 | foreach ($this->_CPTs as $CPT_type => $CPT) { |
129 | - $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
129 | + $_CPT_endpoints [$CPT['plural_slug']] = $CPT_type; |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | return $_CPT_endpoints; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | public function pre_get_posts($WP_Query) |
149 | 149 | { |
150 | 150 | // check that post-type is set |
151 | - if (! $WP_Query instanceof WP_Query) { |
|
151 | + if ( ! $WP_Query instanceof WP_Query) { |
|
152 | 152 | return; |
153 | 153 | } |
154 | 154 | // add our conditionals |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
193 | 193 | foreach ($terms as $term) { |
194 | 194 | if ($term instanceof EE_Term) { |
195 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
195 | + $this->_CPT_terms[$term->slug()] = $term; |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | // set post_tags |
215 | 215 | $this->_set_CPT_terms(); |
216 | 216 | // is this tag archive term in the list of terms used by our CPTs ? |
217 | - $term = isset($this->_CPT_terms[ $WP_Query->query['tag'] ]) |
|
218 | - ? $this->_CPT_terms[ $WP_Query->query['tag'] ] |
|
217 | + $term = isset($this->_CPT_terms[$WP_Query->query['tag']]) |
|
218 | + ? $this->_CPT_terms[$WP_Query->query['tag']] |
|
219 | 219 | : null; |
220 | 220 | // verify the term |
221 | 221 | if ($term instanceof EE_Term) { |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | // loop thru our taxonomies |
262 | 262 | foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
263 | 263 | // check if one of our taxonomies is set as a query var |
264 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
264 | + if (isset($WP_Query->query[$CPT_taxonomy])) { |
|
265 | 265 | // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
266 | 266 | foreach ($this->_CPTs as $post_type => $CPT) { |
267 | 267 | // verify our CPT has args, is public and has taxonomies set |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | break; |
285 | 285 | default: |
286 | 286 | do_action( |
287 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
287 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type', |
|
288 | 288 | $WP_Query, |
289 | 289 | $this |
290 | 290 | ); |
@@ -309,11 +309,11 @@ discard block |
||
309 | 309 | // loop thru post_types as array |
310 | 310 | foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
311 | 311 | // is current query for an EE CPT ? |
312 | - if (isset($this->_CPTs[ $post_type ])) { |
|
312 | + if (isset($this->_CPTs[$post_type])) { |
|
313 | 313 | // is EE on or off ? |
314 | 314 | if (EE_Maintenance_Mode::instance()->level()) { |
315 | 315 | // reroute CPT template view to maintenance_mode.template.php |
316 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
316 | + if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
317 | 317 | add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
318 | 318 | } |
319 | 319 | if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | 'EventEspresso\core\CPTs\CptQueryModifier', |
342 | 342 | array( |
343 | 343 | $post_type, |
344 | - $this->_CPTs[ $post_type ], |
|
344 | + $this->_CPTs[$post_type], |
|
345 | 345 | $WP_Query, |
346 | 346 | ) |
347 | 347 | ); |
@@ -13,252 +13,252 @@ |
||
13 | 13 | class EE_CPT_Event_Strategy |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * the current page, if it utilizes CPTs |
|
18 | - * |
|
19 | - * @var object $CPT |
|
20 | - */ |
|
21 | - protected $CPT; |
|
16 | + /** |
|
17 | + * the current page, if it utilizes CPTs |
|
18 | + * |
|
19 | + * @var object $CPT |
|
20 | + */ |
|
21 | + protected $CPT; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param WP_Query $wp_query |
|
26 | - * @param array $CPT |
|
27 | - */ |
|
28 | - public function __construct($wp_query, $CPT = array()) |
|
29 | - { |
|
30 | - if ($wp_query instanceof WP_Query) { |
|
31 | - $WP_Query = $wp_query; |
|
32 | - $this->CPT = $CPT; |
|
33 | - } else { |
|
34 | - $WP_Query = isset($wp_query['WP_Query']) ? $wp_query['WP_Query'] : null; |
|
35 | - $this->CPT = isset($wp_query['CPT']) ? $wp_query['CPT'] : null; |
|
36 | - } |
|
37 | - // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
|
38 | - // here's the list of available filters in the WP_Query object |
|
39 | - // 'posts_where' |
|
40 | - // 'posts_where_paged' |
|
41 | - // 'posts_groupby' |
|
42 | - // 'posts_join_paged' |
|
43 | - // 'posts_orderby' |
|
44 | - // 'posts_distinct' |
|
45 | - // 'post_limits' |
|
46 | - // 'posts_fields' |
|
47 | - // 'posts_join' |
|
48 | - $this->_add_filters(); |
|
49 | - if ($WP_Query instanceof WP_Query) { |
|
50 | - $WP_Query->is_espresso_event_single = is_singular() |
|
51 | - && isset($WP_Query->query->post_type) |
|
52 | - && $WP_Query->query->post_type === 'espresso_events'; |
|
53 | - $WP_Query->is_espresso_event_archive = is_post_type_archive('espresso_events'); |
|
54 | - $WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories'); |
|
55 | - } |
|
56 | - } |
|
24 | + /** |
|
25 | + * @param WP_Query $wp_query |
|
26 | + * @param array $CPT |
|
27 | + */ |
|
28 | + public function __construct($wp_query, $CPT = array()) |
|
29 | + { |
|
30 | + if ($wp_query instanceof WP_Query) { |
|
31 | + $WP_Query = $wp_query; |
|
32 | + $this->CPT = $CPT; |
|
33 | + } else { |
|
34 | + $WP_Query = isset($wp_query['WP_Query']) ? $wp_query['WP_Query'] : null; |
|
35 | + $this->CPT = isset($wp_query['CPT']) ? $wp_query['CPT'] : null; |
|
36 | + } |
|
37 | + // !!!!!!!!!! IMPORTANT !!!!!!!!!!!! |
|
38 | + // here's the list of available filters in the WP_Query object |
|
39 | + // 'posts_where' |
|
40 | + // 'posts_where_paged' |
|
41 | + // 'posts_groupby' |
|
42 | + // 'posts_join_paged' |
|
43 | + // 'posts_orderby' |
|
44 | + // 'posts_distinct' |
|
45 | + // 'post_limits' |
|
46 | + // 'posts_fields' |
|
47 | + // 'posts_join' |
|
48 | + $this->_add_filters(); |
|
49 | + if ($WP_Query instanceof WP_Query) { |
|
50 | + $WP_Query->is_espresso_event_single = is_singular() |
|
51 | + && isset($WP_Query->query->post_type) |
|
52 | + && $WP_Query->query->post_type === 'espresso_events'; |
|
53 | + $WP_Query->is_espresso_event_archive = is_post_type_archive('espresso_events'); |
|
54 | + $WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories'); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * When an instance of this class is created, we add our filters |
|
61 | - * (which will get removed in case the next call to get_posts ISN'T |
|
62 | - * for event CPTs) |
|
63 | - */ |
|
64 | - protected function _add_filters() |
|
65 | - { |
|
66 | - add_filter('posts_fields', array($this, 'posts_fields'), 1, 2); |
|
67 | - add_filter('posts_join', array($this, 'posts_join'), 1, 2); |
|
68 | - add_filter('posts_where', array($this, 'posts_where'), 10, 2); |
|
69 | - // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 ); |
|
70 | - add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2); |
|
71 | - add_filter('posts_groupby', array($this, 'posts_groupby'), 1, 2); |
|
72 | - add_action('posts_selection', array($this, 'remove_filters')); |
|
73 | - } |
|
59 | + /** |
|
60 | + * When an instance of this class is created, we add our filters |
|
61 | + * (which will get removed in case the next call to get_posts ISN'T |
|
62 | + * for event CPTs) |
|
63 | + */ |
|
64 | + protected function _add_filters() |
|
65 | + { |
|
66 | + add_filter('posts_fields', array($this, 'posts_fields'), 1, 2); |
|
67 | + add_filter('posts_join', array($this, 'posts_join'), 1, 2); |
|
68 | + add_filter('posts_where', array($this, 'posts_where'), 10, 2); |
|
69 | + // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 ); |
|
70 | + add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2); |
|
71 | + add_filter('posts_groupby', array($this, 'posts_groupby'), 1, 2); |
|
72 | + add_action('posts_selection', array($this, 'remove_filters')); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * public access to _remove_filters() |
|
78 | - * |
|
79 | - * @since $VID:$ |
|
80 | - */ |
|
81 | - public function remove_filters() |
|
82 | - { |
|
83 | - $this->_remove_filters(); |
|
84 | - } |
|
76 | + /** |
|
77 | + * public access to _remove_filters() |
|
78 | + * |
|
79 | + * @since $VID:$ |
|
80 | + */ |
|
81 | + public function remove_filters() |
|
82 | + { |
|
83 | + $this->_remove_filters(); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * Should eb called when the last filter or hook is fired for this CPT strategy. |
|
89 | - * This is to avoid applying this CPT strategy for other posts or CPTs (eg, |
|
90 | - * we don't want to join to the datetime table when querying for venues, do we!?) |
|
91 | - */ |
|
92 | - protected function _remove_filters() |
|
93 | - { |
|
94 | - remove_filter('posts_fields', array($this, 'posts_fields'), 1); |
|
95 | - remove_filter('posts_join', array($this, 'posts_join'), 1); |
|
96 | - remove_filter('posts_where', array($this, 'posts_where'), 10); |
|
97 | - // remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 ); |
|
98 | - remove_filter('posts_orderby', array($this, 'posts_orderby'), 1); |
|
99 | - remove_filter('posts_groupby', array($this, 'posts_groupby'), 1); |
|
100 | - remove_action('posts_selection', array($this, 'remove_filters')); |
|
101 | - } |
|
87 | + /** |
|
88 | + * Should eb called when the last filter or hook is fired for this CPT strategy. |
|
89 | + * This is to avoid applying this CPT strategy for other posts or CPTs (eg, |
|
90 | + * we don't want to join to the datetime table when querying for venues, do we!?) |
|
91 | + */ |
|
92 | + protected function _remove_filters() |
|
93 | + { |
|
94 | + remove_filter('posts_fields', array($this, 'posts_fields'), 1); |
|
95 | + remove_filter('posts_join', array($this, 'posts_join'), 1); |
|
96 | + remove_filter('posts_where', array($this, 'posts_where'), 10); |
|
97 | + // remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 ); |
|
98 | + remove_filter('posts_orderby', array($this, 'posts_orderby'), 1); |
|
99 | + remove_filter('posts_groupby', array($this, 'posts_groupby'), 1); |
|
100 | + remove_action('posts_selection', array($this, 'remove_filters')); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | |
104 | - /** |
|
105 | - * @param string $SQL |
|
106 | - * @param WP_Query $wp_query |
|
107 | - * @return string |
|
108 | - * @throws EE_Error |
|
109 | - * @throws InvalidArgumentException |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - * @throws InvalidInterfaceException |
|
112 | - */ |
|
113 | - public function posts_fields($SQL, WP_Query $wp_query) |
|
114 | - { |
|
115 | - if ($wp_query instanceof WP_Query |
|
116 | - && |
|
117 | - ( |
|
118 | - $wp_query->is_espresso_event_single |
|
119 | - || $wp_query->is_espresso_event_archive |
|
120 | - || $wp_query->is_espresso_event_taxonomy |
|
121 | - ) |
|
122 | - ) { |
|
123 | - // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
|
124 | - $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* '; |
|
125 | - if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) { |
|
126 | - // because we only want to retrieve the next upcoming datetime for each event: |
|
127 | - // add something like: |
|
128 | - // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date " |
|
129 | - // to WP Query SELECT statement |
|
130 | - $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
131 | - } |
|
132 | - } |
|
133 | - return $SQL; |
|
134 | - } |
|
104 | + /** |
|
105 | + * @param string $SQL |
|
106 | + * @param WP_Query $wp_query |
|
107 | + * @return string |
|
108 | + * @throws EE_Error |
|
109 | + * @throws InvalidArgumentException |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + * @throws InvalidInterfaceException |
|
112 | + */ |
|
113 | + public function posts_fields($SQL, WP_Query $wp_query) |
|
114 | + { |
|
115 | + if ($wp_query instanceof WP_Query |
|
116 | + && |
|
117 | + ( |
|
118 | + $wp_query->is_espresso_event_single |
|
119 | + || $wp_query->is_espresso_event_archive |
|
120 | + || $wp_query->is_espresso_event_taxonomy |
|
121 | + ) |
|
122 | + ) { |
|
123 | + // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
|
124 | + $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* '; |
|
125 | + if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) { |
|
126 | + // because we only want to retrieve the next upcoming datetime for each event: |
|
127 | + // add something like: |
|
128 | + // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date " |
|
129 | + // to WP Query SELECT statement |
|
130 | + $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
131 | + } |
|
132 | + } |
|
133 | + return $SQL; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | |
137 | - /** |
|
138 | - * @param string $SQL |
|
139 | - * @param WP_Query $wp_query |
|
140 | - * @return string |
|
141 | - * @throws EE_Error |
|
142 | - * @throws InvalidArgumentException |
|
143 | - * @throws InvalidDataTypeException |
|
144 | - * @throws InvalidInterfaceException |
|
145 | - */ |
|
146 | - public function posts_join($SQL, WP_Query $wp_query) |
|
147 | - { |
|
148 | - if ($wp_query instanceof WP_Query |
|
149 | - && |
|
150 | - ( |
|
151 | - $wp_query->is_espresso_event_single |
|
152 | - || $wp_query->is_espresso_event_archive |
|
153 | - || $wp_query->is_espresso_event_taxonomy |
|
154 | - ) |
|
155 | - ) { |
|
156 | - // adds something like: |
|
157 | - // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) " |
|
158 | - // to WP Query JOIN statement |
|
159 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() |
|
160 | - . '.ID = ' . EEM_Datetime::instance()->table() . '.' |
|
161 | - . EEM_Event::instance()->primary_key_name() . ' ) '; |
|
162 | - } |
|
163 | - return $SQL; |
|
164 | - } |
|
137 | + /** |
|
138 | + * @param string $SQL |
|
139 | + * @param WP_Query $wp_query |
|
140 | + * @return string |
|
141 | + * @throws EE_Error |
|
142 | + * @throws InvalidArgumentException |
|
143 | + * @throws InvalidDataTypeException |
|
144 | + * @throws InvalidInterfaceException |
|
145 | + */ |
|
146 | + public function posts_join($SQL, WP_Query $wp_query) |
|
147 | + { |
|
148 | + if ($wp_query instanceof WP_Query |
|
149 | + && |
|
150 | + ( |
|
151 | + $wp_query->is_espresso_event_single |
|
152 | + || $wp_query->is_espresso_event_archive |
|
153 | + || $wp_query->is_espresso_event_taxonomy |
|
154 | + ) |
|
155 | + ) { |
|
156 | + // adds something like: |
|
157 | + // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) " |
|
158 | + // to WP Query JOIN statement |
|
159 | + $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() |
|
160 | + . '.ID = ' . EEM_Datetime::instance()->table() . '.' |
|
161 | + . EEM_Event::instance()->primary_key_name() . ' ) '; |
|
162 | + } |
|
163 | + return $SQL; |
|
164 | + } |
|
165 | 165 | |
166 | 166 | |
167 | - /** |
|
168 | - * @param string $SQL |
|
169 | - * @param WP_Query $wp_query |
|
170 | - * @return string |
|
171 | - * @throws EE_Error |
|
172 | - * @throws InvalidArgumentException |
|
173 | - * @throws InvalidDataTypeException |
|
174 | - * @throws InvalidInterfaceException |
|
175 | - */ |
|
176 | - public function posts_where($SQL, WP_Query $wp_query) |
|
177 | - { |
|
178 | - if ($wp_query instanceof WP_Query |
|
179 | - && |
|
180 | - ( |
|
181 | - $wp_query->is_espresso_event_archive |
|
182 | - || $wp_query->is_espresso_event_taxonomy |
|
183 | - ) |
|
184 | - ) { |
|
185 | - if (! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive) |
|
186 | - || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events) |
|
187 | - || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events |
|
188 | - ) { |
|
189 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" |
|
190 | - . current_time('mysql', true) . "' "; |
|
191 | - } |
|
192 | - } |
|
193 | - return $SQL; |
|
194 | - } |
|
167 | + /** |
|
168 | + * @param string $SQL |
|
169 | + * @param WP_Query $wp_query |
|
170 | + * @return string |
|
171 | + * @throws EE_Error |
|
172 | + * @throws InvalidArgumentException |
|
173 | + * @throws InvalidDataTypeException |
|
174 | + * @throws InvalidInterfaceException |
|
175 | + */ |
|
176 | + public function posts_where($SQL, WP_Query $wp_query) |
|
177 | + { |
|
178 | + if ($wp_query instanceof WP_Query |
|
179 | + && |
|
180 | + ( |
|
181 | + $wp_query->is_espresso_event_archive |
|
182 | + || $wp_query->is_espresso_event_taxonomy |
|
183 | + ) |
|
184 | + ) { |
|
185 | + if (! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive) |
|
186 | + || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events) |
|
187 | + || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events |
|
188 | + ) { |
|
189 | + $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" |
|
190 | + . current_time('mysql', true) . "' "; |
|
191 | + } |
|
192 | + } |
|
193 | + return $SQL; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | |
197 | - /** |
|
198 | - * @param string $SQL |
|
199 | - * @param WP_Query $wp_query |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public function posts_orderby($SQL, WP_Query $wp_query) |
|
203 | - { |
|
204 | - if ($wp_query instanceof WP_Query |
|
205 | - && |
|
206 | - ( |
|
207 | - $wp_query->is_espresso_event_archive |
|
208 | - || $wp_query->is_espresso_event_taxonomy |
|
209 | - ) |
|
210 | - ) { |
|
211 | - $SQL = ' event_start_date ASC '; |
|
212 | - } |
|
213 | - return $SQL; |
|
214 | - } |
|
197 | + /** |
|
198 | + * @param string $SQL |
|
199 | + * @param WP_Query $wp_query |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public function posts_orderby($SQL, WP_Query $wp_query) |
|
203 | + { |
|
204 | + if ($wp_query instanceof WP_Query |
|
205 | + && |
|
206 | + ( |
|
207 | + $wp_query->is_espresso_event_archive |
|
208 | + || $wp_query->is_espresso_event_taxonomy |
|
209 | + ) |
|
210 | + ) { |
|
211 | + $SQL = ' event_start_date ASC '; |
|
212 | + } |
|
213 | + return $SQL; |
|
214 | + } |
|
215 | 215 | |
216 | 216 | |
217 | - /** |
|
218 | - * @param string $SQL |
|
219 | - * @param WP_Query $wp_query |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function posts_groupby($SQL, WP_Query $wp_query) |
|
223 | - { |
|
224 | - if ($wp_query instanceof WP_Query |
|
225 | - && |
|
226 | - ( |
|
227 | - $wp_query->is_espresso_event_archive |
|
228 | - || $wp_query->is_espresso_event_taxonomy |
|
229 | - ) |
|
230 | - ) { |
|
231 | - // TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default) |
|
232 | - // we're joining to the datetimes table, where there can be MANY datetimes for a single event, |
|
233 | - // but we want to only show each event only once |
|
234 | - // (whereas if we didn't group them by the post's ID, then we would end up with many repeats) |
|
235 | - global $wpdb; |
|
236 | - $SQL = $wpdb->posts . '.ID '; |
|
237 | - } |
|
238 | - return $SQL; |
|
239 | - } |
|
217 | + /** |
|
218 | + * @param string $SQL |
|
219 | + * @param WP_Query $wp_query |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function posts_groupby($SQL, WP_Query $wp_query) |
|
223 | + { |
|
224 | + if ($wp_query instanceof WP_Query |
|
225 | + && |
|
226 | + ( |
|
227 | + $wp_query->is_espresso_event_archive |
|
228 | + || $wp_query->is_espresso_event_taxonomy |
|
229 | + ) |
|
230 | + ) { |
|
231 | + // TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default) |
|
232 | + // we're joining to the datetimes table, where there can be MANY datetimes for a single event, |
|
233 | + // but we want to only show each event only once |
|
234 | + // (whereas if we didn't group them by the post's ID, then we would end up with many repeats) |
|
235 | + global $wpdb; |
|
236 | + $SQL = $wpdb->posts . '.ID '; |
|
237 | + } |
|
238 | + return $SQL; |
|
239 | + } |
|
240 | 240 | |
241 | 241 | |
242 | - /** |
|
243 | - * @param array $posts |
|
244 | - * @param WP_Query $wp_query |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - public function the_posts($posts, WP_Query $wp_query) |
|
248 | - { |
|
249 | - return $posts; |
|
250 | - } |
|
242 | + /** |
|
243 | + * @param array $posts |
|
244 | + * @param WP_Query $wp_query |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + public function the_posts($posts, WP_Query $wp_query) |
|
248 | + { |
|
249 | + return $posts; |
|
250 | + } |
|
251 | 251 | |
252 | 252 | |
253 | - /** |
|
254 | - * @param null $meta_value |
|
255 | - * @param $post_id |
|
256 | - * @param $meta_key |
|
257 | - * @param $single |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single) |
|
261 | - { |
|
262 | - return $meta_value; |
|
263 | - } |
|
253 | + /** |
|
254 | + * @param null $meta_value |
|
255 | + * @param $post_id |
|
256 | + * @param $meta_key |
|
257 | + * @param $single |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single) |
|
261 | + { |
|
262 | + return $meta_value; |
|
263 | + } |
|
264 | 264 | } |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | ) |
122 | 122 | ) { |
123 | 123 | // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement |
124 | - $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* '; |
|
124 | + $SQL .= ', '.EEM_Datetime::instance()->table().'.* '; |
|
125 | 125 | if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) { |
126 | 126 | // because we only want to retrieve the next upcoming datetime for each event: |
127 | 127 | // add something like: |
128 | 128 | // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date " |
129 | 129 | // to WP Query SELECT statement |
130 | - $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date '; |
|
130 | + $SQL .= ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date '; |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | return $SQL; |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | // adds something like: |
157 | 157 | // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) " |
158 | 158 | // to WP Query JOIN statement |
159 | - $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table() |
|
160 | - . '.ID = ' . EEM_Datetime::instance()->table() . '.' |
|
161 | - . EEM_Event::instance()->primary_key_name() . ' ) '; |
|
159 | + $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.EEM_Event::instance()->table() |
|
160 | + . '.ID = '.EEM_Datetime::instance()->table().'.' |
|
161 | + . EEM_Event::instance()->primary_key_name().' ) '; |
|
162 | 162 | } |
163 | 163 | return $SQL; |
164 | 164 | } |
@@ -182,12 +182,12 @@ discard block |
||
182 | 182 | || $wp_query->is_espresso_event_taxonomy |
183 | 183 | ) |
184 | 184 | ) { |
185 | - if (! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive) |
|
185 | + if ( ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive) |
|
186 | 186 | || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events) |
187 | 187 | || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events |
188 | 188 | ) { |
189 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '" |
|
190 | - . current_time('mysql', true) . "' "; |
|
189 | + $SQL .= ' AND '.EEM_Datetime::instance()->table().".DTT_EVT_end > '" |
|
190 | + . current_time('mysql', true)."' "; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | return $SQL; |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | // but we want to only show each event only once |
234 | 234 | // (whereas if we didn't group them by the post's ID, then we would end up with many repeats) |
235 | 235 | global $wpdb; |
236 | - $SQL = $wpdb->posts . '.ID '; |
|
236 | + $SQL = $wpdb->posts.'.ID '; |
|
237 | 237 | } |
238 | 238 | return $SQL; |
239 | 239 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | public static function instance(ClassInterfaceCache $class_cache = null) |
123 | 123 | { |
124 | 124 | // check if class object is instantiated, and instantiated properly |
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
125 | + if ( ! self::$_instance instanceof EE_Dependency_Map |
|
126 | 126 | && $class_cache instanceof ClassInterfaceCache |
127 | 127 | ) { |
128 | 128 | self::$_instance = new EE_Dependency_Map($class_cache); |
@@ -203,18 +203,18 @@ discard block |
||
203 | 203 | ) { |
204 | 204 | $class = trim($class, '\\'); |
205 | 205 | $registered = false; |
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
206 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
207 | + self::$_instance->_dependency_map[$class] = array(); |
|
208 | 208 | } |
209 | 209 | // we need to make sure that any aliases used when registering a dependency |
210 | 210 | // get resolved to the correct class name |
211 | 211 | foreach ($dependencies as $dependency => $load_source) { |
212 | 212 | $alias = self::$_instance->getFqnForAlias($dependency); |
213 | 213 | if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
214 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
215 | 215 | ) { |
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
216 | + unset($dependencies[$dependency]); |
|
217 | + $dependencies[$alias] = $load_source; |
|
218 | 218 | $registered = true; |
219 | 219 | } |
220 | 220 | } |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
225 | 225 | // Union is way faster than array_merge() but should be used with caution... |
226 | 226 | // especially with numerically indexed arrays |
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
227 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
228 | 228 | // now we need to ensure that the resulting dependencies |
229 | 229 | // array only has the entries that are required for the class |
230 | 230 | // so first count how many dependencies were originally registered for the class |
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
232 | 232 | // if that count is non-zero (meaning dependencies were already registered) |
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
233 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
234 | 234 | // then truncate the final array to match that count |
235 | 235 | ? array_slice($dependencies, 0, $dependency_count) |
236 | 236 | // otherwise just take the incoming array because nothing previously existed |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public static function register_class_loader($class_name, $loader = 'load_core') |
249 | 249 | { |
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
250 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | 251 | throw new DomainException( |
252 | 252 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
253 | 253 | ); |
254 | 254 | } |
255 | 255 | // check that loader is callable or method starts with "load_" and exists in EE_Registry |
256 | - if (! is_callable($loader) |
|
256 | + if ( ! is_callable($loader) |
|
257 | 257 | && ( |
258 | 258 | strpos($loader, 'load_') !== 0 |
259 | 259 | || ! method_exists('EE_Registry', $loader) |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | ); |
271 | 271 | } |
272 | 272 | $class_name = self::$_instance->getFqnForAlias($class_name); |
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
273 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
274 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
275 | 275 | return true; |
276 | 276 | } |
277 | 277 | return false; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | if (strpos($class_name, 'EEM_') === 0) { |
300 | 300 | $class_name = 'LEGACY_MODELS'; |
301 | 301 | } |
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
302 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $class_name = 'LEGACY_MODELS'; |
318 | 318 | } |
319 | 319 | $dependency = $this->getFqnForAlias($dependency, $class_name); |
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
320 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
321 | 321 | ? true |
322 | 322 | : false; |
323 | 323 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | } |
339 | 339 | $dependency = $this->getFqnForAlias($dependency); |
340 | 340 | return $this->has_dependency_for_class($class_name, $dependency) |
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
341 | + ? $this->_dependency_map[$class_name][$dependency] |
|
342 | 342 | : EE_Dependency_Map::not_registered; |
343 | 343 | } |
344 | 344 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | return 'load_core'; |
362 | 362 | } |
363 | 363 | $class_name = $this->getFqnForAlias($class_name); |
364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
364 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -803,13 +803,13 @@ discard block |
||
803 | 803 | 'EE_Front_Controller' => 'load_core', |
804 | 804 | 'EE_Module_Request_Router' => 'load_core', |
805 | 805 | 'EE_Registry' => 'load_core', |
806 | - 'EE_Request' => function () use (&$legacy_request) { |
|
806 | + 'EE_Request' => function() use (&$legacy_request) { |
|
807 | 807 | return $legacy_request; |
808 | 808 | }, |
809 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
809 | + 'EventEspresso\core\services\request\Request' => function() use (&$request) { |
|
810 | 810 | return $request; |
811 | 811 | }, |
812 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
812 | + 'EventEspresso\core\services\request\Response' => function() use (&$response) { |
|
813 | 813 | return $response; |
814 | 814 | }, |
815 | 815 | 'EE_Base' => 'load_core', |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
834 | 834 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
835 | 835 | 'EE_Payment_Method_Manager' => 'load_lib', |
836 | - 'EE_Messages_Generator' => function () { |
|
836 | + 'EE_Messages_Generator' => function() { |
|
837 | 837 | return EE_Registry::instance()->load_lib( |
838 | 838 | 'Messages_Generator', |
839 | 839 | array(), |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | false |
842 | 842 | ); |
843 | 843 | }, |
844 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
844 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
845 | 845 | return EE_Registry::instance()->load_lib( |
846 | 846 | 'Messages_Template_Defaults', |
847 | 847 | $arguments, |
@@ -850,37 +850,37 @@ discard block |
||
850 | 850 | ); |
851 | 851 | }, |
852 | 852 | // load_helper |
853 | - 'EEH_Parse_Shortcodes' => function () { |
|
853 | + 'EEH_Parse_Shortcodes' => function() { |
|
854 | 854 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
855 | 855 | return new EEH_Parse_Shortcodes(); |
856 | 856 | } |
857 | 857 | return null; |
858 | 858 | }, |
859 | - 'EE_Template_Config' => function () { |
|
859 | + 'EE_Template_Config' => function() { |
|
860 | 860 | return EE_Config::instance()->template_settings; |
861 | 861 | }, |
862 | - 'EE_Currency_Config' => function () { |
|
862 | + 'EE_Currency_Config' => function() { |
|
863 | 863 | return EE_Config::instance()->currency; |
864 | 864 | }, |
865 | - 'EE_Registration_Config' => function () { |
|
865 | + 'EE_Registration_Config' => function() { |
|
866 | 866 | return EE_Config::instance()->registration; |
867 | 867 | }, |
868 | - 'EE_Core_Config' => function () { |
|
868 | + 'EE_Core_Config' => function() { |
|
869 | 869 | return EE_Config::instance()->core; |
870 | 870 | }, |
871 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
871 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
872 | 872 | return LoaderFactory::getLoader(); |
873 | 873 | }, |
874 | - 'EE_Network_Config' => function () { |
|
874 | + 'EE_Network_Config' => function() { |
|
875 | 875 | return EE_Network_Config::instance(); |
876 | 876 | }, |
877 | - 'EE_Config' => function () { |
|
877 | + 'EE_Config' => function() { |
|
878 | 878 | return EE_Config::instance(); |
879 | 879 | }, |
880 | - 'EventEspresso\core\domain\Domain' => function () { |
|
880 | + 'EventEspresso\core\domain\Domain' => function() { |
|
881 | 881 | return DomainFactory::getEventEspressoCoreDomain(); |
882 | 882 | }, |
883 | - 'EE_Admin_Config' => function () { |
|
883 | + 'EE_Admin_Config' => function() { |
|
884 | 884 | return EE_Config::instance()->admin; |
885 | 885 | }, |
886 | 886 | ); |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | } |
943 | 943 | $this->class_cache->addAlias($fqn, $alias); |
944 | 944 | } |
945 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
945 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
946 | 946 | $this->class_cache->addAlias( |
947 | 947 | 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
948 | 948 | 'EventEspresso\core\services\notices\NoticeConverterInterface' |
@@ -20,1008 +20,1008 @@ |
||
20 | 20 | class EE_Dependency_Map |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * This means that the requested class dependency is not present in the dependency map |
|
25 | - */ |
|
26 | - const not_registered = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | - */ |
|
31 | - const load_new_object = 1; |
|
32 | - |
|
33 | - /** |
|
34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | - */ |
|
37 | - const load_from_cache = 2; |
|
38 | - |
|
39 | - /** |
|
40 | - * When registering a dependency, |
|
41 | - * this indicates to keep any existing dependencies that already exist, |
|
42 | - * and simply discard any new dependencies declared in the incoming data |
|
43 | - */ |
|
44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * When registering a dependency, |
|
48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | - */ |
|
50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
51 | - |
|
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 = array(); |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = array(); |
|
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 | - */ |
|
109 | - public function initialize() |
|
110 | - { |
|
111 | - $this->_register_core_dependencies(); |
|
112 | - $this->_register_core_class_loaders(); |
|
113 | - $this->_register_core_aliases(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @singleton method used to instantiate class object |
|
119 | - * @param ClassInterfaceCache|null $class_cache |
|
120 | - * @return EE_Dependency_Map |
|
121 | - */ |
|
122 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | - { |
|
124 | - // check if class object is instantiated, and instantiated properly |
|
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | - && $class_cache instanceof ClassInterfaceCache |
|
127 | - ) { |
|
128 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | - } |
|
130 | - return self::$_instance; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param RequestInterface $request |
|
136 | - */ |
|
137 | - public function setRequest(RequestInterface $request) |
|
138 | - { |
|
139 | - $this->request = $request; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param LegacyRequestInterface $legacy_request |
|
145 | - */ |
|
146 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | - { |
|
148 | - $this->legacy_request = $legacy_request; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param ResponseInterface $response |
|
154 | - */ |
|
155 | - public function setResponse(ResponseInterface $response) |
|
156 | - { |
|
157 | - $this->response = $response; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param LoaderInterface $loader |
|
163 | - */ |
|
164 | - public function setLoader(LoaderInterface $loader) |
|
165 | - { |
|
166 | - $this->loader = $loader; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $class |
|
172 | - * @param array $dependencies |
|
173 | - * @param int $overwrite |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public static function register_dependencies( |
|
177 | - $class, |
|
178 | - array $dependencies, |
|
179 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | - ) { |
|
181 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | - * to the class specified by the first parameter. |
|
188 | - * IMPORTANT !!! |
|
189 | - * The order of elements in the incoming $dependencies array MUST match |
|
190 | - * the order of the constructor parameters for the class in question. |
|
191 | - * This is especially important when overriding any existing dependencies that are registered. |
|
192 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | - * |
|
194 | - * @param string $class |
|
195 | - * @param array $dependencies |
|
196 | - * @param int $overwrite |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function registerDependencies( |
|
200 | - $class, |
|
201 | - array $dependencies, |
|
202 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | - ) { |
|
204 | - $class = trim($class, '\\'); |
|
205 | - $registered = false; |
|
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | - } |
|
209 | - // we need to make sure that any aliases used when registering a dependency |
|
210 | - // get resolved to the correct class name |
|
211 | - foreach ($dependencies as $dependency => $load_source) { |
|
212 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | - ) { |
|
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
218 | - $registered = true; |
|
219 | - } |
|
220 | - } |
|
221 | - // now add our two lists of dependencies together. |
|
222 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | - // so $dependencies is NOT overwritten because it is listed first |
|
224 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | - // Union is way faster than array_merge() but should be used with caution... |
|
226 | - // especially with numerically indexed arrays |
|
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | - // now we need to ensure that the resulting dependencies |
|
229 | - // array only has the entries that are required for the class |
|
230 | - // so first count how many dependencies were originally registered for the class |
|
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | - // if that count is non-zero (meaning dependencies were already registered) |
|
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | - // then truncate the final array to match that count |
|
235 | - ? array_slice($dependencies, 0, $dependency_count) |
|
236 | - // otherwise just take the incoming array because nothing previously existed |
|
237 | - : $dependencies; |
|
238 | - return $registered; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $class_name |
|
244 | - * @param string $loader |
|
245 | - * @return bool |
|
246 | - * @throws DomainException |
|
247 | - */ |
|
248 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | - { |
|
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | - throw new DomainException( |
|
252 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | - ); |
|
254 | - } |
|
255 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | - if (! is_callable($loader) |
|
257 | - && ( |
|
258 | - strpos($loader, 'load_') !== 0 |
|
259 | - || ! method_exists('EE_Registry', $loader) |
|
260 | - ) |
|
261 | - ) { |
|
262 | - throw new DomainException( |
|
263 | - sprintf( |
|
264 | - esc_html__( |
|
265 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - $loader |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | - return true; |
|
276 | - } |
|
277 | - return false; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function dependency_map() |
|
285 | - { |
|
286 | - return $this->_dependency_map; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | - * |
|
293 | - * @param string $class_name |
|
294 | - * @return boolean |
|
295 | - */ |
|
296 | - public function has($class_name = '') |
|
297 | - { |
|
298 | - // all legacy models have the same dependencies |
|
299 | - if (strpos($class_name, 'EEM_') === 0) { |
|
300 | - $class_name = 'LEGACY_MODELS'; |
|
301 | - } |
|
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | - * |
|
309 | - * @param string $class_name |
|
310 | - * @param string $dependency |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | - { |
|
315 | - // all legacy models have the same dependencies |
|
316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
317 | - $class_name = 'LEGACY_MODELS'; |
|
318 | - } |
|
319 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | - ? true |
|
322 | - : false; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | - * |
|
329 | - * @param string $class_name |
|
330 | - * @param string $dependency |
|
331 | - * @return int |
|
332 | - */ |
|
333 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | - { |
|
335 | - // all legacy models have the same dependencies |
|
336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
337 | - $class_name = 'LEGACY_MODELS'; |
|
338 | - } |
|
339 | - $dependency = $this->getFqnForAlias($dependency); |
|
340 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | - : EE_Dependency_Map::not_registered; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param string $class_name |
|
348 | - * @return string | Closure |
|
349 | - */ |
|
350 | - public function class_loader($class_name) |
|
351 | - { |
|
352 | - // all legacy models use load_model() |
|
353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
354 | - return 'load_model'; |
|
355 | - } |
|
356 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | - // perform strpos() first to avoid loading regex every time we load a class |
|
358 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | - ) { |
|
361 | - return 'load_core'; |
|
362 | - } |
|
363 | - $class_name = $this->getFqnForAlias($class_name); |
|
364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function class_loaders() |
|
372 | - { |
|
373 | - return $this->_class_loaders; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * adds an alias for a classname |
|
379 | - * |
|
380 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | - */ |
|
384 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | - { |
|
386 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | - * WHY? |
|
393 | - * Because if a class is type hinting for a concretion, |
|
394 | - * then why would we need to find another class to supply it? |
|
395 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | - * Don't go looking for some substitute. |
|
398 | - * Whereas if a class is type hinting for an interface... |
|
399 | - * then we need to find an actual class to use. |
|
400 | - * So the interface IS the alias for some other FQN, |
|
401 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | - * represents some other class. |
|
403 | - * |
|
404 | - * @param string $fqn |
|
405 | - * @param string $for_class |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function isAlias($fqn = '', $for_class = '') |
|
409 | - { |
|
410 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | - * for example: |
|
418 | - * if the following two entries were added to the _aliases array: |
|
419 | - * array( |
|
420 | - * 'interface_alias' => 'some\namespace\interface' |
|
421 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | - * ) |
|
423 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | - * to load an instance of 'some\namespace\classname' |
|
425 | - * |
|
426 | - * @param string $alias |
|
427 | - * @param string $for_class |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | - { |
|
432 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | - * This is done by using the following class constants: |
|
440 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | - */ |
|
443 | - protected function _register_core_dependencies() |
|
444 | - { |
|
445 | - $this->_dependency_map = array( |
|
446 | - 'EE_Request_Handler' => array( |
|
447 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_System' => array( |
|
450 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EE_Session' => array( |
|
456 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_Cart' => array( |
|
462 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
463 | - ), |
|
464 | - 'EE_Front_Controller' => array( |
|
465 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
466 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
468 | - ), |
|
469 | - 'EE_Messenger_Collection_Loader' => array( |
|
470 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
471 | - ), |
|
472 | - 'EE_Message_Type_Collection_Loader' => array( |
|
473 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
474 | - ), |
|
475 | - 'EE_Message_Resource_Manager' => array( |
|
476 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
477 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EE_Message_Factory' => array( |
|
481 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
482 | - ), |
|
483 | - 'EE_messages' => array( |
|
484 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
485 | - ), |
|
486 | - 'EE_Messages_Generator' => array( |
|
487 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
488 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
489 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
491 | - ), |
|
492 | - 'EE_Messages_Processor' => array( |
|
493 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
494 | - ), |
|
495 | - 'EE_Messages_Queue' => array( |
|
496 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
497 | - ), |
|
498 | - 'EE_Messages_Template_Defaults' => array( |
|
499 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
500 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
501 | - ), |
|
502 | - 'EE_Message_To_Generate_From_Request' => array( |
|
503 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
504 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
505 | - ), |
|
506 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
507 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
508 | - ), |
|
509 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
510 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
511 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
512 | - ), |
|
513 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
514 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
515 | - ), |
|
516 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
517 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
518 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
519 | - ), |
|
520 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
521 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
522 | - ), |
|
523 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
524 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
525 | - ), |
|
526 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
527 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
528 | - ), |
|
529 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
530 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
531 | - ), |
|
532 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
533 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
534 | - ), |
|
535 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
536 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
537 | - ), |
|
538 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
539 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
540 | - ), |
|
541 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
542 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
543 | - ), |
|
544 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
545 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
546 | - ), |
|
547 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
548 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
549 | - ), |
|
550 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
551 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
552 | - ), |
|
553 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
554 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
555 | - ), |
|
556 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
557 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
558 | - ), |
|
559 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
560 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
561 | - ), |
|
562 | - 'EE_Data_Migration_Class_Base' => array( |
|
563 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
564 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
565 | - ), |
|
566 | - 'EE_DMS_Core_4_1_0' => array( |
|
567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | - ), |
|
570 | - 'EE_DMS_Core_4_2_0' => array( |
|
571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | - ), |
|
574 | - 'EE_DMS_Core_4_3_0' => array( |
|
575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | - ), |
|
578 | - 'EE_DMS_Core_4_4_0' => array( |
|
579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | - ), |
|
582 | - 'EE_DMS_Core_4_5_0' => array( |
|
583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | - ), |
|
586 | - 'EE_DMS_Core_4_6_0' => array( |
|
587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EE_DMS_Core_4_7_0' => array( |
|
591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | - ), |
|
594 | - 'EE_DMS_Core_4_8_0' => array( |
|
595 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
596 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
597 | - ), |
|
598 | - 'EE_DMS_Core_4_9_0' => array( |
|
599 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
600 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
603 | - array(), |
|
604 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
605 | - ), |
|
606 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
607 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
608 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
609 | - ), |
|
610 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
611 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
612 | - ), |
|
613 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
614 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
615 | - ), |
|
616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | - ), |
|
619 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
620 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | - ), |
|
622 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | - ), |
|
625 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
626 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | - ), |
|
628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
632 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
635 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
638 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
639 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
640 | - ), |
|
641 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
642 | - null, |
|
643 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
644 | - ), |
|
645 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
646 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
647 | - ), |
|
648 | - 'LEGACY_MODELS' => array( |
|
649 | - null, |
|
650 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
651 | - ), |
|
652 | - 'EE_Module_Request_Router' => array( |
|
653 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
654 | - ), |
|
655 | - 'EE_Registration_Processor' => array( |
|
656 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
657 | - ), |
|
658 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
659 | - null, |
|
660 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
661 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
662 | - ), |
|
663 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
664 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
665 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
666 | - ), |
|
667 | - 'EE_Admin_Transactions_List_Table' => array( |
|
668 | - null, |
|
669 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
670 | - ), |
|
671 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
672 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
673 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
674 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
675 | - ), |
|
676 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
677 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
678 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
679 | - ), |
|
680 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
681 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
682 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
683 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
684 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
685 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
686 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
687 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
688 | - ), |
|
689 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
690 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
691 | - ), |
|
692 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
693 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
694 | - ), |
|
695 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
696 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
697 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
698 | - ), |
|
699 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
700 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
701 | - ), |
|
702 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
703 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
704 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
705 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
706 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
707 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
708 | - ), |
|
709 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
710 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
711 | - ), |
|
712 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
713 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
714 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
715 | - ), |
|
716 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
717 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
718 | - ), |
|
719 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
720 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
721 | - ), |
|
722 | - 'EE_CPT_Strategy' => array( |
|
723 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
725 | - ), |
|
726 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
727 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
728 | - ), |
|
729 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
730 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
731 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
732 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
733 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
734 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
735 | - ), |
|
736 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
737 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
738 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
739 | - ), |
|
740 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
741 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
742 | - ), |
|
743 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
744 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
745 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
746 | - ), |
|
747 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
748 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
749 | - ), |
|
750 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
751 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
752 | - ), |
|
753 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
754 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
755 | - ), |
|
756 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
757 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
758 | - ), |
|
759 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
760 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
761 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
762 | - ), |
|
763 | - 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
764 | - null, |
|
765 | - null, |
|
766 | - null, |
|
767 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
768 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
769 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
770 | - ), |
|
771 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
772 | - 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
773 | - 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
774 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | - ), |
|
776 | - 'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array( |
|
777 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
778 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
779 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
780 | - ), |
|
781 | - 'EventEspresso\core\domain\entities\editor\blocks\widgets\EventAttendees' => array( |
|
782 | - 'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => self::load_from_cache, |
|
783 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => self::load_from_cache, |
|
784 | - ), |
|
785 | - ); |
|
786 | - } |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * Registers how core classes are loaded. |
|
791 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
792 | - * 'EE_Request_Handler' => 'load_core' |
|
793 | - * 'EE_Messages_Queue' => 'load_lib' |
|
794 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
795 | - * or, if greater control is required, by providing a custom closure. For example: |
|
796 | - * 'Some_Class' => function () { |
|
797 | - * return new Some_Class(); |
|
798 | - * }, |
|
799 | - * This is required for instantiating dependencies |
|
800 | - * where an interface has been type hinted in a class constructor. For example: |
|
801 | - * 'Required_Interface' => function () { |
|
802 | - * return new A_Class_That_Implements_Required_Interface(); |
|
803 | - * }, |
|
804 | - */ |
|
805 | - protected function _register_core_class_loaders() |
|
806 | - { |
|
807 | - // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
808 | - // be used in a closure. |
|
809 | - $request = &$this->request; |
|
810 | - $response = &$this->response; |
|
811 | - $legacy_request = &$this->legacy_request; |
|
812 | - // $loader = &$this->loader; |
|
813 | - $this->_class_loaders = array( |
|
814 | - // load_core |
|
815 | - 'EE_Capabilities' => 'load_core', |
|
816 | - 'EE_Encryption' => 'load_core', |
|
817 | - 'EE_Front_Controller' => 'load_core', |
|
818 | - 'EE_Module_Request_Router' => 'load_core', |
|
819 | - 'EE_Registry' => 'load_core', |
|
820 | - 'EE_Request' => function () use (&$legacy_request) { |
|
821 | - return $legacy_request; |
|
822 | - }, |
|
823 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
824 | - return $request; |
|
825 | - }, |
|
826 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
827 | - return $response; |
|
828 | - }, |
|
829 | - 'EE_Base' => 'load_core', |
|
830 | - 'EE_Request_Handler' => 'load_core', |
|
831 | - 'EE_Session' => 'load_core', |
|
832 | - 'EE_Cron_Tasks' => 'load_core', |
|
833 | - 'EE_System' => 'load_core', |
|
834 | - 'EE_Maintenance_Mode' => 'load_core', |
|
835 | - 'EE_Register_CPTs' => 'load_core', |
|
836 | - 'EE_Admin' => 'load_core', |
|
837 | - 'EE_CPT_Strategy' => 'load_core', |
|
838 | - // load_lib |
|
839 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
840 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
841 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
842 | - 'EE_Messenger_Collection' => 'load_lib', |
|
843 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
844 | - 'EE_Messages_Processor' => 'load_lib', |
|
845 | - 'EE_Message_Repository' => 'load_lib', |
|
846 | - 'EE_Messages_Queue' => 'load_lib', |
|
847 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
848 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
849 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
850 | - 'EE_Messages_Generator' => function () { |
|
851 | - return EE_Registry::instance()->load_lib( |
|
852 | - 'Messages_Generator', |
|
853 | - array(), |
|
854 | - false, |
|
855 | - false |
|
856 | - ); |
|
857 | - }, |
|
858 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
859 | - return EE_Registry::instance()->load_lib( |
|
860 | - 'Messages_Template_Defaults', |
|
861 | - $arguments, |
|
862 | - false, |
|
863 | - false |
|
864 | - ); |
|
865 | - }, |
|
866 | - // load_helper |
|
867 | - 'EEH_Parse_Shortcodes' => function () { |
|
868 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
869 | - return new EEH_Parse_Shortcodes(); |
|
870 | - } |
|
871 | - return null; |
|
872 | - }, |
|
873 | - 'EE_Template_Config' => function () { |
|
874 | - return EE_Config::instance()->template_settings; |
|
875 | - }, |
|
876 | - 'EE_Currency_Config' => function () { |
|
877 | - return EE_Config::instance()->currency; |
|
878 | - }, |
|
879 | - 'EE_Registration_Config' => function () { |
|
880 | - return EE_Config::instance()->registration; |
|
881 | - }, |
|
882 | - 'EE_Core_Config' => function () { |
|
883 | - return EE_Config::instance()->core; |
|
884 | - }, |
|
885 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
886 | - return LoaderFactory::getLoader(); |
|
887 | - }, |
|
888 | - 'EE_Network_Config' => function () { |
|
889 | - return EE_Network_Config::instance(); |
|
890 | - }, |
|
891 | - 'EE_Config' => function () { |
|
892 | - return EE_Config::instance(); |
|
893 | - }, |
|
894 | - 'EventEspresso\core\domain\Domain' => function () { |
|
895 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
896 | - }, |
|
897 | - 'EE_Admin_Config' => function () { |
|
898 | - return EE_Config::instance()->admin; |
|
899 | - }, |
|
900 | - ); |
|
901 | - } |
|
902 | - |
|
903 | - |
|
904 | - /** |
|
905 | - * can be used for supplying alternate names for classes, |
|
906 | - * or for connecting interface names to instantiable classes |
|
907 | - */ |
|
908 | - protected function _register_core_aliases() |
|
909 | - { |
|
910 | - $aliases = array( |
|
911 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
912 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
913 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
914 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
915 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
916 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
917 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
918 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
919 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
920 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
921 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
922 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
923 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
924 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
925 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
926 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
927 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
928 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
929 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
930 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
931 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
932 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
933 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
934 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
935 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
936 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
937 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
938 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
939 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
940 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
941 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
942 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
943 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
944 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
945 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
946 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
947 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
948 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
949 | - ); |
|
950 | - foreach ($aliases as $alias => $fqn) { |
|
951 | - if (is_array($fqn)) { |
|
952 | - foreach ($fqn as $class => $for_class) { |
|
953 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
954 | - } |
|
955 | - continue; |
|
956 | - } |
|
957 | - $this->class_cache->addAlias($fqn, $alias); |
|
958 | - } |
|
959 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
960 | - $this->class_cache->addAlias( |
|
961 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
962 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
963 | - ); |
|
964 | - } |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - /** |
|
969 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
970 | - * request Primarily used by unit tests. |
|
971 | - */ |
|
972 | - public function reset() |
|
973 | - { |
|
974 | - $this->_register_core_class_loaders(); |
|
975 | - $this->_register_core_dependencies(); |
|
976 | - } |
|
977 | - |
|
978 | - |
|
979 | - /** |
|
980 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
981 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
982 | - * WHY? |
|
983 | - * Because if a class is type hinting for a concretion, |
|
984 | - * then why would we need to find another class to supply it? |
|
985 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
986 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
987 | - * Don't go looking for some substitute. |
|
988 | - * Whereas if a class is type hinting for an interface... |
|
989 | - * then we need to find an actual class to use. |
|
990 | - * So the interface IS the alias for some other FQN, |
|
991 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
992 | - * represents some other class. |
|
993 | - * |
|
994 | - * @deprecated 4.9.62.p |
|
995 | - * @param string $fqn |
|
996 | - * @param string $for_class |
|
997 | - * @return bool |
|
998 | - */ |
|
999 | - public function has_alias($fqn = '', $for_class = '') |
|
1000 | - { |
|
1001 | - return $this->isAlias($fqn, $for_class); |
|
1002 | - } |
|
1003 | - |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1007 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1008 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1009 | - * for example: |
|
1010 | - * if the following two entries were added to the _aliases array: |
|
1011 | - * array( |
|
1012 | - * 'interface_alias' => 'some\namespace\interface' |
|
1013 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1014 | - * ) |
|
1015 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1016 | - * to load an instance of 'some\namespace\classname' |
|
1017 | - * |
|
1018 | - * @deprecated 4.9.62.p |
|
1019 | - * @param string $alias |
|
1020 | - * @param string $for_class |
|
1021 | - * @return string |
|
1022 | - */ |
|
1023 | - public function get_alias($alias = '', $for_class = '') |
|
1024 | - { |
|
1025 | - return $this->getFqnForAlias($alias, $for_class); |
|
1026 | - } |
|
23 | + /** |
|
24 | + * This means that the requested class dependency is not present in the dependency map |
|
25 | + */ |
|
26 | + const not_registered = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | + */ |
|
31 | + const load_new_object = 1; |
|
32 | + |
|
33 | + /** |
|
34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | + */ |
|
37 | + const load_from_cache = 2; |
|
38 | + |
|
39 | + /** |
|
40 | + * When registering a dependency, |
|
41 | + * this indicates to keep any existing dependencies that already exist, |
|
42 | + * and simply discard any new dependencies declared in the incoming data |
|
43 | + */ |
|
44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * When registering a dependency, |
|
48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | + */ |
|
50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
51 | + |
|
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 = array(); |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = array(); |
|
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 | + */ |
|
109 | + public function initialize() |
|
110 | + { |
|
111 | + $this->_register_core_dependencies(); |
|
112 | + $this->_register_core_class_loaders(); |
|
113 | + $this->_register_core_aliases(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @singleton method used to instantiate class object |
|
119 | + * @param ClassInterfaceCache|null $class_cache |
|
120 | + * @return EE_Dependency_Map |
|
121 | + */ |
|
122 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | + { |
|
124 | + // check if class object is instantiated, and instantiated properly |
|
125 | + if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | + && $class_cache instanceof ClassInterfaceCache |
|
127 | + ) { |
|
128 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | + } |
|
130 | + return self::$_instance; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param RequestInterface $request |
|
136 | + */ |
|
137 | + public function setRequest(RequestInterface $request) |
|
138 | + { |
|
139 | + $this->request = $request; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param LegacyRequestInterface $legacy_request |
|
145 | + */ |
|
146 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | + { |
|
148 | + $this->legacy_request = $legacy_request; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param ResponseInterface $response |
|
154 | + */ |
|
155 | + public function setResponse(ResponseInterface $response) |
|
156 | + { |
|
157 | + $this->response = $response; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param LoaderInterface $loader |
|
163 | + */ |
|
164 | + public function setLoader(LoaderInterface $loader) |
|
165 | + { |
|
166 | + $this->loader = $loader; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $class |
|
172 | + * @param array $dependencies |
|
173 | + * @param int $overwrite |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public static function register_dependencies( |
|
177 | + $class, |
|
178 | + array $dependencies, |
|
179 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | + ) { |
|
181 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | + * to the class specified by the first parameter. |
|
188 | + * IMPORTANT !!! |
|
189 | + * The order of elements in the incoming $dependencies array MUST match |
|
190 | + * the order of the constructor parameters for the class in question. |
|
191 | + * This is especially important when overriding any existing dependencies that are registered. |
|
192 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | + * |
|
194 | + * @param string $class |
|
195 | + * @param array $dependencies |
|
196 | + * @param int $overwrite |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function registerDependencies( |
|
200 | + $class, |
|
201 | + array $dependencies, |
|
202 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | + ) { |
|
204 | + $class = trim($class, '\\'); |
|
205 | + $registered = false; |
|
206 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | + } |
|
209 | + // we need to make sure that any aliases used when registering a dependency |
|
210 | + // get resolved to the correct class name |
|
211 | + foreach ($dependencies as $dependency => $load_source) { |
|
212 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | + ) { |
|
216 | + unset($dependencies[ $dependency ]); |
|
217 | + $dependencies[ $alias ] = $load_source; |
|
218 | + $registered = true; |
|
219 | + } |
|
220 | + } |
|
221 | + // now add our two lists of dependencies together. |
|
222 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | + // so $dependencies is NOT overwritten because it is listed first |
|
224 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | + // Union is way faster than array_merge() but should be used with caution... |
|
226 | + // especially with numerically indexed arrays |
|
227 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | + // now we need to ensure that the resulting dependencies |
|
229 | + // array only has the entries that are required for the class |
|
230 | + // so first count how many dependencies were originally registered for the class |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | + // if that count is non-zero (meaning dependencies were already registered) |
|
233 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | + // then truncate the final array to match that count |
|
235 | + ? array_slice($dependencies, 0, $dependency_count) |
|
236 | + // otherwise just take the incoming array because nothing previously existed |
|
237 | + : $dependencies; |
|
238 | + return $registered; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $class_name |
|
244 | + * @param string $loader |
|
245 | + * @return bool |
|
246 | + * @throws DomainException |
|
247 | + */ |
|
248 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | + { |
|
250 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | + throw new DomainException( |
|
252 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | + ); |
|
254 | + } |
|
255 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | + if (! is_callable($loader) |
|
257 | + && ( |
|
258 | + strpos($loader, 'load_') !== 0 |
|
259 | + || ! method_exists('EE_Registry', $loader) |
|
260 | + ) |
|
261 | + ) { |
|
262 | + throw new DomainException( |
|
263 | + sprintf( |
|
264 | + esc_html__( |
|
265 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + $loader |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | + if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | + self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | + return true; |
|
276 | + } |
|
277 | + return false; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function dependency_map() |
|
285 | + { |
|
286 | + return $this->_dependency_map; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | + * |
|
293 | + * @param string $class_name |
|
294 | + * @return boolean |
|
295 | + */ |
|
296 | + public function has($class_name = '') |
|
297 | + { |
|
298 | + // all legacy models have the same dependencies |
|
299 | + if (strpos($class_name, 'EEM_') === 0) { |
|
300 | + $class_name = 'LEGACY_MODELS'; |
|
301 | + } |
|
302 | + return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | + * |
|
309 | + * @param string $class_name |
|
310 | + * @param string $dependency |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | + { |
|
315 | + // all legacy models have the same dependencies |
|
316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
317 | + $class_name = 'LEGACY_MODELS'; |
|
318 | + } |
|
319 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | + ? true |
|
322 | + : false; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | + * |
|
329 | + * @param string $class_name |
|
330 | + * @param string $dependency |
|
331 | + * @return int |
|
332 | + */ |
|
333 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | + { |
|
335 | + // all legacy models have the same dependencies |
|
336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
337 | + $class_name = 'LEGACY_MODELS'; |
|
338 | + } |
|
339 | + $dependency = $this->getFqnForAlias($dependency); |
|
340 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | + : EE_Dependency_Map::not_registered; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param string $class_name |
|
348 | + * @return string | Closure |
|
349 | + */ |
|
350 | + public function class_loader($class_name) |
|
351 | + { |
|
352 | + // all legacy models use load_model() |
|
353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
354 | + return 'load_model'; |
|
355 | + } |
|
356 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | + // perform strpos() first to avoid loading regex every time we load a class |
|
358 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | + ) { |
|
361 | + return 'load_core'; |
|
362 | + } |
|
363 | + $class_name = $this->getFqnForAlias($class_name); |
|
364 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function class_loaders() |
|
372 | + { |
|
373 | + return $this->_class_loaders; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * adds an alias for a classname |
|
379 | + * |
|
380 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | + */ |
|
384 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | + { |
|
386 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | + * WHY? |
|
393 | + * Because if a class is type hinting for a concretion, |
|
394 | + * then why would we need to find another class to supply it? |
|
395 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | + * Don't go looking for some substitute. |
|
398 | + * Whereas if a class is type hinting for an interface... |
|
399 | + * then we need to find an actual class to use. |
|
400 | + * So the interface IS the alias for some other FQN, |
|
401 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | + * represents some other class. |
|
403 | + * |
|
404 | + * @param string $fqn |
|
405 | + * @param string $for_class |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function isAlias($fqn = '', $for_class = '') |
|
409 | + { |
|
410 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | + * for example: |
|
418 | + * if the following two entries were added to the _aliases array: |
|
419 | + * array( |
|
420 | + * 'interface_alias' => 'some\namespace\interface' |
|
421 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | + * ) |
|
423 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | + * to load an instance of 'some\namespace\classname' |
|
425 | + * |
|
426 | + * @param string $alias |
|
427 | + * @param string $for_class |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | + { |
|
432 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | + * This is done by using the following class constants: |
|
440 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | + */ |
|
443 | + protected function _register_core_dependencies() |
|
444 | + { |
|
445 | + $this->_dependency_map = array( |
|
446 | + 'EE_Request_Handler' => array( |
|
447 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_System' => array( |
|
450 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EE_Session' => array( |
|
456 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_Cart' => array( |
|
462 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
463 | + ), |
|
464 | + 'EE_Front_Controller' => array( |
|
465 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
466 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
468 | + ), |
|
469 | + 'EE_Messenger_Collection_Loader' => array( |
|
470 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
471 | + ), |
|
472 | + 'EE_Message_Type_Collection_Loader' => array( |
|
473 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
474 | + ), |
|
475 | + 'EE_Message_Resource_Manager' => array( |
|
476 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
477 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EE_Message_Factory' => array( |
|
481 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
482 | + ), |
|
483 | + 'EE_messages' => array( |
|
484 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
485 | + ), |
|
486 | + 'EE_Messages_Generator' => array( |
|
487 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
488 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
489 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
491 | + ), |
|
492 | + 'EE_Messages_Processor' => array( |
|
493 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
494 | + ), |
|
495 | + 'EE_Messages_Queue' => array( |
|
496 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
497 | + ), |
|
498 | + 'EE_Messages_Template_Defaults' => array( |
|
499 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
500 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
501 | + ), |
|
502 | + 'EE_Message_To_Generate_From_Request' => array( |
|
503 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
504 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
505 | + ), |
|
506 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
507 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
508 | + ), |
|
509 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
510 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
511 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
512 | + ), |
|
513 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
514 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
515 | + ), |
|
516 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
517 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
518 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
519 | + ), |
|
520 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
521 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
522 | + ), |
|
523 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
524 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
525 | + ), |
|
526 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
527 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
528 | + ), |
|
529 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
530 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
531 | + ), |
|
532 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
533 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
534 | + ), |
|
535 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
536 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
537 | + ), |
|
538 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
539 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
540 | + ), |
|
541 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
542 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
543 | + ), |
|
544 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
545 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
546 | + ), |
|
547 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
548 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
549 | + ), |
|
550 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
551 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
552 | + ), |
|
553 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
554 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
555 | + ), |
|
556 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
557 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
558 | + ), |
|
559 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
560 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
561 | + ), |
|
562 | + 'EE_Data_Migration_Class_Base' => array( |
|
563 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
564 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
565 | + ), |
|
566 | + 'EE_DMS_Core_4_1_0' => array( |
|
567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | + ), |
|
570 | + 'EE_DMS_Core_4_2_0' => array( |
|
571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | + ), |
|
574 | + 'EE_DMS_Core_4_3_0' => array( |
|
575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | + ), |
|
578 | + 'EE_DMS_Core_4_4_0' => array( |
|
579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | + ), |
|
582 | + 'EE_DMS_Core_4_5_0' => array( |
|
583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | + ), |
|
586 | + 'EE_DMS_Core_4_6_0' => array( |
|
587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EE_DMS_Core_4_7_0' => array( |
|
591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | + ), |
|
594 | + 'EE_DMS_Core_4_8_0' => array( |
|
595 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
596 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
597 | + ), |
|
598 | + 'EE_DMS_Core_4_9_0' => array( |
|
599 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
600 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
603 | + array(), |
|
604 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
605 | + ), |
|
606 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
607 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
608 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
609 | + ), |
|
610 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
611 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
612 | + ), |
|
613 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
614 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
615 | + ), |
|
616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | + ), |
|
619 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
620 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | + ), |
|
622 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | + ), |
|
625 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
626 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | + ), |
|
628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
632 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
635 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
638 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
639 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
640 | + ), |
|
641 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
642 | + null, |
|
643 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
644 | + ), |
|
645 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
646 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
647 | + ), |
|
648 | + 'LEGACY_MODELS' => array( |
|
649 | + null, |
|
650 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
651 | + ), |
|
652 | + 'EE_Module_Request_Router' => array( |
|
653 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
654 | + ), |
|
655 | + 'EE_Registration_Processor' => array( |
|
656 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
657 | + ), |
|
658 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
659 | + null, |
|
660 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
661 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
662 | + ), |
|
663 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
664 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
665 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
666 | + ), |
|
667 | + 'EE_Admin_Transactions_List_Table' => array( |
|
668 | + null, |
|
669 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
670 | + ), |
|
671 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
672 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
673 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
674 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
675 | + ), |
|
676 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
677 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
678 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
679 | + ), |
|
680 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
681 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
682 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
683 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
684 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
685 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
686 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
687 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
688 | + ), |
|
689 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
690 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
691 | + ), |
|
692 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
693 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
694 | + ), |
|
695 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
696 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
697 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
698 | + ), |
|
699 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
700 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
701 | + ), |
|
702 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
703 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
704 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
705 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
706 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
707 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
708 | + ), |
|
709 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
710 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
711 | + ), |
|
712 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
713 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
714 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
715 | + ), |
|
716 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
717 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
718 | + ), |
|
719 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
720 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
721 | + ), |
|
722 | + 'EE_CPT_Strategy' => array( |
|
723 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
725 | + ), |
|
726 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
727 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
728 | + ), |
|
729 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
730 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
731 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
732 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
733 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
734 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
735 | + ), |
|
736 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
737 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
738 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
739 | + ), |
|
740 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
741 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
742 | + ), |
|
743 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
744 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
745 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
746 | + ), |
|
747 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
748 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
749 | + ), |
|
750 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
751 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
752 | + ), |
|
753 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
754 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
755 | + ), |
|
756 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
757 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
758 | + ), |
|
759 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
760 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
761 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
762 | + ), |
|
763 | + 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
764 | + null, |
|
765 | + null, |
|
766 | + null, |
|
767 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
768 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
769 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
770 | + ), |
|
771 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
772 | + 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
773 | + 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
774 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | + ), |
|
776 | + 'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array( |
|
777 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
778 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
779 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
780 | + ), |
|
781 | + 'EventEspresso\core\domain\entities\editor\blocks\widgets\EventAttendees' => array( |
|
782 | + 'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => self::load_from_cache, |
|
783 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => self::load_from_cache, |
|
784 | + ), |
|
785 | + ); |
|
786 | + } |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * Registers how core classes are loaded. |
|
791 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
792 | + * 'EE_Request_Handler' => 'load_core' |
|
793 | + * 'EE_Messages_Queue' => 'load_lib' |
|
794 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
795 | + * or, if greater control is required, by providing a custom closure. For example: |
|
796 | + * 'Some_Class' => function () { |
|
797 | + * return new Some_Class(); |
|
798 | + * }, |
|
799 | + * This is required for instantiating dependencies |
|
800 | + * where an interface has been type hinted in a class constructor. For example: |
|
801 | + * 'Required_Interface' => function () { |
|
802 | + * return new A_Class_That_Implements_Required_Interface(); |
|
803 | + * }, |
|
804 | + */ |
|
805 | + protected function _register_core_class_loaders() |
|
806 | + { |
|
807 | + // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
808 | + // be used in a closure. |
|
809 | + $request = &$this->request; |
|
810 | + $response = &$this->response; |
|
811 | + $legacy_request = &$this->legacy_request; |
|
812 | + // $loader = &$this->loader; |
|
813 | + $this->_class_loaders = array( |
|
814 | + // load_core |
|
815 | + 'EE_Capabilities' => 'load_core', |
|
816 | + 'EE_Encryption' => 'load_core', |
|
817 | + 'EE_Front_Controller' => 'load_core', |
|
818 | + 'EE_Module_Request_Router' => 'load_core', |
|
819 | + 'EE_Registry' => 'load_core', |
|
820 | + 'EE_Request' => function () use (&$legacy_request) { |
|
821 | + return $legacy_request; |
|
822 | + }, |
|
823 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
824 | + return $request; |
|
825 | + }, |
|
826 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
827 | + return $response; |
|
828 | + }, |
|
829 | + 'EE_Base' => 'load_core', |
|
830 | + 'EE_Request_Handler' => 'load_core', |
|
831 | + 'EE_Session' => 'load_core', |
|
832 | + 'EE_Cron_Tasks' => 'load_core', |
|
833 | + 'EE_System' => 'load_core', |
|
834 | + 'EE_Maintenance_Mode' => 'load_core', |
|
835 | + 'EE_Register_CPTs' => 'load_core', |
|
836 | + 'EE_Admin' => 'load_core', |
|
837 | + 'EE_CPT_Strategy' => 'load_core', |
|
838 | + // load_lib |
|
839 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
840 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
841 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
842 | + 'EE_Messenger_Collection' => 'load_lib', |
|
843 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
844 | + 'EE_Messages_Processor' => 'load_lib', |
|
845 | + 'EE_Message_Repository' => 'load_lib', |
|
846 | + 'EE_Messages_Queue' => 'load_lib', |
|
847 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
848 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
849 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
850 | + 'EE_Messages_Generator' => function () { |
|
851 | + return EE_Registry::instance()->load_lib( |
|
852 | + 'Messages_Generator', |
|
853 | + array(), |
|
854 | + false, |
|
855 | + false |
|
856 | + ); |
|
857 | + }, |
|
858 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
859 | + return EE_Registry::instance()->load_lib( |
|
860 | + 'Messages_Template_Defaults', |
|
861 | + $arguments, |
|
862 | + false, |
|
863 | + false |
|
864 | + ); |
|
865 | + }, |
|
866 | + // load_helper |
|
867 | + 'EEH_Parse_Shortcodes' => function () { |
|
868 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
869 | + return new EEH_Parse_Shortcodes(); |
|
870 | + } |
|
871 | + return null; |
|
872 | + }, |
|
873 | + 'EE_Template_Config' => function () { |
|
874 | + return EE_Config::instance()->template_settings; |
|
875 | + }, |
|
876 | + 'EE_Currency_Config' => function () { |
|
877 | + return EE_Config::instance()->currency; |
|
878 | + }, |
|
879 | + 'EE_Registration_Config' => function () { |
|
880 | + return EE_Config::instance()->registration; |
|
881 | + }, |
|
882 | + 'EE_Core_Config' => function () { |
|
883 | + return EE_Config::instance()->core; |
|
884 | + }, |
|
885 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
886 | + return LoaderFactory::getLoader(); |
|
887 | + }, |
|
888 | + 'EE_Network_Config' => function () { |
|
889 | + return EE_Network_Config::instance(); |
|
890 | + }, |
|
891 | + 'EE_Config' => function () { |
|
892 | + return EE_Config::instance(); |
|
893 | + }, |
|
894 | + 'EventEspresso\core\domain\Domain' => function () { |
|
895 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
896 | + }, |
|
897 | + 'EE_Admin_Config' => function () { |
|
898 | + return EE_Config::instance()->admin; |
|
899 | + }, |
|
900 | + ); |
|
901 | + } |
|
902 | + |
|
903 | + |
|
904 | + /** |
|
905 | + * can be used for supplying alternate names for classes, |
|
906 | + * or for connecting interface names to instantiable classes |
|
907 | + */ |
|
908 | + protected function _register_core_aliases() |
|
909 | + { |
|
910 | + $aliases = array( |
|
911 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
912 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
913 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
914 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
915 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
916 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
917 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
918 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
919 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
920 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
921 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
922 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
923 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
924 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
925 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
926 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
927 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
928 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
929 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
930 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
931 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
932 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
933 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
934 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
935 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
936 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
937 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
938 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
939 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
940 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
941 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
942 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
943 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
944 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
945 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
946 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
947 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
948 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
949 | + ); |
|
950 | + foreach ($aliases as $alias => $fqn) { |
|
951 | + if (is_array($fqn)) { |
|
952 | + foreach ($fqn as $class => $for_class) { |
|
953 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
954 | + } |
|
955 | + continue; |
|
956 | + } |
|
957 | + $this->class_cache->addAlias($fqn, $alias); |
|
958 | + } |
|
959 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
960 | + $this->class_cache->addAlias( |
|
961 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
962 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
963 | + ); |
|
964 | + } |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + /** |
|
969 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
970 | + * request Primarily used by unit tests. |
|
971 | + */ |
|
972 | + public function reset() |
|
973 | + { |
|
974 | + $this->_register_core_class_loaders(); |
|
975 | + $this->_register_core_dependencies(); |
|
976 | + } |
|
977 | + |
|
978 | + |
|
979 | + /** |
|
980 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
981 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
982 | + * WHY? |
|
983 | + * Because if a class is type hinting for a concretion, |
|
984 | + * then why would we need to find another class to supply it? |
|
985 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
986 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
987 | + * Don't go looking for some substitute. |
|
988 | + * Whereas if a class is type hinting for an interface... |
|
989 | + * then we need to find an actual class to use. |
|
990 | + * So the interface IS the alias for some other FQN, |
|
991 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
992 | + * represents some other class. |
|
993 | + * |
|
994 | + * @deprecated 4.9.62.p |
|
995 | + * @param string $fqn |
|
996 | + * @param string $for_class |
|
997 | + * @return bool |
|
998 | + */ |
|
999 | + public function has_alias($fqn = '', $for_class = '') |
|
1000 | + { |
|
1001 | + return $this->isAlias($fqn, $for_class); |
|
1002 | + } |
|
1003 | + |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1007 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1008 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1009 | + * for example: |
|
1010 | + * if the following two entries were added to the _aliases array: |
|
1011 | + * array( |
|
1012 | + * 'interface_alias' => 'some\namespace\interface' |
|
1013 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1014 | + * ) |
|
1015 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1016 | + * to load an instance of 'some\namespace\classname' |
|
1017 | + * |
|
1018 | + * @deprecated 4.9.62.p |
|
1019 | + * @param string $alias |
|
1020 | + * @param string $for_class |
|
1021 | + * @return string |
|
1022 | + */ |
|
1023 | + public function get_alias($alias = '', $for_class = '') |
|
1024 | + { |
|
1025 | + return $this->getFqnForAlias($alias, $for_class); |
|
1026 | + } |
|
1027 | 1027 | } |
@@ -23,1668 +23,1668 @@ |
||
23 | 23 | class EE_Registry implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registry $_instance |
|
28 | - */ |
|
29 | - private static $_instance; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EE_Dependency_Map $_dependency_map |
|
33 | - */ |
|
34 | - protected $_dependency_map; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Mirror |
|
38 | - */ |
|
39 | - private $mirror; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ClassInterfaceCache $class_cache |
|
43 | - */ |
|
44 | - private $class_cache; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array $_class_abbreviations |
|
48 | - */ |
|
49 | - protected $_class_abbreviations = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * @var CommandBusInterface $BUS |
|
53 | - */ |
|
54 | - public $BUS; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var EE_Cart $CART |
|
58 | - */ |
|
59 | - public $CART; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var EE_Config $CFG |
|
63 | - */ |
|
64 | - public $CFG; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var EE_Network_Config $NET_CFG |
|
68 | - */ |
|
69 | - public $NET_CFG; |
|
70 | - |
|
71 | - /** |
|
72 | - * StdClass object for storing library classes in |
|
73 | - * |
|
74 | - * @var RegistryContainer $LIB |
|
75 | - */ |
|
76 | - public $LIB; |
|
77 | - |
|
78 | - /** |
|
79 | - * @var EE_Request_Handler $REQ |
|
80 | - */ |
|
81 | - public $REQ; |
|
82 | - |
|
83 | - /** |
|
84 | - * @var EE_Session $SSN |
|
85 | - */ |
|
86 | - public $SSN; |
|
87 | - |
|
88 | - /** |
|
89 | - * @since 4.5.0 |
|
90 | - * @var EE_Capabilities $CAP |
|
91 | - */ |
|
92 | - public $CAP; |
|
93 | - |
|
94 | - /** |
|
95 | - * @since 4.9.0 |
|
96 | - * @var EE_Message_Resource_Manager $MRM |
|
97 | - */ |
|
98 | - public $MRM; |
|
99 | - |
|
100 | - /** |
|
101 | - * @var Registry $AssetsRegistry |
|
102 | - */ |
|
103 | - public $AssetsRegistry; |
|
104 | - |
|
105 | - /** |
|
106 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
107 | - * |
|
108 | - * @var EE_Addon[] $addons |
|
109 | - */ |
|
110 | - public $addons; |
|
111 | - |
|
112 | - /** |
|
113 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
114 | - * |
|
115 | - * @var EEM_Base[] $models |
|
116 | - */ |
|
117 | - public $models = array(); |
|
118 | - |
|
119 | - /** |
|
120 | - * @var EED_Module[] $modules |
|
121 | - */ |
|
122 | - public $modules; |
|
123 | - |
|
124 | - /** |
|
125 | - * @var EES_Shortcode[] $shortcodes |
|
126 | - */ |
|
127 | - public $shortcodes; |
|
128 | - |
|
129 | - /** |
|
130 | - * @var WP_Widget[] $widgets |
|
131 | - */ |
|
132 | - public $widgets; |
|
133 | - |
|
134 | - /** |
|
135 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
136 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
137 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
138 | - * classnames (eg "EEM_Event") |
|
139 | - * |
|
140 | - * @var array $non_abstract_db_models |
|
141 | - */ |
|
142 | - public $non_abstract_db_models = array(); |
|
143 | - |
|
144 | - /** |
|
145 | - * internationalization for JS strings |
|
146 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
147 | - * in js file: var translatedString = eei18n.string_key; |
|
148 | - * |
|
149 | - * @var array $i18n_js_strings |
|
150 | - */ |
|
151 | - public static $i18n_js_strings = array(); |
|
152 | - |
|
153 | - /** |
|
154 | - * $main_file - path to espresso.php |
|
155 | - * |
|
156 | - * @var array $main_file |
|
157 | - */ |
|
158 | - public $main_file; |
|
159 | - |
|
160 | - /** |
|
161 | - * array of ReflectionClass objects where the key is the class name |
|
162 | - * |
|
163 | - * @deprecated 4.9.62.p |
|
164 | - * @var ReflectionClass[] $_reflectors |
|
165 | - */ |
|
166 | - public $_reflectors; |
|
167 | - |
|
168 | - /** |
|
169 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
170 | - * |
|
171 | - * @var boolean $_cache_on |
|
172 | - */ |
|
173 | - protected $_cache_on = true; |
|
174 | - |
|
175 | - /** |
|
176 | - * @var ObjectIdentifier |
|
177 | - */ |
|
178 | - private $object_identifier; |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @singleton method used to instantiate class object |
|
183 | - * @param EE_Dependency_Map|null $dependency_map |
|
184 | - * @param Mirror|null $mirror |
|
185 | - * @param ClassInterfaceCache|null $class_cache |
|
186 | - * @param ObjectIdentifier|null $object_identifier |
|
187 | - * @return EE_Registry instance |
|
188 | - */ |
|
189 | - public static function instance( |
|
190 | - EE_Dependency_Map $dependency_map = null, |
|
191 | - Mirror $mirror = null, |
|
192 | - ClassInterfaceCache $class_cache = null, |
|
193 | - ObjectIdentifier $object_identifier = null |
|
194 | - ) { |
|
195 | - // check if class object is instantiated |
|
196 | - if (! self::$_instance instanceof EE_Registry |
|
197 | - && $dependency_map instanceof EE_Dependency_Map |
|
198 | - && $mirror instanceof Mirror |
|
199 | - && $class_cache instanceof ClassInterfaceCache |
|
200 | - && $object_identifier instanceof ObjectIdentifier |
|
201 | - ) { |
|
202 | - self::$_instance = new self( |
|
203 | - $dependency_map, |
|
204 | - $mirror, |
|
205 | - $class_cache, |
|
206 | - $object_identifier |
|
207 | - ); |
|
208 | - } |
|
209 | - return self::$_instance; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * protected constructor to prevent direct creation |
|
215 | - * |
|
216 | - * @Constructor |
|
217 | - * @param EE_Dependency_Map $dependency_map |
|
218 | - * @param Mirror $mirror |
|
219 | - * @param ClassInterfaceCache $class_cache |
|
220 | - * @param ObjectIdentifier $object_identifier |
|
221 | - */ |
|
222 | - protected function __construct( |
|
223 | - EE_Dependency_Map $dependency_map, |
|
224 | - Mirror $mirror, |
|
225 | - ClassInterfaceCache $class_cache, |
|
226 | - ObjectIdentifier $object_identifier |
|
227 | - ) { |
|
228 | - $this->_dependency_map = $dependency_map; |
|
229 | - $this->mirror = $mirror; |
|
230 | - $this->class_cache = $class_cache; |
|
231 | - $this->object_identifier = $object_identifier; |
|
232 | - // $registry_container = new RegistryContainer(); |
|
233 | - $this->LIB = new RegistryContainer(); |
|
234 | - $this->addons = new RegistryContainer(); |
|
235 | - $this->modules = new RegistryContainer(); |
|
236 | - $this->shortcodes = new RegistryContainer(); |
|
237 | - $this->widgets = new RegistryContainer(); |
|
238 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * initialize |
|
244 | - * |
|
245 | - * @throws OutOfBoundsException |
|
246 | - * @throws InvalidArgumentException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - * @throws InvalidDataTypeException |
|
249 | - * @throws EE_Error |
|
250 | - * @throws ReflectionException |
|
251 | - */ |
|
252 | - public function initialize() |
|
253 | - { |
|
254 | - $this->_class_abbreviations = apply_filters( |
|
255 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
256 | - array( |
|
257 | - 'EE_Config' => 'CFG', |
|
258 | - 'EE_Session' => 'SSN', |
|
259 | - 'EE_Capabilities' => 'CAP', |
|
260 | - 'EE_Cart' => 'CART', |
|
261 | - 'EE_Network_Config' => 'NET_CFG', |
|
262 | - 'EE_Request_Handler' => 'REQ', |
|
263 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
264 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
265 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
266 | - ) |
|
267 | - ); |
|
268 | - $this->load_core('Base', array(), true); |
|
269 | - // add our request and response objects to the cache |
|
270 | - $request_loader = $this->_dependency_map->class_loader( |
|
271 | - 'EventEspresso\core\services\request\Request' |
|
272 | - ); |
|
273 | - $this->_set_cached_class( |
|
274 | - $request_loader(), |
|
275 | - 'EventEspresso\core\services\request\Request' |
|
276 | - ); |
|
277 | - $response_loader = $this->_dependency_map->class_loader( |
|
278 | - 'EventEspresso\core\services\request\Response' |
|
279 | - ); |
|
280 | - $this->_set_cached_class( |
|
281 | - $response_loader(), |
|
282 | - 'EventEspresso\core\services\request\Response' |
|
283 | - ); |
|
284 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @return void |
|
290 | - */ |
|
291 | - public function init() |
|
292 | - { |
|
293 | - // Get current page protocol |
|
294 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
295 | - // Output admin-ajax.php URL with same protocol as current page |
|
296 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
297 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * localize_i18n_js_strings |
|
303 | - * |
|
304 | - * @return string |
|
305 | - */ |
|
306 | - public static function localize_i18n_js_strings() |
|
307 | - { |
|
308 | - $i18n_js_strings = (array) self::$i18n_js_strings; |
|
309 | - foreach ($i18n_js_strings as $key => $value) { |
|
310 | - if (is_scalar($value)) { |
|
311 | - $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | - } |
|
313 | - } |
|
314 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @param mixed string | EED_Module $module |
|
320 | - * @throws OutOfBoundsException |
|
321 | - * @throws InvalidArgumentException |
|
322 | - * @throws InvalidInterfaceException |
|
323 | - * @throws InvalidDataTypeException |
|
324 | - * @throws EE_Error |
|
325 | - * @throws ReflectionException |
|
326 | - */ |
|
327 | - public function add_module($module) |
|
328 | - { |
|
329 | - if ($module instanceof EED_Module) { |
|
330 | - $module_class = get_class($module); |
|
331 | - $this->modules->{$module_class} = $module; |
|
332 | - } else { |
|
333 | - if (! class_exists('EE_Module_Request_Router', false)) { |
|
334 | - $this->load_core('Module_Request_Router'); |
|
335 | - } |
|
336 | - EE_Module_Request_Router::module_factory($module); |
|
337 | - } |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * @param string $module_name |
|
343 | - * @return mixed EED_Module | NULL |
|
344 | - */ |
|
345 | - public function get_module($module_name = '') |
|
346 | - { |
|
347 | - return isset($this->modules->{$module_name}) |
|
348 | - ? $this->modules->{$module_name} |
|
349 | - : null; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * loads core classes - must be singletons |
|
355 | - * |
|
356 | - * @param string $class_name - simple class name ie: session |
|
357 | - * @param mixed $arguments |
|
358 | - * @param bool $load_only |
|
359 | - * @return mixed |
|
360 | - * @throws InvalidInterfaceException |
|
361 | - * @throws InvalidDataTypeException |
|
362 | - * @throws EE_Error |
|
363 | - * @throws ReflectionException |
|
364 | - * @throws InvalidArgumentException |
|
365 | - */ |
|
366 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
367 | - { |
|
368 | - $core_paths = apply_filters( |
|
369 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
370 | - array( |
|
371 | - EE_CORE, |
|
372 | - EE_ADMIN, |
|
373 | - EE_CPTS, |
|
374 | - EE_CORE . 'data_migration_scripts' . DS, |
|
375 | - EE_CORE . 'capabilities' . DS, |
|
376 | - EE_CORE . 'request_stack' . DS, |
|
377 | - EE_CORE . 'middleware' . DS, |
|
378 | - ) |
|
379 | - ); |
|
380 | - // retrieve instantiated class |
|
381 | - return $this->_load( |
|
382 | - $core_paths, |
|
383 | - 'EE_', |
|
384 | - $class_name, |
|
385 | - 'core', |
|
386 | - $arguments, |
|
387 | - false, |
|
388 | - true, |
|
389 | - $load_only |
|
390 | - ); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * loads service classes |
|
396 | - * |
|
397 | - * @param string $class_name - simple class name ie: session |
|
398 | - * @param mixed $arguments |
|
399 | - * @param bool $load_only |
|
400 | - * @return mixed |
|
401 | - * @throws InvalidInterfaceException |
|
402 | - * @throws InvalidDataTypeException |
|
403 | - * @throws EE_Error |
|
404 | - * @throws ReflectionException |
|
405 | - * @throws InvalidArgumentException |
|
406 | - */ |
|
407 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
408 | - { |
|
409 | - $service_paths = apply_filters( |
|
410 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
411 | - array( |
|
412 | - EE_CORE . 'services' . DS, |
|
413 | - ) |
|
414 | - ); |
|
415 | - // retrieve instantiated class |
|
416 | - return $this->_load( |
|
417 | - $service_paths, |
|
418 | - 'EE_', |
|
419 | - $class_name, |
|
420 | - 'class', |
|
421 | - $arguments, |
|
422 | - false, |
|
423 | - true, |
|
424 | - $load_only |
|
425 | - ); |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * loads data_migration_scripts |
|
431 | - * |
|
432 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
433 | - * @param mixed $arguments |
|
434 | - * @return EE_Data_Migration_Script_Base|mixed |
|
435 | - * @throws InvalidInterfaceException |
|
436 | - * @throws InvalidDataTypeException |
|
437 | - * @throws EE_Error |
|
438 | - * @throws ReflectionException |
|
439 | - * @throws InvalidArgumentException |
|
440 | - */ |
|
441 | - public function load_dms($class_name, $arguments = array()) |
|
442 | - { |
|
443 | - // retrieve instantiated class |
|
444 | - return $this->_load( |
|
445 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
446 | - 'EE_DMS_', |
|
447 | - $class_name, |
|
448 | - 'dms', |
|
449 | - $arguments, |
|
450 | - false, |
|
451 | - false |
|
452 | - ); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * loads object creating classes - must be singletons |
|
458 | - * |
|
459 | - * @param string $class_name - simple class name ie: attendee |
|
460 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
461 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
462 | - * instantiate |
|
463 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
464 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
465 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
466 | - * (default) |
|
467 | - * @return EE_Base_Class | bool |
|
468 | - * @throws InvalidInterfaceException |
|
469 | - * @throws InvalidDataTypeException |
|
470 | - * @throws EE_Error |
|
471 | - * @throws ReflectionException |
|
472 | - * @throws InvalidArgumentException |
|
473 | - */ |
|
474 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
475 | - { |
|
476 | - $paths = apply_filters( |
|
477 | - 'FHEE__EE_Registry__load_class__paths', |
|
478 | - array( |
|
479 | - EE_CORE, |
|
480 | - EE_CLASSES, |
|
481 | - EE_BUSINESS, |
|
482 | - ) |
|
483 | - ); |
|
484 | - // retrieve instantiated class |
|
485 | - return $this->_load( |
|
486 | - $paths, |
|
487 | - 'EE_', |
|
488 | - $class_name, |
|
489 | - 'class', |
|
490 | - $arguments, |
|
491 | - $from_db, |
|
492 | - $cache, |
|
493 | - $load_only |
|
494 | - ); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * loads helper classes - must be singletons |
|
500 | - * |
|
501 | - * @param string $class_name - simple class name ie: price |
|
502 | - * @param mixed $arguments |
|
503 | - * @param bool $load_only |
|
504 | - * @return EEH_Base | bool |
|
505 | - * @throws InvalidInterfaceException |
|
506 | - * @throws InvalidDataTypeException |
|
507 | - * @throws EE_Error |
|
508 | - * @throws ReflectionException |
|
509 | - * @throws InvalidArgumentException |
|
510 | - */ |
|
511 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
512 | - { |
|
513 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
514 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
515 | - // retrieve instantiated class |
|
516 | - return $this->_load( |
|
517 | - $helper_paths, |
|
518 | - 'EEH_', |
|
519 | - $class_name, |
|
520 | - 'helper', |
|
521 | - $arguments, |
|
522 | - false, |
|
523 | - true, |
|
524 | - $load_only |
|
525 | - ); |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * loads core classes - must be singletons |
|
531 | - * |
|
532 | - * @param string $class_name - simple class name ie: session |
|
533 | - * @param mixed $arguments |
|
534 | - * @param bool $load_only |
|
535 | - * @param bool $cache whether to cache the object or not. |
|
536 | - * @return mixed |
|
537 | - * @throws InvalidInterfaceException |
|
538 | - * @throws InvalidDataTypeException |
|
539 | - * @throws EE_Error |
|
540 | - * @throws ReflectionException |
|
541 | - * @throws InvalidArgumentException |
|
542 | - */ |
|
543 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
544 | - { |
|
545 | - $paths = array( |
|
546 | - EE_LIBRARIES, |
|
547 | - EE_LIBRARIES . 'messages' . DS, |
|
548 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
549 | - EE_LIBRARIES . 'qtips' . DS, |
|
550 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
551 | - ); |
|
552 | - // retrieve instantiated class |
|
553 | - return $this->_load( |
|
554 | - $paths, |
|
555 | - 'EE_', |
|
556 | - $class_name, |
|
557 | - 'lib', |
|
558 | - $arguments, |
|
559 | - false, |
|
560 | - $cache, |
|
561 | - $load_only |
|
562 | - ); |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * loads model classes - must be singletons |
|
568 | - * |
|
569 | - * @param string $class_name - simple class name ie: price |
|
570 | - * @param mixed $arguments |
|
571 | - * @param bool $load_only |
|
572 | - * @return EEM_Base | bool |
|
573 | - * @throws InvalidInterfaceException |
|
574 | - * @throws InvalidDataTypeException |
|
575 | - * @throws EE_Error |
|
576 | - * @throws ReflectionException |
|
577 | - * @throws InvalidArgumentException |
|
578 | - */ |
|
579 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
580 | - { |
|
581 | - $paths = apply_filters( |
|
582 | - 'FHEE__EE_Registry__load_model__paths', |
|
583 | - array( |
|
584 | - EE_MODELS, |
|
585 | - EE_CORE, |
|
586 | - ) |
|
587 | - ); |
|
588 | - // retrieve instantiated class |
|
589 | - return $this->_load( |
|
590 | - $paths, |
|
591 | - 'EEM_', |
|
592 | - $class_name, |
|
593 | - 'model', |
|
594 | - $arguments, |
|
595 | - false, |
|
596 | - true, |
|
597 | - $load_only |
|
598 | - ); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * loads model classes - must be singletons |
|
604 | - * |
|
605 | - * @param string $class_name - simple class name ie: price |
|
606 | - * @param mixed $arguments |
|
607 | - * @param bool $load_only |
|
608 | - * @return mixed | bool |
|
609 | - * @throws InvalidInterfaceException |
|
610 | - * @throws InvalidDataTypeException |
|
611 | - * @throws EE_Error |
|
612 | - * @throws ReflectionException |
|
613 | - * @throws InvalidArgumentException |
|
614 | - */ |
|
615 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
616 | - { |
|
617 | - $paths = array( |
|
618 | - EE_MODELS . 'fields' . DS, |
|
619 | - EE_MODELS . 'helpers' . DS, |
|
620 | - EE_MODELS . 'relations' . DS, |
|
621 | - EE_MODELS . 'strategies' . DS, |
|
622 | - ); |
|
623 | - // retrieve instantiated class |
|
624 | - return $this->_load( |
|
625 | - $paths, |
|
626 | - 'EE_', |
|
627 | - $class_name, |
|
628 | - '', |
|
629 | - $arguments, |
|
630 | - false, |
|
631 | - true, |
|
632 | - $load_only |
|
633 | - ); |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - /** |
|
638 | - * Determines if $model_name is the name of an actual EE model. |
|
639 | - * |
|
640 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
641 | - * @return boolean |
|
642 | - */ |
|
643 | - public function is_model_name($model_name) |
|
644 | - { |
|
645 | - return isset($this->models[ $model_name ]); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * generic class loader |
|
651 | - * |
|
652 | - * @param string $path_to_file - directory path to file location, not including filename |
|
653 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
654 | - * @param string $type - file type - core? class? helper? model? |
|
655 | - * @param mixed $arguments |
|
656 | - * @param bool $load_only |
|
657 | - * @return mixed |
|
658 | - * @throws InvalidInterfaceException |
|
659 | - * @throws InvalidDataTypeException |
|
660 | - * @throws EE_Error |
|
661 | - * @throws ReflectionException |
|
662 | - * @throws InvalidArgumentException |
|
663 | - */ |
|
664 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
665 | - { |
|
666 | - // retrieve instantiated class |
|
667 | - return $this->_load( |
|
668 | - $path_to_file, |
|
669 | - '', |
|
670 | - $file_name, |
|
671 | - $type, |
|
672 | - $arguments, |
|
673 | - false, |
|
674 | - true, |
|
675 | - $load_only |
|
676 | - ); |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * @param string $path_to_file - directory path to file location, not including filename |
|
682 | - * @param string $class_name - full class name ie: My_Class |
|
683 | - * @param string $type - file type - core? class? helper? model? |
|
684 | - * @param mixed $arguments |
|
685 | - * @param bool $load_only |
|
686 | - * @return bool|EE_Addon|object |
|
687 | - * @throws InvalidInterfaceException |
|
688 | - * @throws InvalidDataTypeException |
|
689 | - * @throws EE_Error |
|
690 | - * @throws ReflectionException |
|
691 | - * @throws InvalidArgumentException |
|
692 | - */ |
|
693 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
694 | - { |
|
695 | - // retrieve instantiated class |
|
696 | - return $this->_load( |
|
697 | - $path_to_file, |
|
698 | - 'addon', |
|
699 | - $class_name, |
|
700 | - $type, |
|
701 | - $arguments, |
|
702 | - false, |
|
703 | - true, |
|
704 | - $load_only |
|
705 | - ); |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * instantiates, caches, and automatically resolves dependencies |
|
711 | - * for classes that use a Fully Qualified Class Name. |
|
712 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
713 | - * then you need to use one of the existing load_*() methods |
|
714 | - * which can resolve the classname and filepath from the passed arguments |
|
715 | - * |
|
716 | - * @param bool|string $class_name Fully Qualified Class Name |
|
717 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
718 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
719 | - * @param bool $from_db some classes are instantiated from the db |
|
720 | - * and thus call a different method to instantiate |
|
721 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
722 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
723 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
724 | - * object = class loaded and instantiated successfully. |
|
725 | - * bool = fail or success when $load_only is true |
|
726 | - * @throws InvalidInterfaceException |
|
727 | - * @throws InvalidDataTypeException |
|
728 | - * @throws EE_Error |
|
729 | - * @throws ReflectionException |
|
730 | - * @throws InvalidArgumentException |
|
731 | - */ |
|
732 | - public function create( |
|
733 | - $class_name = false, |
|
734 | - $arguments = array(), |
|
735 | - $cache = false, |
|
736 | - $from_db = false, |
|
737 | - $load_only = false, |
|
738 | - $addon = false |
|
739 | - ) { |
|
740 | - $class_name = ltrim($class_name, '\\'); |
|
741 | - $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
742 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
743 | - // if a non-FQCN was passed, then |
|
744 | - // verifyClassExists() might return an object |
|
745 | - // or it could return null if the class just could not be found anywhere |
|
746 | - if ($class_exists instanceof $class_name || $class_exists === null) { |
|
747 | - // either way, return the results |
|
748 | - return $class_exists; |
|
749 | - } |
|
750 | - $class_name = $class_exists; |
|
751 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
752 | - if ($load_only) { |
|
753 | - return true; |
|
754 | - } |
|
755 | - $addon = $addon ? 'addon' : ''; |
|
756 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
757 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
758 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
759 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
760 | - // return object if it's already cached |
|
761 | - $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); |
|
762 | - if ($cached_class !== null) { |
|
763 | - return $cached_class; |
|
764 | - } |
|
765 | - }// obtain the loader method from the dependency map |
|
766 | - $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
767 | - if ($loader instanceof Closure) { |
|
768 | - $class_obj = $loader($arguments); |
|
769 | - } else { |
|
770 | - if ($loader && method_exists($this, $loader)) { |
|
771 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
772 | - } else { |
|
773 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
774 | - } |
|
775 | - } |
|
776 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
777 | - // save it for later... kinda like gum { : $ |
|
778 | - $this->_set_cached_class( |
|
779 | - $class_obj, |
|
780 | - $class_name, |
|
781 | - $addon, |
|
782 | - $from_db, |
|
783 | - $arguments |
|
784 | - ); |
|
785 | - } |
|
786 | - $this->_cache_on = true; |
|
787 | - return $class_obj; |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - /** |
|
792 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
793 | - * |
|
794 | - * @param string|object $class_name |
|
795 | - * @param array $arguments |
|
796 | - * @param int $attempt |
|
797 | - * @return mixed |
|
798 | - */ |
|
799 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
|
800 | - { |
|
801 | - if (is_object($class_name) || class_exists($class_name)) { |
|
802 | - return $class_name; |
|
803 | - } |
|
804 | - switch ($attempt) { |
|
805 | - case 1: |
|
806 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
807 | - $class_name = strpos($class_name, '\\') !== false |
|
808 | - ? '\\' . ltrim($class_name, '\\') |
|
809 | - : $class_name; |
|
810 | - break; |
|
811 | - case 2: |
|
812 | - // |
|
813 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
814 | - if ($loader && method_exists($this, $loader)) { |
|
815 | - return $this->{$loader}($class_name, $arguments); |
|
816 | - } |
|
817 | - break; |
|
818 | - case 3: |
|
819 | - default: |
|
820 | - return null; |
|
821 | - } |
|
822 | - $attempt++; |
|
823 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * instantiates, caches, and injects dependencies for classes |
|
829 | - * |
|
830 | - * @param array $file_paths an array of paths to folders to look in |
|
831 | - * @param string $class_prefix EE or EEM or... ??? |
|
832 | - * @param bool|string $class_name $class name |
|
833 | - * @param string $type file type - core? class? helper? model? |
|
834 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
835 | - * @param bool $from_db some classes are instantiated from the db |
|
836 | - * and thus call a different method to instantiate |
|
837 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
838 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
839 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
840 | - * object = class loaded and instantiated successfully. |
|
841 | - * bool = fail or success when $load_only is true |
|
842 | - * @throws EE_Error |
|
843 | - * @throws ReflectionException |
|
844 | - * @throws InvalidInterfaceException |
|
845 | - * @throws InvalidDataTypeException |
|
846 | - * @throws InvalidArgumentException |
|
847 | - */ |
|
848 | - protected function _load( |
|
849 | - $file_paths = array(), |
|
850 | - $class_prefix = 'EE_', |
|
851 | - $class_name = false, |
|
852 | - $type = 'class', |
|
853 | - $arguments = array(), |
|
854 | - $from_db = false, |
|
855 | - $cache = true, |
|
856 | - $load_only = false |
|
857 | - ) { |
|
858 | - $class_name = ltrim($class_name, '\\'); |
|
859 | - // strip php file extension |
|
860 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
861 | - // does the class have a prefix ? |
|
862 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
863 | - // make sure $class_prefix is uppercase |
|
864 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
865 | - // add class prefix ONCE!!! |
|
866 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
867 | - } |
|
868 | - $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
869 | - $class_exists = class_exists($class_name, false); |
|
870 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
871 | - if ($load_only && $class_exists) { |
|
872 | - return true; |
|
873 | - } |
|
874 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
875 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
876 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
877 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
878 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
879 | - // return object if it's already cached |
|
880 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); |
|
881 | - if ($cached_class !== null) { |
|
882 | - return $cached_class; |
|
883 | - } |
|
884 | - } |
|
885 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
886 | - if (! $class_exists) { |
|
887 | - // get full path to file |
|
888 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
889 | - // load the file |
|
890 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
891 | - // if we are only loading a file but NOT instantiating an object |
|
892 | - // then return boolean for whether class was loaded or not |
|
893 | - if ($load_only) { |
|
894 | - return $loaded; |
|
895 | - } |
|
896 | - // if an object was expected but loading failed, then return nothing |
|
897 | - if (! $loaded) { |
|
898 | - return null; |
|
899 | - } |
|
900 | - } |
|
901 | - // instantiate the requested object |
|
902 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
903 | - if ($this->_cache_on && $cache) { |
|
904 | - // save it for later... kinda like gum { : $ |
|
905 | - $this->_set_cached_class( |
|
906 | - $class_obj, |
|
907 | - $class_name, |
|
908 | - $class_prefix, |
|
909 | - $from_db, |
|
910 | - $arguments |
|
911 | - ); |
|
912 | - } |
|
913 | - $this->_cache_on = true; |
|
914 | - return $class_obj; |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * @param string $class_name |
|
920 | - * @param string $default have to specify something, but not anything that will conflict |
|
921 | - * @return mixed|string |
|
922 | - */ |
|
923 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
924 | - { |
|
925 | - return isset($this->_class_abbreviations[ $class_name ]) |
|
926 | - ? $this->_class_abbreviations[ $class_name ] |
|
927 | - : $default; |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * attempts to find a cached version of the requested class |
|
933 | - * by looking in the following places: |
|
934 | - * $this->{$class_abbreviation} ie: $this->CART |
|
935 | - * $this->{$class_name} ie: $this->Some_Class |
|
936 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
937 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
938 | - * |
|
939 | - * @param string $class_name |
|
940 | - * @param string $class_prefix |
|
941 | - * @param array $arguments |
|
942 | - * @return mixed |
|
943 | - */ |
|
944 | - protected function _get_cached_class( |
|
945 | - $class_name, |
|
946 | - $class_prefix = '', |
|
947 | - $arguments = array() |
|
948 | - ) { |
|
949 | - if ($class_name === 'EE_Registry') { |
|
950 | - return $this; |
|
951 | - } |
|
952 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
953 | - // check if class has already been loaded, and return it if it has been |
|
954 | - if (isset($this->{$class_abbreviation})) { |
|
955 | - return $this->{$class_abbreviation}; |
|
956 | - } |
|
957 | - $class_name = str_replace('\\', '_', $class_name); |
|
958 | - if (isset($this->{$class_name})) { |
|
959 | - return $this->{$class_name}; |
|
960 | - } |
|
961 | - if ($class_prefix === 'addon' && isset($this->addons->{$class_name})) { |
|
962 | - return $this->addons->{$class_name}; |
|
963 | - } |
|
964 | - $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
965 | - if (isset($this->LIB->{$object_identifier})) { |
|
966 | - return $this->LIB->{$object_identifier}; |
|
967 | - } |
|
968 | - foreach ($this->LIB as $key => $object) { |
|
969 | - if (// request does not contain new arguments and therefore no args identifier |
|
970 | - ! $this->object_identifier->hasArguments($object_identifier) |
|
971 | - // but previously cached class with args was found |
|
972 | - && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) |
|
973 | - ) { |
|
974 | - return $object; |
|
975 | - } |
|
976 | - } |
|
977 | - return null; |
|
978 | - } |
|
979 | - |
|
980 | - |
|
981 | - /** |
|
982 | - * removes a cached version of the requested class |
|
983 | - * |
|
984 | - * @param string $class_name |
|
985 | - * @param boolean $addon |
|
986 | - * @param array $arguments |
|
987 | - * @return boolean |
|
988 | - */ |
|
989 | - public function clear_cached_class( |
|
990 | - $class_name, |
|
991 | - $addon = false, |
|
992 | - $arguments = array() |
|
993 | - ) { |
|
994 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
995 | - // check if class has already been loaded, and return it if it has been |
|
996 | - if (isset($this->{$class_abbreviation})) { |
|
997 | - $this->{$class_abbreviation} = null; |
|
998 | - return true; |
|
999 | - } |
|
1000 | - $class_name = str_replace('\\', '_', $class_name); |
|
1001 | - if (isset($this->{$class_name})) { |
|
1002 | - $this->{$class_name} = null; |
|
1003 | - return true; |
|
1004 | - } |
|
1005 | - if ($addon && isset($this->addons->{$class_name})) { |
|
1006 | - unset($this->addons->{$class_name}); |
|
1007 | - return true; |
|
1008 | - } |
|
1009 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1010 | - if (isset($this->LIB->{$class_name})) { |
|
1011 | - unset($this->LIB->{$class_name}); |
|
1012 | - return true; |
|
1013 | - } |
|
1014 | - return false; |
|
1015 | - } |
|
1016 | - |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * _set_cached_class |
|
1020 | - * attempts to cache the instantiated class locally |
|
1021 | - * in one of the following places, in the following order: |
|
1022 | - * $this->{class_abbreviation} ie: $this->CART |
|
1023 | - * $this->{$class_name} ie: $this->Some_Class |
|
1024 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1025 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1026 | - * |
|
1027 | - * @param object $class_obj |
|
1028 | - * @param string $class_name |
|
1029 | - * @param string $class_prefix |
|
1030 | - * @param bool $from_db |
|
1031 | - * @param array $arguments |
|
1032 | - * @return void |
|
1033 | - */ |
|
1034 | - protected function _set_cached_class( |
|
1035 | - $class_obj, |
|
1036 | - $class_name, |
|
1037 | - $class_prefix = '', |
|
1038 | - $from_db = false, |
|
1039 | - $arguments = array() |
|
1040 | - ) { |
|
1041 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1042 | - return; |
|
1043 | - } |
|
1044 | - // return newly instantiated class |
|
1045 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1046 | - if ($class_abbreviation) { |
|
1047 | - $this->{$class_abbreviation} = $class_obj; |
|
1048 | - return; |
|
1049 | - } |
|
1050 | - $class_name = str_replace('\\', '_', $class_name); |
|
1051 | - if (property_exists($this, $class_name)) { |
|
1052 | - $this->{$class_name} = $class_obj; |
|
1053 | - return; |
|
1054 | - } |
|
1055 | - if ($class_prefix === 'addon') { |
|
1056 | - $this->addons->{$class_name} = $class_obj; |
|
1057 | - return; |
|
1058 | - } |
|
1059 | - if (! $from_db) { |
|
1060 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1061 | - $this->LIB->{$class_name} = $class_obj; |
|
1062 | - } |
|
1063 | - } |
|
1064 | - |
|
1065 | - |
|
1066 | - /** |
|
1067 | - * attempts to find a full valid filepath for the requested class. |
|
1068 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
1069 | - * then returns that path if the target file has been found and is readable |
|
1070 | - * |
|
1071 | - * @param string $class_name |
|
1072 | - * @param string $type |
|
1073 | - * @param array $file_paths |
|
1074 | - * @return string | bool |
|
1075 | - */ |
|
1076 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
1077 | - { |
|
1078 | - // make sure $file_paths is an array |
|
1079 | - $file_paths = is_array($file_paths) |
|
1080 | - ? $file_paths |
|
1081 | - : array($file_paths); |
|
1082 | - // cycle thru paths |
|
1083 | - foreach ($file_paths as $key => $file_path) { |
|
1084 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
1085 | - $file_path = $file_path |
|
1086 | - ? str_replace(array('/', '\\'), DS, $file_path) |
|
1087 | - : EE_CLASSES; |
|
1088 | - // prep file type |
|
1089 | - $type = ! empty($type) |
|
1090 | - ? trim($type, '.') . '.' |
|
1091 | - : ''; |
|
1092 | - // build full file path |
|
1093 | - $file_paths[ $key ] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
1094 | - // does the file exist and can be read ? |
|
1095 | - if (is_readable($file_paths[ $key ])) { |
|
1096 | - return $file_paths[ $key ]; |
|
1097 | - } |
|
1098 | - } |
|
1099 | - return false; |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * basically just performs a require_once() |
|
1105 | - * but with some error handling |
|
1106 | - * |
|
1107 | - * @param string $path |
|
1108 | - * @param string $class_name |
|
1109 | - * @param string $type |
|
1110 | - * @param array $file_paths |
|
1111 | - * @return bool |
|
1112 | - * @throws EE_Error |
|
1113 | - * @throws ReflectionException |
|
1114 | - */ |
|
1115 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
1116 | - { |
|
1117 | - $this->resolve_legacy_class_parent($class_name); |
|
1118 | - // don't give up! you gotta... |
|
1119 | - try { |
|
1120 | - // does the file exist and can it be read ? |
|
1121 | - if (! $path) { |
|
1122 | - // just in case the file has already been autoloaded, |
|
1123 | - // but discrepancies in the naming schema are preventing it from |
|
1124 | - // being loaded via one of the EE_Registry::load_*() methods, |
|
1125 | - // then let's try one last hail mary before throwing an exception |
|
1126 | - // and call class_exists() again, but with autoloading turned ON |
|
1127 | - if (class_exists($class_name)) { |
|
1128 | - return true; |
|
1129 | - } |
|
1130 | - // so sorry, can't find the file |
|
1131 | - throw new EE_Error( |
|
1132 | - sprintf( |
|
1133 | - esc_html__( |
|
1134 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
1135 | - 'event_espresso' |
|
1136 | - ), |
|
1137 | - trim($type, '.'), |
|
1138 | - $class_name, |
|
1139 | - '<br />' . implode(',<br />', $file_paths) |
|
1140 | - ) |
|
1141 | - ); |
|
1142 | - } |
|
1143 | - // get the file |
|
1144 | - require_once($path); |
|
1145 | - // if the class isn't already declared somewhere |
|
1146 | - if (class_exists($class_name, false) === false) { |
|
1147 | - // so sorry, not a class |
|
1148 | - throw new EE_Error( |
|
1149 | - sprintf( |
|
1150 | - esc_html__( |
|
1151 | - 'The %s file %s does not appear to contain the %s Class.', |
|
1152 | - 'event_espresso' |
|
1153 | - ), |
|
1154 | - $type, |
|
1155 | - $path, |
|
1156 | - $class_name |
|
1157 | - ) |
|
1158 | - ); |
|
1159 | - } |
|
1160 | - } catch (EE_Error $e) { |
|
1161 | - $e->get_error(); |
|
1162 | - return false; |
|
1163 | - } |
|
1164 | - return true; |
|
1165 | - } |
|
1166 | - |
|
1167 | - |
|
1168 | - /** |
|
1169 | - * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1170 | - * before their class declaration in order to ensure that the parent class was loaded. |
|
1171 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1172 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1173 | - * |
|
1174 | - * @param string $class_name |
|
1175 | - */ |
|
1176 | - protected function resolve_legacy_class_parent($class_name = '') |
|
1177 | - { |
|
1178 | - try { |
|
1179 | - $legacy_parent_class_map = array( |
|
1180 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
|
1181 | - ); |
|
1182 | - if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1183 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1184 | - } |
|
1185 | - } catch (Exception $exception) { |
|
1186 | - } |
|
1187 | - } |
|
1188 | - |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * _create_object |
|
1192 | - * Attempts to instantiate the requested class via any of the |
|
1193 | - * commonly used instantiation methods employed throughout EE. |
|
1194 | - * The priority for instantiation is as follows: |
|
1195 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1196 | - * - model objects via their 'new_instance_from_db' method |
|
1197 | - * - model objects via their 'new_instance' method |
|
1198 | - * - "singleton" classes" via their 'instance' method |
|
1199 | - * - standard instantiable classes via their __constructor |
|
1200 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
1201 | - * then the constructor for the requested class will be examined to determine |
|
1202 | - * if any dependencies exist, and if they can be injected. |
|
1203 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1204 | - * |
|
1205 | - * @param string $class_name |
|
1206 | - * @param array $arguments |
|
1207 | - * @param string $type |
|
1208 | - * @param bool $from_db |
|
1209 | - * @return null|object|bool |
|
1210 | - * @throws InvalidArgumentException |
|
1211 | - * @throws InvalidInterfaceException |
|
1212 | - * @throws EE_Error |
|
1213 | - * @throws ReflectionException |
|
1214 | - * @throws InvalidDataTypeException |
|
1215 | - */ |
|
1216 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1217 | - { |
|
1218 | - // create reflection |
|
1219 | - $reflector = $this->mirror->getReflectionClass($class_name); |
|
1220 | - // make sure arguments are an array |
|
1221 | - $arguments = is_array($arguments) |
|
1222 | - ? $arguments |
|
1223 | - : array($arguments); |
|
1224 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1225 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1226 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1227 | - ? $arguments |
|
1228 | - : array($arguments); |
|
1229 | - // attempt to inject dependencies ? |
|
1230 | - if ($this->_dependency_map->has($class_name)) { |
|
1231 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1232 | - } |
|
1233 | - // instantiate the class if possible |
|
1234 | - if ($reflector->isAbstract()) { |
|
1235 | - // nothing to instantiate, loading file was enough |
|
1236 | - // does not throw an exception so $instantiation_mode is unused |
|
1237 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
1238 | - return true; |
|
1239 | - } |
|
1240 | - if (empty($arguments) |
|
1241 | - && $this->mirror->getConstructorFromReflection($reflector) === null |
|
1242 | - && $reflector->isInstantiable() |
|
1243 | - ) { |
|
1244 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1245 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
1246 | - return $reflector->newInstance(); |
|
1247 | - } |
|
1248 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1249 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
1250 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1251 | - } |
|
1252 | - if (method_exists($class_name, 'new_instance')) { |
|
1253 | - // $instantiation_mode = "4) new_instance()"; |
|
1254 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1255 | - } |
|
1256 | - if (method_exists($class_name, 'instance')) { |
|
1257 | - // $instantiation_mode = "5) instance()"; |
|
1258 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1259 | - } |
|
1260 | - if ($reflector->isInstantiable()) { |
|
1261 | - // $instantiation_mode = "6) constructor"; |
|
1262 | - return $reflector->newInstanceArgs($arguments); |
|
1263 | - } |
|
1264 | - // heh ? something's not right ! |
|
1265 | - throw new EE_Error( |
|
1266 | - sprintf( |
|
1267 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1268 | - $type, |
|
1269 | - $class_name |
|
1270 | - ) |
|
1271 | - ); |
|
1272 | - } |
|
1273 | - |
|
1274 | - |
|
1275 | - /** |
|
1276 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1277 | - * @param array $array |
|
1278 | - * @return bool |
|
1279 | - */ |
|
1280 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1281 | - { |
|
1282 | - return ! empty($array) |
|
1283 | - ? array_keys($array) === range(0, count($array) - 1) |
|
1284 | - : true; |
|
1285 | - } |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * _resolve_dependencies |
|
1290 | - * examines the constructor for the requested class to determine |
|
1291 | - * if any dependencies exist, and if they can be injected. |
|
1292 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1293 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1294 | - * For example: |
|
1295 | - * if attempting to load a class "Foo" with the following constructor: |
|
1296 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1297 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1298 | - * but only IF they are NOT already present in the incoming arguments array, |
|
1299 | - * and the correct classes can be loaded |
|
1300 | - * |
|
1301 | - * @param ReflectionClass $reflector |
|
1302 | - * @param string $class_name |
|
1303 | - * @param array $arguments |
|
1304 | - * @return array |
|
1305 | - * @throws InvalidArgumentException |
|
1306 | - * @throws InvalidDataTypeException |
|
1307 | - * @throws InvalidInterfaceException |
|
1308 | - * @throws ReflectionException |
|
1309 | - */ |
|
1310 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
|
1311 | - { |
|
1312 | - // let's examine the constructor |
|
1313 | - $constructor = $this->mirror->getConstructorFromReflection($reflector); |
|
1314 | - // whu? huh? nothing? |
|
1315 | - if (! $constructor) { |
|
1316 | - return $arguments; |
|
1317 | - } |
|
1318 | - // get constructor parameters |
|
1319 | - $params = $this->mirror->getParametersFromReflection($reflector); |
|
1320 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1321 | - $argument_keys = array_keys($arguments); |
|
1322 | - // now loop thru all of the constructors expected parameters |
|
1323 | - foreach ($params as $index => $param) { |
|
1324 | - // is this a dependency for a specific class ? |
|
1325 | - $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); |
|
1326 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1327 | - $param_class = $this->class_cache->isAlias($param_class, $class_name) |
|
1328 | - ? $this->class_cache->getFqnForAlias($param_class, $class_name) |
|
1329 | - : $param_class; |
|
1330 | - if (// param is not even a class |
|
1331 | - $param_class === null |
|
1332 | - // and something already exists in the incoming arguments for this param |
|
1333 | - && array_key_exists($index, $argument_keys) |
|
1334 | - && array_key_exists($argument_keys[ $index ], $arguments) |
|
1335 | - ) { |
|
1336 | - // so let's skip this argument and move on to the next |
|
1337 | - continue; |
|
1338 | - } |
|
1339 | - if (// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1340 | - $param_class !== null |
|
1341 | - && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1342 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1343 | - ) { |
|
1344 | - // skip this argument and move on to the next |
|
1345 | - continue; |
|
1346 | - } |
|
1347 | - if (// parameter is type hinted as a class, and should be injected |
|
1348 | - $param_class !== null |
|
1349 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1350 | - ) { |
|
1351 | - $arguments = $this->_resolve_dependency( |
|
1352 | - $class_name, |
|
1353 | - $param_class, |
|
1354 | - $arguments, |
|
1355 | - $index |
|
1356 | - ); |
|
1357 | - } else { |
|
1358 | - $arguments[ $index ] = $this->mirror->getParameterDefaultValue( |
|
1359 | - $param, |
|
1360 | - $class_name, |
|
1361 | - $index |
|
1362 | - ); |
|
1363 | - } |
|
1364 | - } |
|
1365 | - return $arguments; |
|
1366 | - } |
|
1367 | - |
|
1368 | - |
|
1369 | - /** |
|
1370 | - * @param string $class_name |
|
1371 | - * @param string $param_class |
|
1372 | - * @param array $arguments |
|
1373 | - * @param mixed $index |
|
1374 | - * @return array |
|
1375 | - * @throws InvalidArgumentException |
|
1376 | - * @throws InvalidInterfaceException |
|
1377 | - * @throws InvalidDataTypeException |
|
1378 | - */ |
|
1379 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1380 | - { |
|
1381 | - $dependency = null; |
|
1382 | - // should dependency be loaded from cache ? |
|
1383 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1384 | - $class_name, |
|
1385 | - $param_class |
|
1386 | - ); |
|
1387 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1388 | - // we might have a dependency... |
|
1389 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1390 | - $cached_class = $cache_on |
|
1391 | - ? $this->_get_cached_class($param_class) |
|
1392 | - : null; |
|
1393 | - // and grab it if it exists |
|
1394 | - if ($cached_class instanceof $param_class) { |
|
1395 | - $dependency = $cached_class; |
|
1396 | - } elseif ($param_class !== $class_name) { |
|
1397 | - // obtain the loader method from the dependency map |
|
1398 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1399 | - // is loader a custom closure ? |
|
1400 | - if ($loader instanceof Closure) { |
|
1401 | - $dependency = $loader($arguments); |
|
1402 | - } else { |
|
1403 | - // set the cache on property for the recursive loading call |
|
1404 | - $this->_cache_on = $cache_on; |
|
1405 | - // if not, then let's try and load it via the registry |
|
1406 | - if ($loader && method_exists($this, $loader)) { |
|
1407 | - $dependency = $this->{$loader}($param_class); |
|
1408 | - } else { |
|
1409 | - $dependency = LoaderFactory::getLoader()->load( |
|
1410 | - $param_class, |
|
1411 | - array(), |
|
1412 | - $cache_on |
|
1413 | - ); |
|
1414 | - } |
|
1415 | - } |
|
1416 | - } |
|
1417 | - // did we successfully find the correct dependency ? |
|
1418 | - if ($dependency instanceof $param_class) { |
|
1419 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1420 | - $arguments[ $index ] = $dependency; |
|
1421 | - } |
|
1422 | - return $arguments; |
|
1423 | - } |
|
1424 | - |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1428 | - * |
|
1429 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1430 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1431 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1432 | - * @param array $arguments |
|
1433 | - * @return object |
|
1434 | - */ |
|
1435 | - public static function factory($classname, $arguments = array()) |
|
1436 | - { |
|
1437 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1438 | - if ($loader instanceof Closure) { |
|
1439 | - return $loader($arguments); |
|
1440 | - } |
|
1441 | - if (method_exists(self::instance(), $loader)) { |
|
1442 | - return self::instance()->{$loader}($classname, $arguments); |
|
1443 | - } |
|
1444 | - return null; |
|
1445 | - } |
|
1446 | - |
|
1447 | - |
|
1448 | - /** |
|
1449 | - * Gets the addon by its class name |
|
1450 | - * |
|
1451 | - * @param string $class_name |
|
1452 | - * @return EE_Addon |
|
1453 | - */ |
|
1454 | - public function getAddon($class_name) |
|
1455 | - { |
|
1456 | - $class_name = str_replace('\\', '_', $class_name); |
|
1457 | - if (isset($this->addons->{$class_name})) { |
|
1458 | - return $this->addons->{$class_name}; |
|
1459 | - } else { |
|
1460 | - return null; |
|
1461 | - } |
|
1462 | - } |
|
1463 | - |
|
1464 | - |
|
1465 | - /** |
|
1466 | - * removes the addon from the internal cache |
|
1467 | - * |
|
1468 | - * @param string $class_name |
|
1469 | - * @return void |
|
1470 | - */ |
|
1471 | - public function removeAddon($class_name) |
|
1472 | - { |
|
1473 | - $class_name = str_replace('\\', '_', $class_name); |
|
1474 | - unset($this->addons->{$class_name}); |
|
1475 | - } |
|
1476 | - |
|
1477 | - |
|
1478 | - /** |
|
1479 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1480 | - * use the get_addon() method above |
|
1481 | - * |
|
1482 | - * @param string $name |
|
1483 | - * @return EE_Addon |
|
1484 | - */ |
|
1485 | - public function get_addon_by_name($name) |
|
1486 | - { |
|
1487 | - foreach ($this->addons as $addon) { |
|
1488 | - if ($addon->name() === $name) { |
|
1489 | - return $addon; |
|
1490 | - } |
|
1491 | - } |
|
1492 | - return null; |
|
1493 | - } |
|
1494 | - |
|
1495 | - |
|
1496 | - /** |
|
1497 | - * Gets an array of all the registered addons, where the keys are their names. |
|
1498 | - * (ie, what each returns for their name() function) |
|
1499 | - * They're already available on EE_Registry::instance()->addons as properties, |
|
1500 | - * where each property's name is the addon's classname, |
|
1501 | - * So if you just want to get the addon by classname, |
|
1502 | - * OR use the get_addon() method above. |
|
1503 | - * PLEASE NOTE: |
|
1504 | - * addons with Fully Qualified Class Names |
|
1505 | - * have had the namespace separators converted to underscores, |
|
1506 | - * so a classname like Fully\Qualified\ClassName |
|
1507 | - * would have been converted to Fully_Qualified_ClassName |
|
1508 | - * |
|
1509 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1510 | - */ |
|
1511 | - public function get_addons_by_name() |
|
1512 | - { |
|
1513 | - $addons = array(); |
|
1514 | - foreach ($this->addons as $addon) { |
|
1515 | - $addons[ $addon->name() ] = $addon; |
|
1516 | - } |
|
1517 | - return $addons; |
|
1518 | - } |
|
1519 | - |
|
1520 | - |
|
1521 | - /** |
|
1522 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1523 | - * a stale copy of it around |
|
1524 | - * |
|
1525 | - * @param string $model_name |
|
1526 | - * @return \EEM_Base |
|
1527 | - * @throws \EE_Error |
|
1528 | - */ |
|
1529 | - public function reset_model($model_name) |
|
1530 | - { |
|
1531 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1532 | - ? "EEM_{$model_name}" |
|
1533 | - : $model_name; |
|
1534 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1535 | - return null; |
|
1536 | - } |
|
1537 | - // get that model reset it and make sure we nuke the old reference to it |
|
1538 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
1539 | - && is_callable( |
|
1540 | - array($model_class_name, 'reset') |
|
1541 | - )) { |
|
1542 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1543 | - } else { |
|
1544 | - throw new EE_Error( |
|
1545 | - sprintf( |
|
1546 | - esc_html__('Model %s does not have a method "reset"', 'event_espresso'), |
|
1547 | - $model_name |
|
1548 | - ) |
|
1549 | - ); |
|
1550 | - } |
|
1551 | - return $this->LIB->{$model_class_name}; |
|
1552 | - } |
|
1553 | - |
|
1554 | - |
|
1555 | - /** |
|
1556 | - * Resets the registry. |
|
1557 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1558 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1559 | - * - $_dependency_map |
|
1560 | - * - $_class_abbreviations |
|
1561 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1562 | - * - $REQ: Still on the same request so no need to change. |
|
1563 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1564 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1565 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1566 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1567 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1568 | - * switch or on the restore. |
|
1569 | - * - $modules |
|
1570 | - * - $shortcodes |
|
1571 | - * - $widgets |
|
1572 | - * |
|
1573 | - * @param boolean $hard [deprecated] |
|
1574 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1575 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1576 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1577 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1578 | - * client |
|
1579 | - * code instead can just change the model context to a different blog id if |
|
1580 | - * necessary |
|
1581 | - * @return EE_Registry |
|
1582 | - * @throws InvalidInterfaceException |
|
1583 | - * @throws InvalidDataTypeException |
|
1584 | - * @throws EE_Error |
|
1585 | - * @throws ReflectionException |
|
1586 | - * @throws InvalidArgumentException |
|
1587 | - */ |
|
1588 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1589 | - { |
|
1590 | - $instance = self::instance(); |
|
1591 | - $instance->_cache_on = true; |
|
1592 | - // reset some "special" classes |
|
1593 | - EEH_Activation::reset(); |
|
1594 | - $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
1595 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1596 | - $instance->CART = null; |
|
1597 | - $instance->MRM = null; |
|
1598 | - $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared( |
|
1599 | - 'EventEspresso\core\services\assets\Registry' |
|
1600 | - ); |
|
1601 | - // messages reset |
|
1602 | - EED_Messages::reset(); |
|
1603 | - // handle of objects cached on LIB |
|
1604 | - foreach (array('LIB', 'modules') as $cache) { |
|
1605 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
1606 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1607 | - unset($instance->{$cache}->{$class_name}); |
|
1608 | - } |
|
1609 | - } |
|
1610 | - } |
|
1611 | - return $instance; |
|
1612 | - } |
|
1613 | - |
|
1614 | - |
|
1615 | - /** |
|
1616 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
1617 | - * if passed object implements InterminableInterface, then return false, |
|
1618 | - * to indicate that it should NOT be cleared from the Registry cache |
|
1619 | - * |
|
1620 | - * @param $object |
|
1621 | - * @param bool $reset_models |
|
1622 | - * @return bool returns true if cached object should be unset |
|
1623 | - */ |
|
1624 | - private static function _reset_and_unset_object($object, $reset_models) |
|
1625 | - { |
|
1626 | - if (! is_object($object)) { |
|
1627 | - // don't unset anything that's not an object |
|
1628 | - return false; |
|
1629 | - } |
|
1630 | - if ($object instanceof EED_Module) { |
|
1631 | - $object::reset(); |
|
1632 | - // don't unset modules |
|
1633 | - return false; |
|
1634 | - } |
|
1635 | - if ($object instanceof ResettableInterface) { |
|
1636 | - if ($object instanceof EEM_Base) { |
|
1637 | - if ($reset_models) { |
|
1638 | - $object->reset(); |
|
1639 | - return true; |
|
1640 | - } |
|
1641 | - return false; |
|
1642 | - } |
|
1643 | - $object->reset(); |
|
1644 | - return true; |
|
1645 | - } |
|
1646 | - if (! $object instanceof InterminableInterface) { |
|
1647 | - return true; |
|
1648 | - } |
|
1649 | - return false; |
|
1650 | - } |
|
1651 | - |
|
1652 | - |
|
1653 | - /** |
|
1654 | - * Gets all the custom post type models defined |
|
1655 | - * |
|
1656 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1657 | - */ |
|
1658 | - public function cpt_models() |
|
1659 | - { |
|
1660 | - $cpt_models = array(); |
|
1661 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1662 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1663 | - $cpt_models[ $short_name ] = $classname; |
|
1664 | - } |
|
1665 | - } |
|
1666 | - return $cpt_models; |
|
1667 | - } |
|
1668 | - |
|
1669 | - |
|
1670 | - /** |
|
1671 | - * @return \EE_Config |
|
1672 | - */ |
|
1673 | - public static function CFG() |
|
1674 | - { |
|
1675 | - return self::instance()->CFG; |
|
1676 | - } |
|
1677 | - |
|
1678 | - |
|
1679 | - /** |
|
1680 | - * @deprecated 4.9.62.p |
|
1681 | - * @param string $class_name |
|
1682 | - * @return ReflectionClass |
|
1683 | - * @throws ReflectionException |
|
1684 | - * @throws InvalidDataTypeException |
|
1685 | - */ |
|
1686 | - public function get_ReflectionClass($class_name) |
|
1687 | - { |
|
1688 | - return $this->mirror->getReflectionClass($class_name); |
|
1689 | - } |
|
26 | + /** |
|
27 | + * @var EE_Registry $_instance |
|
28 | + */ |
|
29 | + private static $_instance; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EE_Dependency_Map $_dependency_map |
|
33 | + */ |
|
34 | + protected $_dependency_map; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Mirror |
|
38 | + */ |
|
39 | + private $mirror; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ClassInterfaceCache $class_cache |
|
43 | + */ |
|
44 | + private $class_cache; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array $_class_abbreviations |
|
48 | + */ |
|
49 | + protected $_class_abbreviations = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * @var CommandBusInterface $BUS |
|
53 | + */ |
|
54 | + public $BUS; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var EE_Cart $CART |
|
58 | + */ |
|
59 | + public $CART; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var EE_Config $CFG |
|
63 | + */ |
|
64 | + public $CFG; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var EE_Network_Config $NET_CFG |
|
68 | + */ |
|
69 | + public $NET_CFG; |
|
70 | + |
|
71 | + /** |
|
72 | + * StdClass object for storing library classes in |
|
73 | + * |
|
74 | + * @var RegistryContainer $LIB |
|
75 | + */ |
|
76 | + public $LIB; |
|
77 | + |
|
78 | + /** |
|
79 | + * @var EE_Request_Handler $REQ |
|
80 | + */ |
|
81 | + public $REQ; |
|
82 | + |
|
83 | + /** |
|
84 | + * @var EE_Session $SSN |
|
85 | + */ |
|
86 | + public $SSN; |
|
87 | + |
|
88 | + /** |
|
89 | + * @since 4.5.0 |
|
90 | + * @var EE_Capabilities $CAP |
|
91 | + */ |
|
92 | + public $CAP; |
|
93 | + |
|
94 | + /** |
|
95 | + * @since 4.9.0 |
|
96 | + * @var EE_Message_Resource_Manager $MRM |
|
97 | + */ |
|
98 | + public $MRM; |
|
99 | + |
|
100 | + /** |
|
101 | + * @var Registry $AssetsRegistry |
|
102 | + */ |
|
103 | + public $AssetsRegistry; |
|
104 | + |
|
105 | + /** |
|
106 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
107 | + * |
|
108 | + * @var EE_Addon[] $addons |
|
109 | + */ |
|
110 | + public $addons; |
|
111 | + |
|
112 | + /** |
|
113 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
114 | + * |
|
115 | + * @var EEM_Base[] $models |
|
116 | + */ |
|
117 | + public $models = array(); |
|
118 | + |
|
119 | + /** |
|
120 | + * @var EED_Module[] $modules |
|
121 | + */ |
|
122 | + public $modules; |
|
123 | + |
|
124 | + /** |
|
125 | + * @var EES_Shortcode[] $shortcodes |
|
126 | + */ |
|
127 | + public $shortcodes; |
|
128 | + |
|
129 | + /** |
|
130 | + * @var WP_Widget[] $widgets |
|
131 | + */ |
|
132 | + public $widgets; |
|
133 | + |
|
134 | + /** |
|
135 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
136 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
137 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
138 | + * classnames (eg "EEM_Event") |
|
139 | + * |
|
140 | + * @var array $non_abstract_db_models |
|
141 | + */ |
|
142 | + public $non_abstract_db_models = array(); |
|
143 | + |
|
144 | + /** |
|
145 | + * internationalization for JS strings |
|
146 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
147 | + * in js file: var translatedString = eei18n.string_key; |
|
148 | + * |
|
149 | + * @var array $i18n_js_strings |
|
150 | + */ |
|
151 | + public static $i18n_js_strings = array(); |
|
152 | + |
|
153 | + /** |
|
154 | + * $main_file - path to espresso.php |
|
155 | + * |
|
156 | + * @var array $main_file |
|
157 | + */ |
|
158 | + public $main_file; |
|
159 | + |
|
160 | + /** |
|
161 | + * array of ReflectionClass objects where the key is the class name |
|
162 | + * |
|
163 | + * @deprecated 4.9.62.p |
|
164 | + * @var ReflectionClass[] $_reflectors |
|
165 | + */ |
|
166 | + public $_reflectors; |
|
167 | + |
|
168 | + /** |
|
169 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
170 | + * |
|
171 | + * @var boolean $_cache_on |
|
172 | + */ |
|
173 | + protected $_cache_on = true; |
|
174 | + |
|
175 | + /** |
|
176 | + * @var ObjectIdentifier |
|
177 | + */ |
|
178 | + private $object_identifier; |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @singleton method used to instantiate class object |
|
183 | + * @param EE_Dependency_Map|null $dependency_map |
|
184 | + * @param Mirror|null $mirror |
|
185 | + * @param ClassInterfaceCache|null $class_cache |
|
186 | + * @param ObjectIdentifier|null $object_identifier |
|
187 | + * @return EE_Registry instance |
|
188 | + */ |
|
189 | + public static function instance( |
|
190 | + EE_Dependency_Map $dependency_map = null, |
|
191 | + Mirror $mirror = null, |
|
192 | + ClassInterfaceCache $class_cache = null, |
|
193 | + ObjectIdentifier $object_identifier = null |
|
194 | + ) { |
|
195 | + // check if class object is instantiated |
|
196 | + if (! self::$_instance instanceof EE_Registry |
|
197 | + && $dependency_map instanceof EE_Dependency_Map |
|
198 | + && $mirror instanceof Mirror |
|
199 | + && $class_cache instanceof ClassInterfaceCache |
|
200 | + && $object_identifier instanceof ObjectIdentifier |
|
201 | + ) { |
|
202 | + self::$_instance = new self( |
|
203 | + $dependency_map, |
|
204 | + $mirror, |
|
205 | + $class_cache, |
|
206 | + $object_identifier |
|
207 | + ); |
|
208 | + } |
|
209 | + return self::$_instance; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * protected constructor to prevent direct creation |
|
215 | + * |
|
216 | + * @Constructor |
|
217 | + * @param EE_Dependency_Map $dependency_map |
|
218 | + * @param Mirror $mirror |
|
219 | + * @param ClassInterfaceCache $class_cache |
|
220 | + * @param ObjectIdentifier $object_identifier |
|
221 | + */ |
|
222 | + protected function __construct( |
|
223 | + EE_Dependency_Map $dependency_map, |
|
224 | + Mirror $mirror, |
|
225 | + ClassInterfaceCache $class_cache, |
|
226 | + ObjectIdentifier $object_identifier |
|
227 | + ) { |
|
228 | + $this->_dependency_map = $dependency_map; |
|
229 | + $this->mirror = $mirror; |
|
230 | + $this->class_cache = $class_cache; |
|
231 | + $this->object_identifier = $object_identifier; |
|
232 | + // $registry_container = new RegistryContainer(); |
|
233 | + $this->LIB = new RegistryContainer(); |
|
234 | + $this->addons = new RegistryContainer(); |
|
235 | + $this->modules = new RegistryContainer(); |
|
236 | + $this->shortcodes = new RegistryContainer(); |
|
237 | + $this->widgets = new RegistryContainer(); |
|
238 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * initialize |
|
244 | + * |
|
245 | + * @throws OutOfBoundsException |
|
246 | + * @throws InvalidArgumentException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + * @throws InvalidDataTypeException |
|
249 | + * @throws EE_Error |
|
250 | + * @throws ReflectionException |
|
251 | + */ |
|
252 | + public function initialize() |
|
253 | + { |
|
254 | + $this->_class_abbreviations = apply_filters( |
|
255 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
256 | + array( |
|
257 | + 'EE_Config' => 'CFG', |
|
258 | + 'EE_Session' => 'SSN', |
|
259 | + 'EE_Capabilities' => 'CAP', |
|
260 | + 'EE_Cart' => 'CART', |
|
261 | + 'EE_Network_Config' => 'NET_CFG', |
|
262 | + 'EE_Request_Handler' => 'REQ', |
|
263 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
264 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
265 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
266 | + ) |
|
267 | + ); |
|
268 | + $this->load_core('Base', array(), true); |
|
269 | + // add our request and response objects to the cache |
|
270 | + $request_loader = $this->_dependency_map->class_loader( |
|
271 | + 'EventEspresso\core\services\request\Request' |
|
272 | + ); |
|
273 | + $this->_set_cached_class( |
|
274 | + $request_loader(), |
|
275 | + 'EventEspresso\core\services\request\Request' |
|
276 | + ); |
|
277 | + $response_loader = $this->_dependency_map->class_loader( |
|
278 | + 'EventEspresso\core\services\request\Response' |
|
279 | + ); |
|
280 | + $this->_set_cached_class( |
|
281 | + $response_loader(), |
|
282 | + 'EventEspresso\core\services\request\Response' |
|
283 | + ); |
|
284 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @return void |
|
290 | + */ |
|
291 | + public function init() |
|
292 | + { |
|
293 | + // Get current page protocol |
|
294 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
295 | + // Output admin-ajax.php URL with same protocol as current page |
|
296 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
297 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * localize_i18n_js_strings |
|
303 | + * |
|
304 | + * @return string |
|
305 | + */ |
|
306 | + public static function localize_i18n_js_strings() |
|
307 | + { |
|
308 | + $i18n_js_strings = (array) self::$i18n_js_strings; |
|
309 | + foreach ($i18n_js_strings as $key => $value) { |
|
310 | + if (is_scalar($value)) { |
|
311 | + $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | + } |
|
313 | + } |
|
314 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @param mixed string | EED_Module $module |
|
320 | + * @throws OutOfBoundsException |
|
321 | + * @throws InvalidArgumentException |
|
322 | + * @throws InvalidInterfaceException |
|
323 | + * @throws InvalidDataTypeException |
|
324 | + * @throws EE_Error |
|
325 | + * @throws ReflectionException |
|
326 | + */ |
|
327 | + public function add_module($module) |
|
328 | + { |
|
329 | + if ($module instanceof EED_Module) { |
|
330 | + $module_class = get_class($module); |
|
331 | + $this->modules->{$module_class} = $module; |
|
332 | + } else { |
|
333 | + if (! class_exists('EE_Module_Request_Router', false)) { |
|
334 | + $this->load_core('Module_Request_Router'); |
|
335 | + } |
|
336 | + EE_Module_Request_Router::module_factory($module); |
|
337 | + } |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * @param string $module_name |
|
343 | + * @return mixed EED_Module | NULL |
|
344 | + */ |
|
345 | + public function get_module($module_name = '') |
|
346 | + { |
|
347 | + return isset($this->modules->{$module_name}) |
|
348 | + ? $this->modules->{$module_name} |
|
349 | + : null; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * loads core classes - must be singletons |
|
355 | + * |
|
356 | + * @param string $class_name - simple class name ie: session |
|
357 | + * @param mixed $arguments |
|
358 | + * @param bool $load_only |
|
359 | + * @return mixed |
|
360 | + * @throws InvalidInterfaceException |
|
361 | + * @throws InvalidDataTypeException |
|
362 | + * @throws EE_Error |
|
363 | + * @throws ReflectionException |
|
364 | + * @throws InvalidArgumentException |
|
365 | + */ |
|
366 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
367 | + { |
|
368 | + $core_paths = apply_filters( |
|
369 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
370 | + array( |
|
371 | + EE_CORE, |
|
372 | + EE_ADMIN, |
|
373 | + EE_CPTS, |
|
374 | + EE_CORE . 'data_migration_scripts' . DS, |
|
375 | + EE_CORE . 'capabilities' . DS, |
|
376 | + EE_CORE . 'request_stack' . DS, |
|
377 | + EE_CORE . 'middleware' . DS, |
|
378 | + ) |
|
379 | + ); |
|
380 | + // retrieve instantiated class |
|
381 | + return $this->_load( |
|
382 | + $core_paths, |
|
383 | + 'EE_', |
|
384 | + $class_name, |
|
385 | + 'core', |
|
386 | + $arguments, |
|
387 | + false, |
|
388 | + true, |
|
389 | + $load_only |
|
390 | + ); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * loads service classes |
|
396 | + * |
|
397 | + * @param string $class_name - simple class name ie: session |
|
398 | + * @param mixed $arguments |
|
399 | + * @param bool $load_only |
|
400 | + * @return mixed |
|
401 | + * @throws InvalidInterfaceException |
|
402 | + * @throws InvalidDataTypeException |
|
403 | + * @throws EE_Error |
|
404 | + * @throws ReflectionException |
|
405 | + * @throws InvalidArgumentException |
|
406 | + */ |
|
407 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
408 | + { |
|
409 | + $service_paths = apply_filters( |
|
410 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
411 | + array( |
|
412 | + EE_CORE . 'services' . DS, |
|
413 | + ) |
|
414 | + ); |
|
415 | + // retrieve instantiated class |
|
416 | + return $this->_load( |
|
417 | + $service_paths, |
|
418 | + 'EE_', |
|
419 | + $class_name, |
|
420 | + 'class', |
|
421 | + $arguments, |
|
422 | + false, |
|
423 | + true, |
|
424 | + $load_only |
|
425 | + ); |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * loads data_migration_scripts |
|
431 | + * |
|
432 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
433 | + * @param mixed $arguments |
|
434 | + * @return EE_Data_Migration_Script_Base|mixed |
|
435 | + * @throws InvalidInterfaceException |
|
436 | + * @throws InvalidDataTypeException |
|
437 | + * @throws EE_Error |
|
438 | + * @throws ReflectionException |
|
439 | + * @throws InvalidArgumentException |
|
440 | + */ |
|
441 | + public function load_dms($class_name, $arguments = array()) |
|
442 | + { |
|
443 | + // retrieve instantiated class |
|
444 | + return $this->_load( |
|
445 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
446 | + 'EE_DMS_', |
|
447 | + $class_name, |
|
448 | + 'dms', |
|
449 | + $arguments, |
|
450 | + false, |
|
451 | + false |
|
452 | + ); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * loads object creating classes - must be singletons |
|
458 | + * |
|
459 | + * @param string $class_name - simple class name ie: attendee |
|
460 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
461 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
462 | + * instantiate |
|
463 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
464 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
465 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
466 | + * (default) |
|
467 | + * @return EE_Base_Class | bool |
|
468 | + * @throws InvalidInterfaceException |
|
469 | + * @throws InvalidDataTypeException |
|
470 | + * @throws EE_Error |
|
471 | + * @throws ReflectionException |
|
472 | + * @throws InvalidArgumentException |
|
473 | + */ |
|
474 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
475 | + { |
|
476 | + $paths = apply_filters( |
|
477 | + 'FHEE__EE_Registry__load_class__paths', |
|
478 | + array( |
|
479 | + EE_CORE, |
|
480 | + EE_CLASSES, |
|
481 | + EE_BUSINESS, |
|
482 | + ) |
|
483 | + ); |
|
484 | + // retrieve instantiated class |
|
485 | + return $this->_load( |
|
486 | + $paths, |
|
487 | + 'EE_', |
|
488 | + $class_name, |
|
489 | + 'class', |
|
490 | + $arguments, |
|
491 | + $from_db, |
|
492 | + $cache, |
|
493 | + $load_only |
|
494 | + ); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * loads helper classes - must be singletons |
|
500 | + * |
|
501 | + * @param string $class_name - simple class name ie: price |
|
502 | + * @param mixed $arguments |
|
503 | + * @param bool $load_only |
|
504 | + * @return EEH_Base | bool |
|
505 | + * @throws InvalidInterfaceException |
|
506 | + * @throws InvalidDataTypeException |
|
507 | + * @throws EE_Error |
|
508 | + * @throws ReflectionException |
|
509 | + * @throws InvalidArgumentException |
|
510 | + */ |
|
511 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
512 | + { |
|
513 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
514 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
515 | + // retrieve instantiated class |
|
516 | + return $this->_load( |
|
517 | + $helper_paths, |
|
518 | + 'EEH_', |
|
519 | + $class_name, |
|
520 | + 'helper', |
|
521 | + $arguments, |
|
522 | + false, |
|
523 | + true, |
|
524 | + $load_only |
|
525 | + ); |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * loads core classes - must be singletons |
|
531 | + * |
|
532 | + * @param string $class_name - simple class name ie: session |
|
533 | + * @param mixed $arguments |
|
534 | + * @param bool $load_only |
|
535 | + * @param bool $cache whether to cache the object or not. |
|
536 | + * @return mixed |
|
537 | + * @throws InvalidInterfaceException |
|
538 | + * @throws InvalidDataTypeException |
|
539 | + * @throws EE_Error |
|
540 | + * @throws ReflectionException |
|
541 | + * @throws InvalidArgumentException |
|
542 | + */ |
|
543 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
544 | + { |
|
545 | + $paths = array( |
|
546 | + EE_LIBRARIES, |
|
547 | + EE_LIBRARIES . 'messages' . DS, |
|
548 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
549 | + EE_LIBRARIES . 'qtips' . DS, |
|
550 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
551 | + ); |
|
552 | + // retrieve instantiated class |
|
553 | + return $this->_load( |
|
554 | + $paths, |
|
555 | + 'EE_', |
|
556 | + $class_name, |
|
557 | + 'lib', |
|
558 | + $arguments, |
|
559 | + false, |
|
560 | + $cache, |
|
561 | + $load_only |
|
562 | + ); |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * loads model classes - must be singletons |
|
568 | + * |
|
569 | + * @param string $class_name - simple class name ie: price |
|
570 | + * @param mixed $arguments |
|
571 | + * @param bool $load_only |
|
572 | + * @return EEM_Base | bool |
|
573 | + * @throws InvalidInterfaceException |
|
574 | + * @throws InvalidDataTypeException |
|
575 | + * @throws EE_Error |
|
576 | + * @throws ReflectionException |
|
577 | + * @throws InvalidArgumentException |
|
578 | + */ |
|
579 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
580 | + { |
|
581 | + $paths = apply_filters( |
|
582 | + 'FHEE__EE_Registry__load_model__paths', |
|
583 | + array( |
|
584 | + EE_MODELS, |
|
585 | + EE_CORE, |
|
586 | + ) |
|
587 | + ); |
|
588 | + // retrieve instantiated class |
|
589 | + return $this->_load( |
|
590 | + $paths, |
|
591 | + 'EEM_', |
|
592 | + $class_name, |
|
593 | + 'model', |
|
594 | + $arguments, |
|
595 | + false, |
|
596 | + true, |
|
597 | + $load_only |
|
598 | + ); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * loads model classes - must be singletons |
|
604 | + * |
|
605 | + * @param string $class_name - simple class name ie: price |
|
606 | + * @param mixed $arguments |
|
607 | + * @param bool $load_only |
|
608 | + * @return mixed | bool |
|
609 | + * @throws InvalidInterfaceException |
|
610 | + * @throws InvalidDataTypeException |
|
611 | + * @throws EE_Error |
|
612 | + * @throws ReflectionException |
|
613 | + * @throws InvalidArgumentException |
|
614 | + */ |
|
615 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
616 | + { |
|
617 | + $paths = array( |
|
618 | + EE_MODELS . 'fields' . DS, |
|
619 | + EE_MODELS . 'helpers' . DS, |
|
620 | + EE_MODELS . 'relations' . DS, |
|
621 | + EE_MODELS . 'strategies' . DS, |
|
622 | + ); |
|
623 | + // retrieve instantiated class |
|
624 | + return $this->_load( |
|
625 | + $paths, |
|
626 | + 'EE_', |
|
627 | + $class_name, |
|
628 | + '', |
|
629 | + $arguments, |
|
630 | + false, |
|
631 | + true, |
|
632 | + $load_only |
|
633 | + ); |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + /** |
|
638 | + * Determines if $model_name is the name of an actual EE model. |
|
639 | + * |
|
640 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
641 | + * @return boolean |
|
642 | + */ |
|
643 | + public function is_model_name($model_name) |
|
644 | + { |
|
645 | + return isset($this->models[ $model_name ]); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * generic class loader |
|
651 | + * |
|
652 | + * @param string $path_to_file - directory path to file location, not including filename |
|
653 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
654 | + * @param string $type - file type - core? class? helper? model? |
|
655 | + * @param mixed $arguments |
|
656 | + * @param bool $load_only |
|
657 | + * @return mixed |
|
658 | + * @throws InvalidInterfaceException |
|
659 | + * @throws InvalidDataTypeException |
|
660 | + * @throws EE_Error |
|
661 | + * @throws ReflectionException |
|
662 | + * @throws InvalidArgumentException |
|
663 | + */ |
|
664 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
665 | + { |
|
666 | + // retrieve instantiated class |
|
667 | + return $this->_load( |
|
668 | + $path_to_file, |
|
669 | + '', |
|
670 | + $file_name, |
|
671 | + $type, |
|
672 | + $arguments, |
|
673 | + false, |
|
674 | + true, |
|
675 | + $load_only |
|
676 | + ); |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * @param string $path_to_file - directory path to file location, not including filename |
|
682 | + * @param string $class_name - full class name ie: My_Class |
|
683 | + * @param string $type - file type - core? class? helper? model? |
|
684 | + * @param mixed $arguments |
|
685 | + * @param bool $load_only |
|
686 | + * @return bool|EE_Addon|object |
|
687 | + * @throws InvalidInterfaceException |
|
688 | + * @throws InvalidDataTypeException |
|
689 | + * @throws EE_Error |
|
690 | + * @throws ReflectionException |
|
691 | + * @throws InvalidArgumentException |
|
692 | + */ |
|
693 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
694 | + { |
|
695 | + // retrieve instantiated class |
|
696 | + return $this->_load( |
|
697 | + $path_to_file, |
|
698 | + 'addon', |
|
699 | + $class_name, |
|
700 | + $type, |
|
701 | + $arguments, |
|
702 | + false, |
|
703 | + true, |
|
704 | + $load_only |
|
705 | + ); |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * instantiates, caches, and automatically resolves dependencies |
|
711 | + * for classes that use a Fully Qualified Class Name. |
|
712 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
713 | + * then you need to use one of the existing load_*() methods |
|
714 | + * which can resolve the classname and filepath from the passed arguments |
|
715 | + * |
|
716 | + * @param bool|string $class_name Fully Qualified Class Name |
|
717 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
718 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
719 | + * @param bool $from_db some classes are instantiated from the db |
|
720 | + * and thus call a different method to instantiate |
|
721 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
722 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
723 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
724 | + * object = class loaded and instantiated successfully. |
|
725 | + * bool = fail or success when $load_only is true |
|
726 | + * @throws InvalidInterfaceException |
|
727 | + * @throws InvalidDataTypeException |
|
728 | + * @throws EE_Error |
|
729 | + * @throws ReflectionException |
|
730 | + * @throws InvalidArgumentException |
|
731 | + */ |
|
732 | + public function create( |
|
733 | + $class_name = false, |
|
734 | + $arguments = array(), |
|
735 | + $cache = false, |
|
736 | + $from_db = false, |
|
737 | + $load_only = false, |
|
738 | + $addon = false |
|
739 | + ) { |
|
740 | + $class_name = ltrim($class_name, '\\'); |
|
741 | + $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
742 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
743 | + // if a non-FQCN was passed, then |
|
744 | + // verifyClassExists() might return an object |
|
745 | + // or it could return null if the class just could not be found anywhere |
|
746 | + if ($class_exists instanceof $class_name || $class_exists === null) { |
|
747 | + // either way, return the results |
|
748 | + return $class_exists; |
|
749 | + } |
|
750 | + $class_name = $class_exists; |
|
751 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
752 | + if ($load_only) { |
|
753 | + return true; |
|
754 | + } |
|
755 | + $addon = $addon ? 'addon' : ''; |
|
756 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
757 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
758 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
759 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
760 | + // return object if it's already cached |
|
761 | + $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); |
|
762 | + if ($cached_class !== null) { |
|
763 | + return $cached_class; |
|
764 | + } |
|
765 | + }// obtain the loader method from the dependency map |
|
766 | + $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
767 | + if ($loader instanceof Closure) { |
|
768 | + $class_obj = $loader($arguments); |
|
769 | + } else { |
|
770 | + if ($loader && method_exists($this, $loader)) { |
|
771 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
772 | + } else { |
|
773 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
774 | + } |
|
775 | + } |
|
776 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
777 | + // save it for later... kinda like gum { : $ |
|
778 | + $this->_set_cached_class( |
|
779 | + $class_obj, |
|
780 | + $class_name, |
|
781 | + $addon, |
|
782 | + $from_db, |
|
783 | + $arguments |
|
784 | + ); |
|
785 | + } |
|
786 | + $this->_cache_on = true; |
|
787 | + return $class_obj; |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + /** |
|
792 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
793 | + * |
|
794 | + * @param string|object $class_name |
|
795 | + * @param array $arguments |
|
796 | + * @param int $attempt |
|
797 | + * @return mixed |
|
798 | + */ |
|
799 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
|
800 | + { |
|
801 | + if (is_object($class_name) || class_exists($class_name)) { |
|
802 | + return $class_name; |
|
803 | + } |
|
804 | + switch ($attempt) { |
|
805 | + case 1: |
|
806 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
807 | + $class_name = strpos($class_name, '\\') !== false |
|
808 | + ? '\\' . ltrim($class_name, '\\') |
|
809 | + : $class_name; |
|
810 | + break; |
|
811 | + case 2: |
|
812 | + // |
|
813 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
814 | + if ($loader && method_exists($this, $loader)) { |
|
815 | + return $this->{$loader}($class_name, $arguments); |
|
816 | + } |
|
817 | + break; |
|
818 | + case 3: |
|
819 | + default: |
|
820 | + return null; |
|
821 | + } |
|
822 | + $attempt++; |
|
823 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * instantiates, caches, and injects dependencies for classes |
|
829 | + * |
|
830 | + * @param array $file_paths an array of paths to folders to look in |
|
831 | + * @param string $class_prefix EE or EEM or... ??? |
|
832 | + * @param bool|string $class_name $class name |
|
833 | + * @param string $type file type - core? class? helper? model? |
|
834 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
835 | + * @param bool $from_db some classes are instantiated from the db |
|
836 | + * and thus call a different method to instantiate |
|
837 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
838 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
839 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
840 | + * object = class loaded and instantiated successfully. |
|
841 | + * bool = fail or success when $load_only is true |
|
842 | + * @throws EE_Error |
|
843 | + * @throws ReflectionException |
|
844 | + * @throws InvalidInterfaceException |
|
845 | + * @throws InvalidDataTypeException |
|
846 | + * @throws InvalidArgumentException |
|
847 | + */ |
|
848 | + protected function _load( |
|
849 | + $file_paths = array(), |
|
850 | + $class_prefix = 'EE_', |
|
851 | + $class_name = false, |
|
852 | + $type = 'class', |
|
853 | + $arguments = array(), |
|
854 | + $from_db = false, |
|
855 | + $cache = true, |
|
856 | + $load_only = false |
|
857 | + ) { |
|
858 | + $class_name = ltrim($class_name, '\\'); |
|
859 | + // strip php file extension |
|
860 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
861 | + // does the class have a prefix ? |
|
862 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
863 | + // make sure $class_prefix is uppercase |
|
864 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
865 | + // add class prefix ONCE!!! |
|
866 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
867 | + } |
|
868 | + $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
869 | + $class_exists = class_exists($class_name, false); |
|
870 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
871 | + if ($load_only && $class_exists) { |
|
872 | + return true; |
|
873 | + } |
|
874 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
875 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
876 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
877 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
878 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
879 | + // return object if it's already cached |
|
880 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); |
|
881 | + if ($cached_class !== null) { |
|
882 | + return $cached_class; |
|
883 | + } |
|
884 | + } |
|
885 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
886 | + if (! $class_exists) { |
|
887 | + // get full path to file |
|
888 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
889 | + // load the file |
|
890 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
891 | + // if we are only loading a file but NOT instantiating an object |
|
892 | + // then return boolean for whether class was loaded or not |
|
893 | + if ($load_only) { |
|
894 | + return $loaded; |
|
895 | + } |
|
896 | + // if an object was expected but loading failed, then return nothing |
|
897 | + if (! $loaded) { |
|
898 | + return null; |
|
899 | + } |
|
900 | + } |
|
901 | + // instantiate the requested object |
|
902 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
903 | + if ($this->_cache_on && $cache) { |
|
904 | + // save it for later... kinda like gum { : $ |
|
905 | + $this->_set_cached_class( |
|
906 | + $class_obj, |
|
907 | + $class_name, |
|
908 | + $class_prefix, |
|
909 | + $from_db, |
|
910 | + $arguments |
|
911 | + ); |
|
912 | + } |
|
913 | + $this->_cache_on = true; |
|
914 | + return $class_obj; |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * @param string $class_name |
|
920 | + * @param string $default have to specify something, but not anything that will conflict |
|
921 | + * @return mixed|string |
|
922 | + */ |
|
923 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
924 | + { |
|
925 | + return isset($this->_class_abbreviations[ $class_name ]) |
|
926 | + ? $this->_class_abbreviations[ $class_name ] |
|
927 | + : $default; |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * attempts to find a cached version of the requested class |
|
933 | + * by looking in the following places: |
|
934 | + * $this->{$class_abbreviation} ie: $this->CART |
|
935 | + * $this->{$class_name} ie: $this->Some_Class |
|
936 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
937 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
938 | + * |
|
939 | + * @param string $class_name |
|
940 | + * @param string $class_prefix |
|
941 | + * @param array $arguments |
|
942 | + * @return mixed |
|
943 | + */ |
|
944 | + protected function _get_cached_class( |
|
945 | + $class_name, |
|
946 | + $class_prefix = '', |
|
947 | + $arguments = array() |
|
948 | + ) { |
|
949 | + if ($class_name === 'EE_Registry') { |
|
950 | + return $this; |
|
951 | + } |
|
952 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
953 | + // check if class has already been loaded, and return it if it has been |
|
954 | + if (isset($this->{$class_abbreviation})) { |
|
955 | + return $this->{$class_abbreviation}; |
|
956 | + } |
|
957 | + $class_name = str_replace('\\', '_', $class_name); |
|
958 | + if (isset($this->{$class_name})) { |
|
959 | + return $this->{$class_name}; |
|
960 | + } |
|
961 | + if ($class_prefix === 'addon' && isset($this->addons->{$class_name})) { |
|
962 | + return $this->addons->{$class_name}; |
|
963 | + } |
|
964 | + $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
965 | + if (isset($this->LIB->{$object_identifier})) { |
|
966 | + return $this->LIB->{$object_identifier}; |
|
967 | + } |
|
968 | + foreach ($this->LIB as $key => $object) { |
|
969 | + if (// request does not contain new arguments and therefore no args identifier |
|
970 | + ! $this->object_identifier->hasArguments($object_identifier) |
|
971 | + // but previously cached class with args was found |
|
972 | + && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) |
|
973 | + ) { |
|
974 | + return $object; |
|
975 | + } |
|
976 | + } |
|
977 | + return null; |
|
978 | + } |
|
979 | + |
|
980 | + |
|
981 | + /** |
|
982 | + * removes a cached version of the requested class |
|
983 | + * |
|
984 | + * @param string $class_name |
|
985 | + * @param boolean $addon |
|
986 | + * @param array $arguments |
|
987 | + * @return boolean |
|
988 | + */ |
|
989 | + public function clear_cached_class( |
|
990 | + $class_name, |
|
991 | + $addon = false, |
|
992 | + $arguments = array() |
|
993 | + ) { |
|
994 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
995 | + // check if class has already been loaded, and return it if it has been |
|
996 | + if (isset($this->{$class_abbreviation})) { |
|
997 | + $this->{$class_abbreviation} = null; |
|
998 | + return true; |
|
999 | + } |
|
1000 | + $class_name = str_replace('\\', '_', $class_name); |
|
1001 | + if (isset($this->{$class_name})) { |
|
1002 | + $this->{$class_name} = null; |
|
1003 | + return true; |
|
1004 | + } |
|
1005 | + if ($addon && isset($this->addons->{$class_name})) { |
|
1006 | + unset($this->addons->{$class_name}); |
|
1007 | + return true; |
|
1008 | + } |
|
1009 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1010 | + if (isset($this->LIB->{$class_name})) { |
|
1011 | + unset($this->LIB->{$class_name}); |
|
1012 | + return true; |
|
1013 | + } |
|
1014 | + return false; |
|
1015 | + } |
|
1016 | + |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * _set_cached_class |
|
1020 | + * attempts to cache the instantiated class locally |
|
1021 | + * in one of the following places, in the following order: |
|
1022 | + * $this->{class_abbreviation} ie: $this->CART |
|
1023 | + * $this->{$class_name} ie: $this->Some_Class |
|
1024 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1025 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1026 | + * |
|
1027 | + * @param object $class_obj |
|
1028 | + * @param string $class_name |
|
1029 | + * @param string $class_prefix |
|
1030 | + * @param bool $from_db |
|
1031 | + * @param array $arguments |
|
1032 | + * @return void |
|
1033 | + */ |
|
1034 | + protected function _set_cached_class( |
|
1035 | + $class_obj, |
|
1036 | + $class_name, |
|
1037 | + $class_prefix = '', |
|
1038 | + $from_db = false, |
|
1039 | + $arguments = array() |
|
1040 | + ) { |
|
1041 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1042 | + return; |
|
1043 | + } |
|
1044 | + // return newly instantiated class |
|
1045 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1046 | + if ($class_abbreviation) { |
|
1047 | + $this->{$class_abbreviation} = $class_obj; |
|
1048 | + return; |
|
1049 | + } |
|
1050 | + $class_name = str_replace('\\', '_', $class_name); |
|
1051 | + if (property_exists($this, $class_name)) { |
|
1052 | + $this->{$class_name} = $class_obj; |
|
1053 | + return; |
|
1054 | + } |
|
1055 | + if ($class_prefix === 'addon') { |
|
1056 | + $this->addons->{$class_name} = $class_obj; |
|
1057 | + return; |
|
1058 | + } |
|
1059 | + if (! $from_db) { |
|
1060 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1061 | + $this->LIB->{$class_name} = $class_obj; |
|
1062 | + } |
|
1063 | + } |
|
1064 | + |
|
1065 | + |
|
1066 | + /** |
|
1067 | + * attempts to find a full valid filepath for the requested class. |
|
1068 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
1069 | + * then returns that path if the target file has been found and is readable |
|
1070 | + * |
|
1071 | + * @param string $class_name |
|
1072 | + * @param string $type |
|
1073 | + * @param array $file_paths |
|
1074 | + * @return string | bool |
|
1075 | + */ |
|
1076 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
1077 | + { |
|
1078 | + // make sure $file_paths is an array |
|
1079 | + $file_paths = is_array($file_paths) |
|
1080 | + ? $file_paths |
|
1081 | + : array($file_paths); |
|
1082 | + // cycle thru paths |
|
1083 | + foreach ($file_paths as $key => $file_path) { |
|
1084 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
1085 | + $file_path = $file_path |
|
1086 | + ? str_replace(array('/', '\\'), DS, $file_path) |
|
1087 | + : EE_CLASSES; |
|
1088 | + // prep file type |
|
1089 | + $type = ! empty($type) |
|
1090 | + ? trim($type, '.') . '.' |
|
1091 | + : ''; |
|
1092 | + // build full file path |
|
1093 | + $file_paths[ $key ] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
1094 | + // does the file exist and can be read ? |
|
1095 | + if (is_readable($file_paths[ $key ])) { |
|
1096 | + return $file_paths[ $key ]; |
|
1097 | + } |
|
1098 | + } |
|
1099 | + return false; |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * basically just performs a require_once() |
|
1105 | + * but with some error handling |
|
1106 | + * |
|
1107 | + * @param string $path |
|
1108 | + * @param string $class_name |
|
1109 | + * @param string $type |
|
1110 | + * @param array $file_paths |
|
1111 | + * @return bool |
|
1112 | + * @throws EE_Error |
|
1113 | + * @throws ReflectionException |
|
1114 | + */ |
|
1115 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
1116 | + { |
|
1117 | + $this->resolve_legacy_class_parent($class_name); |
|
1118 | + // don't give up! you gotta... |
|
1119 | + try { |
|
1120 | + // does the file exist and can it be read ? |
|
1121 | + if (! $path) { |
|
1122 | + // just in case the file has already been autoloaded, |
|
1123 | + // but discrepancies in the naming schema are preventing it from |
|
1124 | + // being loaded via one of the EE_Registry::load_*() methods, |
|
1125 | + // then let's try one last hail mary before throwing an exception |
|
1126 | + // and call class_exists() again, but with autoloading turned ON |
|
1127 | + if (class_exists($class_name)) { |
|
1128 | + return true; |
|
1129 | + } |
|
1130 | + // so sorry, can't find the file |
|
1131 | + throw new EE_Error( |
|
1132 | + sprintf( |
|
1133 | + esc_html__( |
|
1134 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
1135 | + 'event_espresso' |
|
1136 | + ), |
|
1137 | + trim($type, '.'), |
|
1138 | + $class_name, |
|
1139 | + '<br />' . implode(',<br />', $file_paths) |
|
1140 | + ) |
|
1141 | + ); |
|
1142 | + } |
|
1143 | + // get the file |
|
1144 | + require_once($path); |
|
1145 | + // if the class isn't already declared somewhere |
|
1146 | + if (class_exists($class_name, false) === false) { |
|
1147 | + // so sorry, not a class |
|
1148 | + throw new EE_Error( |
|
1149 | + sprintf( |
|
1150 | + esc_html__( |
|
1151 | + 'The %s file %s does not appear to contain the %s Class.', |
|
1152 | + 'event_espresso' |
|
1153 | + ), |
|
1154 | + $type, |
|
1155 | + $path, |
|
1156 | + $class_name |
|
1157 | + ) |
|
1158 | + ); |
|
1159 | + } |
|
1160 | + } catch (EE_Error $e) { |
|
1161 | + $e->get_error(); |
|
1162 | + return false; |
|
1163 | + } |
|
1164 | + return true; |
|
1165 | + } |
|
1166 | + |
|
1167 | + |
|
1168 | + /** |
|
1169 | + * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1170 | + * before their class declaration in order to ensure that the parent class was loaded. |
|
1171 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1172 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1173 | + * |
|
1174 | + * @param string $class_name |
|
1175 | + */ |
|
1176 | + protected function resolve_legacy_class_parent($class_name = '') |
|
1177 | + { |
|
1178 | + try { |
|
1179 | + $legacy_parent_class_map = array( |
|
1180 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
|
1181 | + ); |
|
1182 | + if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1183 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1184 | + } |
|
1185 | + } catch (Exception $exception) { |
|
1186 | + } |
|
1187 | + } |
|
1188 | + |
|
1189 | + |
|
1190 | + /** |
|
1191 | + * _create_object |
|
1192 | + * Attempts to instantiate the requested class via any of the |
|
1193 | + * commonly used instantiation methods employed throughout EE. |
|
1194 | + * The priority for instantiation is as follows: |
|
1195 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1196 | + * - model objects via their 'new_instance_from_db' method |
|
1197 | + * - model objects via their 'new_instance' method |
|
1198 | + * - "singleton" classes" via their 'instance' method |
|
1199 | + * - standard instantiable classes via their __constructor |
|
1200 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
1201 | + * then the constructor for the requested class will be examined to determine |
|
1202 | + * if any dependencies exist, and if they can be injected. |
|
1203 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1204 | + * |
|
1205 | + * @param string $class_name |
|
1206 | + * @param array $arguments |
|
1207 | + * @param string $type |
|
1208 | + * @param bool $from_db |
|
1209 | + * @return null|object|bool |
|
1210 | + * @throws InvalidArgumentException |
|
1211 | + * @throws InvalidInterfaceException |
|
1212 | + * @throws EE_Error |
|
1213 | + * @throws ReflectionException |
|
1214 | + * @throws InvalidDataTypeException |
|
1215 | + */ |
|
1216 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1217 | + { |
|
1218 | + // create reflection |
|
1219 | + $reflector = $this->mirror->getReflectionClass($class_name); |
|
1220 | + // make sure arguments are an array |
|
1221 | + $arguments = is_array($arguments) |
|
1222 | + ? $arguments |
|
1223 | + : array($arguments); |
|
1224 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1225 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1226 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1227 | + ? $arguments |
|
1228 | + : array($arguments); |
|
1229 | + // attempt to inject dependencies ? |
|
1230 | + if ($this->_dependency_map->has($class_name)) { |
|
1231 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1232 | + } |
|
1233 | + // instantiate the class if possible |
|
1234 | + if ($reflector->isAbstract()) { |
|
1235 | + // nothing to instantiate, loading file was enough |
|
1236 | + // does not throw an exception so $instantiation_mode is unused |
|
1237 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
1238 | + return true; |
|
1239 | + } |
|
1240 | + if (empty($arguments) |
|
1241 | + && $this->mirror->getConstructorFromReflection($reflector) === null |
|
1242 | + && $reflector->isInstantiable() |
|
1243 | + ) { |
|
1244 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1245 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
1246 | + return $reflector->newInstance(); |
|
1247 | + } |
|
1248 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1249 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
1250 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1251 | + } |
|
1252 | + if (method_exists($class_name, 'new_instance')) { |
|
1253 | + // $instantiation_mode = "4) new_instance()"; |
|
1254 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1255 | + } |
|
1256 | + if (method_exists($class_name, 'instance')) { |
|
1257 | + // $instantiation_mode = "5) instance()"; |
|
1258 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1259 | + } |
|
1260 | + if ($reflector->isInstantiable()) { |
|
1261 | + // $instantiation_mode = "6) constructor"; |
|
1262 | + return $reflector->newInstanceArgs($arguments); |
|
1263 | + } |
|
1264 | + // heh ? something's not right ! |
|
1265 | + throw new EE_Error( |
|
1266 | + sprintf( |
|
1267 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1268 | + $type, |
|
1269 | + $class_name |
|
1270 | + ) |
|
1271 | + ); |
|
1272 | + } |
|
1273 | + |
|
1274 | + |
|
1275 | + /** |
|
1276 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1277 | + * @param array $array |
|
1278 | + * @return bool |
|
1279 | + */ |
|
1280 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1281 | + { |
|
1282 | + return ! empty($array) |
|
1283 | + ? array_keys($array) === range(0, count($array) - 1) |
|
1284 | + : true; |
|
1285 | + } |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * _resolve_dependencies |
|
1290 | + * examines the constructor for the requested class to determine |
|
1291 | + * if any dependencies exist, and if they can be injected. |
|
1292 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1293 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1294 | + * For example: |
|
1295 | + * if attempting to load a class "Foo" with the following constructor: |
|
1296 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1297 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1298 | + * but only IF they are NOT already present in the incoming arguments array, |
|
1299 | + * and the correct classes can be loaded |
|
1300 | + * |
|
1301 | + * @param ReflectionClass $reflector |
|
1302 | + * @param string $class_name |
|
1303 | + * @param array $arguments |
|
1304 | + * @return array |
|
1305 | + * @throws InvalidArgumentException |
|
1306 | + * @throws InvalidDataTypeException |
|
1307 | + * @throws InvalidInterfaceException |
|
1308 | + * @throws ReflectionException |
|
1309 | + */ |
|
1310 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
|
1311 | + { |
|
1312 | + // let's examine the constructor |
|
1313 | + $constructor = $this->mirror->getConstructorFromReflection($reflector); |
|
1314 | + // whu? huh? nothing? |
|
1315 | + if (! $constructor) { |
|
1316 | + return $arguments; |
|
1317 | + } |
|
1318 | + // get constructor parameters |
|
1319 | + $params = $this->mirror->getParametersFromReflection($reflector); |
|
1320 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1321 | + $argument_keys = array_keys($arguments); |
|
1322 | + // now loop thru all of the constructors expected parameters |
|
1323 | + foreach ($params as $index => $param) { |
|
1324 | + // is this a dependency for a specific class ? |
|
1325 | + $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); |
|
1326 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1327 | + $param_class = $this->class_cache->isAlias($param_class, $class_name) |
|
1328 | + ? $this->class_cache->getFqnForAlias($param_class, $class_name) |
|
1329 | + : $param_class; |
|
1330 | + if (// param is not even a class |
|
1331 | + $param_class === null |
|
1332 | + // and something already exists in the incoming arguments for this param |
|
1333 | + && array_key_exists($index, $argument_keys) |
|
1334 | + && array_key_exists($argument_keys[ $index ], $arguments) |
|
1335 | + ) { |
|
1336 | + // so let's skip this argument and move on to the next |
|
1337 | + continue; |
|
1338 | + } |
|
1339 | + if (// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1340 | + $param_class !== null |
|
1341 | + && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1342 | + && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1343 | + ) { |
|
1344 | + // skip this argument and move on to the next |
|
1345 | + continue; |
|
1346 | + } |
|
1347 | + if (// parameter is type hinted as a class, and should be injected |
|
1348 | + $param_class !== null |
|
1349 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1350 | + ) { |
|
1351 | + $arguments = $this->_resolve_dependency( |
|
1352 | + $class_name, |
|
1353 | + $param_class, |
|
1354 | + $arguments, |
|
1355 | + $index |
|
1356 | + ); |
|
1357 | + } else { |
|
1358 | + $arguments[ $index ] = $this->mirror->getParameterDefaultValue( |
|
1359 | + $param, |
|
1360 | + $class_name, |
|
1361 | + $index |
|
1362 | + ); |
|
1363 | + } |
|
1364 | + } |
|
1365 | + return $arguments; |
|
1366 | + } |
|
1367 | + |
|
1368 | + |
|
1369 | + /** |
|
1370 | + * @param string $class_name |
|
1371 | + * @param string $param_class |
|
1372 | + * @param array $arguments |
|
1373 | + * @param mixed $index |
|
1374 | + * @return array |
|
1375 | + * @throws InvalidArgumentException |
|
1376 | + * @throws InvalidInterfaceException |
|
1377 | + * @throws InvalidDataTypeException |
|
1378 | + */ |
|
1379 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1380 | + { |
|
1381 | + $dependency = null; |
|
1382 | + // should dependency be loaded from cache ? |
|
1383 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1384 | + $class_name, |
|
1385 | + $param_class |
|
1386 | + ); |
|
1387 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1388 | + // we might have a dependency... |
|
1389 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1390 | + $cached_class = $cache_on |
|
1391 | + ? $this->_get_cached_class($param_class) |
|
1392 | + : null; |
|
1393 | + // and grab it if it exists |
|
1394 | + if ($cached_class instanceof $param_class) { |
|
1395 | + $dependency = $cached_class; |
|
1396 | + } elseif ($param_class !== $class_name) { |
|
1397 | + // obtain the loader method from the dependency map |
|
1398 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1399 | + // is loader a custom closure ? |
|
1400 | + if ($loader instanceof Closure) { |
|
1401 | + $dependency = $loader($arguments); |
|
1402 | + } else { |
|
1403 | + // set the cache on property for the recursive loading call |
|
1404 | + $this->_cache_on = $cache_on; |
|
1405 | + // if not, then let's try and load it via the registry |
|
1406 | + if ($loader && method_exists($this, $loader)) { |
|
1407 | + $dependency = $this->{$loader}($param_class); |
|
1408 | + } else { |
|
1409 | + $dependency = LoaderFactory::getLoader()->load( |
|
1410 | + $param_class, |
|
1411 | + array(), |
|
1412 | + $cache_on |
|
1413 | + ); |
|
1414 | + } |
|
1415 | + } |
|
1416 | + } |
|
1417 | + // did we successfully find the correct dependency ? |
|
1418 | + if ($dependency instanceof $param_class) { |
|
1419 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1420 | + $arguments[ $index ] = $dependency; |
|
1421 | + } |
|
1422 | + return $arguments; |
|
1423 | + } |
|
1424 | + |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1428 | + * |
|
1429 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1430 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1431 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1432 | + * @param array $arguments |
|
1433 | + * @return object |
|
1434 | + */ |
|
1435 | + public static function factory($classname, $arguments = array()) |
|
1436 | + { |
|
1437 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1438 | + if ($loader instanceof Closure) { |
|
1439 | + return $loader($arguments); |
|
1440 | + } |
|
1441 | + if (method_exists(self::instance(), $loader)) { |
|
1442 | + return self::instance()->{$loader}($classname, $arguments); |
|
1443 | + } |
|
1444 | + return null; |
|
1445 | + } |
|
1446 | + |
|
1447 | + |
|
1448 | + /** |
|
1449 | + * Gets the addon by its class name |
|
1450 | + * |
|
1451 | + * @param string $class_name |
|
1452 | + * @return EE_Addon |
|
1453 | + */ |
|
1454 | + public function getAddon($class_name) |
|
1455 | + { |
|
1456 | + $class_name = str_replace('\\', '_', $class_name); |
|
1457 | + if (isset($this->addons->{$class_name})) { |
|
1458 | + return $this->addons->{$class_name}; |
|
1459 | + } else { |
|
1460 | + return null; |
|
1461 | + } |
|
1462 | + } |
|
1463 | + |
|
1464 | + |
|
1465 | + /** |
|
1466 | + * removes the addon from the internal cache |
|
1467 | + * |
|
1468 | + * @param string $class_name |
|
1469 | + * @return void |
|
1470 | + */ |
|
1471 | + public function removeAddon($class_name) |
|
1472 | + { |
|
1473 | + $class_name = str_replace('\\', '_', $class_name); |
|
1474 | + unset($this->addons->{$class_name}); |
|
1475 | + } |
|
1476 | + |
|
1477 | + |
|
1478 | + /** |
|
1479 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1480 | + * use the get_addon() method above |
|
1481 | + * |
|
1482 | + * @param string $name |
|
1483 | + * @return EE_Addon |
|
1484 | + */ |
|
1485 | + public function get_addon_by_name($name) |
|
1486 | + { |
|
1487 | + foreach ($this->addons as $addon) { |
|
1488 | + if ($addon->name() === $name) { |
|
1489 | + return $addon; |
|
1490 | + } |
|
1491 | + } |
|
1492 | + return null; |
|
1493 | + } |
|
1494 | + |
|
1495 | + |
|
1496 | + /** |
|
1497 | + * Gets an array of all the registered addons, where the keys are their names. |
|
1498 | + * (ie, what each returns for their name() function) |
|
1499 | + * They're already available on EE_Registry::instance()->addons as properties, |
|
1500 | + * where each property's name is the addon's classname, |
|
1501 | + * So if you just want to get the addon by classname, |
|
1502 | + * OR use the get_addon() method above. |
|
1503 | + * PLEASE NOTE: |
|
1504 | + * addons with Fully Qualified Class Names |
|
1505 | + * have had the namespace separators converted to underscores, |
|
1506 | + * so a classname like Fully\Qualified\ClassName |
|
1507 | + * would have been converted to Fully_Qualified_ClassName |
|
1508 | + * |
|
1509 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1510 | + */ |
|
1511 | + public function get_addons_by_name() |
|
1512 | + { |
|
1513 | + $addons = array(); |
|
1514 | + foreach ($this->addons as $addon) { |
|
1515 | + $addons[ $addon->name() ] = $addon; |
|
1516 | + } |
|
1517 | + return $addons; |
|
1518 | + } |
|
1519 | + |
|
1520 | + |
|
1521 | + /** |
|
1522 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1523 | + * a stale copy of it around |
|
1524 | + * |
|
1525 | + * @param string $model_name |
|
1526 | + * @return \EEM_Base |
|
1527 | + * @throws \EE_Error |
|
1528 | + */ |
|
1529 | + public function reset_model($model_name) |
|
1530 | + { |
|
1531 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1532 | + ? "EEM_{$model_name}" |
|
1533 | + : $model_name; |
|
1534 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1535 | + return null; |
|
1536 | + } |
|
1537 | + // get that model reset it and make sure we nuke the old reference to it |
|
1538 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
1539 | + && is_callable( |
|
1540 | + array($model_class_name, 'reset') |
|
1541 | + )) { |
|
1542 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1543 | + } else { |
|
1544 | + throw new EE_Error( |
|
1545 | + sprintf( |
|
1546 | + esc_html__('Model %s does not have a method "reset"', 'event_espresso'), |
|
1547 | + $model_name |
|
1548 | + ) |
|
1549 | + ); |
|
1550 | + } |
|
1551 | + return $this->LIB->{$model_class_name}; |
|
1552 | + } |
|
1553 | + |
|
1554 | + |
|
1555 | + /** |
|
1556 | + * Resets the registry. |
|
1557 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1558 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1559 | + * - $_dependency_map |
|
1560 | + * - $_class_abbreviations |
|
1561 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1562 | + * - $REQ: Still on the same request so no need to change. |
|
1563 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1564 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1565 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1566 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1567 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1568 | + * switch or on the restore. |
|
1569 | + * - $modules |
|
1570 | + * - $shortcodes |
|
1571 | + * - $widgets |
|
1572 | + * |
|
1573 | + * @param boolean $hard [deprecated] |
|
1574 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1575 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1576 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1577 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1578 | + * client |
|
1579 | + * code instead can just change the model context to a different blog id if |
|
1580 | + * necessary |
|
1581 | + * @return EE_Registry |
|
1582 | + * @throws InvalidInterfaceException |
|
1583 | + * @throws InvalidDataTypeException |
|
1584 | + * @throws EE_Error |
|
1585 | + * @throws ReflectionException |
|
1586 | + * @throws InvalidArgumentException |
|
1587 | + */ |
|
1588 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1589 | + { |
|
1590 | + $instance = self::instance(); |
|
1591 | + $instance->_cache_on = true; |
|
1592 | + // reset some "special" classes |
|
1593 | + EEH_Activation::reset(); |
|
1594 | + $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
1595 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1596 | + $instance->CART = null; |
|
1597 | + $instance->MRM = null; |
|
1598 | + $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared( |
|
1599 | + 'EventEspresso\core\services\assets\Registry' |
|
1600 | + ); |
|
1601 | + // messages reset |
|
1602 | + EED_Messages::reset(); |
|
1603 | + // handle of objects cached on LIB |
|
1604 | + foreach (array('LIB', 'modules') as $cache) { |
|
1605 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
1606 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1607 | + unset($instance->{$cache}->{$class_name}); |
|
1608 | + } |
|
1609 | + } |
|
1610 | + } |
|
1611 | + return $instance; |
|
1612 | + } |
|
1613 | + |
|
1614 | + |
|
1615 | + /** |
|
1616 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
1617 | + * if passed object implements InterminableInterface, then return false, |
|
1618 | + * to indicate that it should NOT be cleared from the Registry cache |
|
1619 | + * |
|
1620 | + * @param $object |
|
1621 | + * @param bool $reset_models |
|
1622 | + * @return bool returns true if cached object should be unset |
|
1623 | + */ |
|
1624 | + private static function _reset_and_unset_object($object, $reset_models) |
|
1625 | + { |
|
1626 | + if (! is_object($object)) { |
|
1627 | + // don't unset anything that's not an object |
|
1628 | + return false; |
|
1629 | + } |
|
1630 | + if ($object instanceof EED_Module) { |
|
1631 | + $object::reset(); |
|
1632 | + // don't unset modules |
|
1633 | + return false; |
|
1634 | + } |
|
1635 | + if ($object instanceof ResettableInterface) { |
|
1636 | + if ($object instanceof EEM_Base) { |
|
1637 | + if ($reset_models) { |
|
1638 | + $object->reset(); |
|
1639 | + return true; |
|
1640 | + } |
|
1641 | + return false; |
|
1642 | + } |
|
1643 | + $object->reset(); |
|
1644 | + return true; |
|
1645 | + } |
|
1646 | + if (! $object instanceof InterminableInterface) { |
|
1647 | + return true; |
|
1648 | + } |
|
1649 | + return false; |
|
1650 | + } |
|
1651 | + |
|
1652 | + |
|
1653 | + /** |
|
1654 | + * Gets all the custom post type models defined |
|
1655 | + * |
|
1656 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1657 | + */ |
|
1658 | + public function cpt_models() |
|
1659 | + { |
|
1660 | + $cpt_models = array(); |
|
1661 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1662 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1663 | + $cpt_models[ $short_name ] = $classname; |
|
1664 | + } |
|
1665 | + } |
|
1666 | + return $cpt_models; |
|
1667 | + } |
|
1668 | + |
|
1669 | + |
|
1670 | + /** |
|
1671 | + * @return \EE_Config |
|
1672 | + */ |
|
1673 | + public static function CFG() |
|
1674 | + { |
|
1675 | + return self::instance()->CFG; |
|
1676 | + } |
|
1677 | + |
|
1678 | + |
|
1679 | + /** |
|
1680 | + * @deprecated 4.9.62.p |
|
1681 | + * @param string $class_name |
|
1682 | + * @return ReflectionClass |
|
1683 | + * @throws ReflectionException |
|
1684 | + * @throws InvalidDataTypeException |
|
1685 | + */ |
|
1686 | + public function get_ReflectionClass($class_name) |
|
1687 | + { |
|
1688 | + return $this->mirror->getReflectionClass($class_name); |
|
1689 | + } |
|
1690 | 1690 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.63.rc.019'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.63.rc.019'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -23,296 +23,296 @@ |
||
23 | 23 | abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var string $editor_script_handle |
|
28 | - */ |
|
29 | - private $editor_script_handle; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string $editor_style_handle |
|
33 | - */ |
|
34 | - private $editor_style_handle; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string $script_handle |
|
38 | - */ |
|
39 | - private $script_handle; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string $style_handle |
|
43 | - */ |
|
44 | - private $style_handle; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getEditorScriptHandle() |
|
51 | - { |
|
52 | - return $this->editor_script_handle; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param string $editor_script_handle |
|
58 | - */ |
|
59 | - public function setEditorScriptHandle($editor_script_handle) |
|
60 | - { |
|
61 | - if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
62 | - $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
63 | - } |
|
64 | - $this->editor_script_handle = $editor_script_handle; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getEditorStyleHandle() |
|
72 | - { |
|
73 | - return $this->editor_style_handle; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @param string $editor_style_handle |
|
79 | - */ |
|
80 | - public function setEditorStyleHandle($editor_style_handle) |
|
81 | - { |
|
82 | - if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
83 | - $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
84 | - } |
|
85 | - $this->editor_style_handle = $editor_style_handle; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function getScriptHandle() |
|
93 | - { |
|
94 | - return $this->script_handle; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $script_handle |
|
100 | - */ |
|
101 | - public function setScriptHandle($script_handle) |
|
102 | - { |
|
103 | - if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
104 | - $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
105 | - } |
|
106 | - $this->script_handle = $script_handle; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function getStyleHandle() |
|
114 | - { |
|
115 | - return $this->style_handle; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param string $style_handle |
|
121 | - */ |
|
122 | - public function setStyleHandle($style_handle) |
|
123 | - { |
|
124 | - if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
125 | - $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
126 | - } |
|
127 | - $this->style_handle = $style_handle; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @since $VID:$ |
|
132 | - * @throws InvalidDataTypeException |
|
133 | - * @throws InvalidEntityException |
|
134 | - * @throws DuplicateCollectionIdentifierException |
|
135 | - */ |
|
136 | - public function addAssets() |
|
137 | - { |
|
138 | - $this->addEditorScript($this->getEditorScriptHandle()); |
|
139 | - $this->addEditorStyle($this->getEditorStyleHandle()); |
|
140 | - $this->setScriptHandle($this->getScriptHandle()); |
|
141 | - $this->setStyleHandle($this->getStyleHandle()); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param $handle |
|
147 | - * @param array $dependencies |
|
148 | - * @since $VID:$ |
|
149 | - * @return JavascriptAsset |
|
150 | - * @throws InvalidDataTypeException |
|
151 | - * @throws InvalidEntityException |
|
152 | - * @throws DuplicateCollectionIdentifierException |
|
153 | - */ |
|
154 | - public function addEditorScript($handle, array $dependencies = array()) |
|
155 | - { |
|
156 | - if($this->assets->hasJavascriptAsset($handle)){ |
|
157 | - return $this->assets->getJavascriptAsset($handle); |
|
158 | - } |
|
159 | - return parent::addJavascript( |
|
160 | - $handle, |
|
161 | - $this->registry->getJsUrl( |
|
162 | - $this->domain->assetNamespace(), |
|
163 | - $handle |
|
164 | - ), |
|
165 | - $this->addDefaultBlockScriptDependencies($dependencies) |
|
166 | - ) |
|
167 | - ->setRequiresTranslation(); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param $handle |
|
173 | - * @param array $dependencies |
|
174 | - * @since $VID:$ |
|
175 | - * @return StylesheetAsset |
|
176 | - * @throws InvalidDataTypeException |
|
177 | - * @throws InvalidEntityException |
|
178 | - * @throws DuplicateCollectionIdentifierException |
|
179 | - */ |
|
180 | - public function addEditorStyle($handle, array $dependencies = array()) |
|
181 | - { |
|
182 | - if ($this->assets->hasStylesheetAsset($handle)) { |
|
183 | - return $this->assets->getStylesheetAsset($handle); |
|
184 | - } |
|
185 | - return parent::addStylesheet( |
|
186 | - $handle, |
|
187 | - $this->registry->getCssUrl( |
|
188 | - $this->domain->assetNamespace(), |
|
189 | - $handle |
|
190 | - ), |
|
191 | - $dependencies |
|
192 | - ); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @param $handle |
|
198 | - * @param array $dependencies |
|
199 | - * @since $VID:$ |
|
200 | - * @return JavascriptAsset |
|
201 | - * @throws InvalidDataTypeException |
|
202 | - * @throws InvalidEntityException |
|
203 | - * @throws DuplicateCollectionIdentifierException |
|
204 | - */ |
|
205 | - public function addScript($handle, array $dependencies = array()) |
|
206 | - { |
|
207 | - if ($this->assets->hasJavascriptAsset($handle)) { |
|
208 | - return $this->assets->getJavascriptAsset($handle); |
|
209 | - } |
|
210 | - return parent::addJavascript( |
|
211 | - $handle, |
|
212 | - $this->registry->getJsUrl( |
|
213 | - $this->domain->assetNamespace(), |
|
214 | - $handle |
|
215 | - ), |
|
216 | - $this->addDefaultBlockScriptDependencies($dependencies) |
|
217 | - ) |
|
218 | - ->setRequiresTranslation(); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param $handle |
|
224 | - * @param array $dependencies |
|
225 | - * @since $VID:$ |
|
226 | - * @return StylesheetAsset |
|
227 | - * @throws InvalidDataTypeException |
|
228 | - * @throws InvalidEntityException |
|
229 | - * @throws DuplicateCollectionIdentifierException |
|
230 | - */ |
|
231 | - public function addStyle($handle, array $dependencies = array()) |
|
232 | - { |
|
233 | - if ($this->assets->hasStylesheetAsset($handle)) { |
|
234 | - return $this->assets->getStylesheetAsset($handle); |
|
235 | - } |
|
236 | - return parent::addStylesheet( |
|
237 | - $handle, |
|
238 | - $this->registry->getCssUrl( |
|
239 | - $this->domain->assetNamespace(), |
|
240 | - $handle |
|
241 | - ), |
|
242 | - $dependencies |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @param array $dependencies |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function addDefaultBlockScriptDependencies(array $dependencies) |
|
252 | - { |
|
253 | - $dependencies += array( |
|
254 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | - 'wp-i18n', // Provides localization functions |
|
256 | - 'wp-element', // Provides React.Component |
|
257 | - 'wp-components', // Provides many prebuilt components and controls |
|
258 | - CoreAssetManager::JS_HANDLE_EE_COMPONENTS |
|
259 | - ); |
|
260 | - return $dependencies; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @return JavascriptAsset|null |
|
266 | - */ |
|
267 | - public function getEditorScript() |
|
268 | - { |
|
269 | - return $this->assets->getJavascriptAsset($this->editor_script_handle); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * @return StylesheetAsset|null |
|
275 | - */ |
|
276 | - public function getEditorStyle() |
|
277 | - { |
|
278 | - return $this->assets->getStylesheetAsset($this->editor_style_handle); |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * @return JavascriptAsset|null |
|
284 | - */ |
|
285 | - public function getScript() |
|
286 | - { |
|
287 | - return $this->assets->getJavascriptAsset($this->script_handle); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * @return StylesheetAsset|null |
|
293 | - */ |
|
294 | - public function getStyle() |
|
295 | - { |
|
296 | - return $this->assets->getStylesheetAsset($this->style_handle); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * @return void |
|
302 | - */ |
|
303 | - public function enqueueAssets() |
|
304 | - { |
|
305 | - $assets = array( |
|
306 | - $this->getEditorScript(), |
|
307 | - $this->getEditorStyle(), |
|
308 | - $this->getScript(), |
|
309 | - $this->getStyle(), |
|
310 | - ); |
|
311 | - foreach ($assets as $asset) { |
|
312 | - if ($asset instanceof BrowserAsset && $asset->isRegistered()) { |
|
313 | - $asset->enqueueAsset(); |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
26 | + /** |
|
27 | + * @var string $editor_script_handle |
|
28 | + */ |
|
29 | + private $editor_script_handle; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string $editor_style_handle |
|
33 | + */ |
|
34 | + private $editor_style_handle; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string $script_handle |
|
38 | + */ |
|
39 | + private $script_handle; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string $style_handle |
|
43 | + */ |
|
44 | + private $style_handle; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getEditorScriptHandle() |
|
51 | + { |
|
52 | + return $this->editor_script_handle; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param string $editor_script_handle |
|
58 | + */ |
|
59 | + public function setEditorScriptHandle($editor_script_handle) |
|
60 | + { |
|
61 | + if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
62 | + $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle; |
|
63 | + } |
|
64 | + $this->editor_script_handle = $editor_script_handle; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getEditorStyleHandle() |
|
72 | + { |
|
73 | + return $this->editor_style_handle; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @param string $editor_style_handle |
|
79 | + */ |
|
80 | + public function setEditorStyleHandle($editor_style_handle) |
|
81 | + { |
|
82 | + if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
83 | + $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle; |
|
84 | + } |
|
85 | + $this->editor_style_handle = $editor_style_handle; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function getScriptHandle() |
|
93 | + { |
|
94 | + return $this->script_handle; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $script_handle |
|
100 | + */ |
|
101 | + public function setScriptHandle($script_handle) |
|
102 | + { |
|
103 | + if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
104 | + $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle; |
|
105 | + } |
|
106 | + $this->script_handle = $script_handle; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function getStyleHandle() |
|
114 | + { |
|
115 | + return $this->style_handle; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param string $style_handle |
|
121 | + */ |
|
122 | + public function setStyleHandle($style_handle) |
|
123 | + { |
|
124 | + if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) { |
|
125 | + $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle; |
|
126 | + } |
|
127 | + $this->style_handle = $style_handle; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @since $VID:$ |
|
132 | + * @throws InvalidDataTypeException |
|
133 | + * @throws InvalidEntityException |
|
134 | + * @throws DuplicateCollectionIdentifierException |
|
135 | + */ |
|
136 | + public function addAssets() |
|
137 | + { |
|
138 | + $this->addEditorScript($this->getEditorScriptHandle()); |
|
139 | + $this->addEditorStyle($this->getEditorStyleHandle()); |
|
140 | + $this->setScriptHandle($this->getScriptHandle()); |
|
141 | + $this->setStyleHandle($this->getStyleHandle()); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param $handle |
|
147 | + * @param array $dependencies |
|
148 | + * @since $VID:$ |
|
149 | + * @return JavascriptAsset |
|
150 | + * @throws InvalidDataTypeException |
|
151 | + * @throws InvalidEntityException |
|
152 | + * @throws DuplicateCollectionIdentifierException |
|
153 | + */ |
|
154 | + public function addEditorScript($handle, array $dependencies = array()) |
|
155 | + { |
|
156 | + if($this->assets->hasJavascriptAsset($handle)){ |
|
157 | + return $this->assets->getJavascriptAsset($handle); |
|
158 | + } |
|
159 | + return parent::addJavascript( |
|
160 | + $handle, |
|
161 | + $this->registry->getJsUrl( |
|
162 | + $this->domain->assetNamespace(), |
|
163 | + $handle |
|
164 | + ), |
|
165 | + $this->addDefaultBlockScriptDependencies($dependencies) |
|
166 | + ) |
|
167 | + ->setRequiresTranslation(); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param $handle |
|
173 | + * @param array $dependencies |
|
174 | + * @since $VID:$ |
|
175 | + * @return StylesheetAsset |
|
176 | + * @throws InvalidDataTypeException |
|
177 | + * @throws InvalidEntityException |
|
178 | + * @throws DuplicateCollectionIdentifierException |
|
179 | + */ |
|
180 | + public function addEditorStyle($handle, array $dependencies = array()) |
|
181 | + { |
|
182 | + if ($this->assets->hasStylesheetAsset($handle)) { |
|
183 | + return $this->assets->getStylesheetAsset($handle); |
|
184 | + } |
|
185 | + return parent::addStylesheet( |
|
186 | + $handle, |
|
187 | + $this->registry->getCssUrl( |
|
188 | + $this->domain->assetNamespace(), |
|
189 | + $handle |
|
190 | + ), |
|
191 | + $dependencies |
|
192 | + ); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @param $handle |
|
198 | + * @param array $dependencies |
|
199 | + * @since $VID:$ |
|
200 | + * @return JavascriptAsset |
|
201 | + * @throws InvalidDataTypeException |
|
202 | + * @throws InvalidEntityException |
|
203 | + * @throws DuplicateCollectionIdentifierException |
|
204 | + */ |
|
205 | + public function addScript($handle, array $dependencies = array()) |
|
206 | + { |
|
207 | + if ($this->assets->hasJavascriptAsset($handle)) { |
|
208 | + return $this->assets->getJavascriptAsset($handle); |
|
209 | + } |
|
210 | + return parent::addJavascript( |
|
211 | + $handle, |
|
212 | + $this->registry->getJsUrl( |
|
213 | + $this->domain->assetNamespace(), |
|
214 | + $handle |
|
215 | + ), |
|
216 | + $this->addDefaultBlockScriptDependencies($dependencies) |
|
217 | + ) |
|
218 | + ->setRequiresTranslation(); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param $handle |
|
224 | + * @param array $dependencies |
|
225 | + * @since $VID:$ |
|
226 | + * @return StylesheetAsset |
|
227 | + * @throws InvalidDataTypeException |
|
228 | + * @throws InvalidEntityException |
|
229 | + * @throws DuplicateCollectionIdentifierException |
|
230 | + */ |
|
231 | + public function addStyle($handle, array $dependencies = array()) |
|
232 | + { |
|
233 | + if ($this->assets->hasStylesheetAsset($handle)) { |
|
234 | + return $this->assets->getStylesheetAsset($handle); |
|
235 | + } |
|
236 | + return parent::addStylesheet( |
|
237 | + $handle, |
|
238 | + $this->registry->getCssUrl( |
|
239 | + $this->domain->assetNamespace(), |
|
240 | + $handle |
|
241 | + ), |
|
242 | + $dependencies |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @param array $dependencies |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function addDefaultBlockScriptDependencies(array $dependencies) |
|
252 | + { |
|
253 | + $dependencies += array( |
|
254 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
255 | + 'wp-i18n', // Provides localization functions |
|
256 | + 'wp-element', // Provides React.Component |
|
257 | + 'wp-components', // Provides many prebuilt components and controls |
|
258 | + CoreAssetManager::JS_HANDLE_EE_COMPONENTS |
|
259 | + ); |
|
260 | + return $dependencies; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @return JavascriptAsset|null |
|
266 | + */ |
|
267 | + public function getEditorScript() |
|
268 | + { |
|
269 | + return $this->assets->getJavascriptAsset($this->editor_script_handle); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @return StylesheetAsset|null |
|
275 | + */ |
|
276 | + public function getEditorStyle() |
|
277 | + { |
|
278 | + return $this->assets->getStylesheetAsset($this->editor_style_handle); |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * @return JavascriptAsset|null |
|
284 | + */ |
|
285 | + public function getScript() |
|
286 | + { |
|
287 | + return $this->assets->getJavascriptAsset($this->script_handle); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * @return StylesheetAsset|null |
|
293 | + */ |
|
294 | + public function getStyle() |
|
295 | + { |
|
296 | + return $this->assets->getStylesheetAsset($this->style_handle); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * @return void |
|
302 | + */ |
|
303 | + public function enqueueAssets() |
|
304 | + { |
|
305 | + $assets = array( |
|
306 | + $this->getEditorScript(), |
|
307 | + $this->getEditorStyle(), |
|
308 | + $this->getScript(), |
|
309 | + $this->getStyle(), |
|
310 | + ); |
|
311 | + foreach ($assets as $asset) { |
|
312 | + if ($asset instanceof BrowserAsset && $asset->isRegistered()) { |
|
313 | + $asset->enqueueAsset(); |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | 317 | |
318 | 318 | } |