Complex classes like EE_Front_Controller often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EE_Front_Controller, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | final class EE_Front_Controller |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * @var string $_template_path |
||
36 | */ |
||
37 | private $_template_path; |
||
38 | |||
39 | /** |
||
40 | * @var string $_template |
||
41 | */ |
||
42 | private $_template; |
||
43 | |||
44 | /** |
||
45 | * @type EE_Registry $Registry |
||
46 | */ |
||
47 | protected $Registry; |
||
48 | |||
49 | /** |
||
50 | * @type EE_Request_Handler $Request_Handler |
||
51 | */ |
||
52 | protected $Request_Handler; |
||
53 | |||
54 | /** |
||
55 | * @type EE_Module_Request_Router $Module_Request_Router |
||
56 | */ |
||
57 | protected $Module_Request_Router; |
||
58 | |||
59 | /** |
||
60 | * @var PersistentAdminNoticeManager $persistent_admin_notice_manager |
||
61 | */ |
||
62 | private $persistent_admin_notice_manager; |
||
63 | |||
64 | |||
65 | /** |
||
66 | * class constructor |
||
67 | * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
||
68 | * |
||
69 | * @access public |
||
70 | * @param \EE_Registry $Registry |
||
71 | * @param \EE_Request_Handler $Request_Handler |
||
72 | * @param \EE_Module_Request_Router $Module_Request_Router |
||
73 | */ |
||
74 | public function __construct( |
||
115 | |||
116 | |||
117 | /** |
||
118 | * @return EE_Request_Handler |
||
119 | */ |
||
120 | public function Request_Handler() |
||
124 | |||
125 | |||
126 | /** |
||
127 | * @return EE_Module_Request_Router |
||
128 | */ |
||
129 | public function Module_Request_Router() |
||
133 | |||
134 | |||
135 | |||
136 | /** |
||
137 | * @return LegacyShortcodesManager |
||
138 | */ |
||
139 | public function getLegacyShortcodesManager() |
||
143 | |||
144 | |||
145 | |||
146 | |||
147 | |||
148 | /*********************************************** INIT ACTION HOOK ***********************************************/ |
||
149 | |||
150 | |||
151 | |||
152 | /** |
||
153 | * filter_wp_comments |
||
154 | * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
||
155 | * widgets/queries done on frontend |
||
156 | * |
||
157 | * @param array $clauses array of comment clauses setup by WP_Comment_Query |
||
158 | * @return array array of comment clauses with modifications. |
||
159 | */ |
||
160 | public function filter_wp_comments($clauses) |
||
171 | |||
172 | |||
173 | /** |
||
174 | * @return void |
||
175 | * @throws EE_Error |
||
176 | * @throws ReflectionException |
||
177 | */ |
||
178 | public function employ_CPT_Strategy() |
||
184 | |||
185 | |||
186 | /** |
||
187 | * @return void |
||
188 | * @throws InvalidArgumentException |
||
189 | * @throws InvalidDataTypeException |
||
190 | * @throws InvalidInterfaceException |
||
191 | */ |
||
192 | public function loadPersistentAdminNoticeManager() |
||
198 | |||
199 | |||
200 | /** |
||
201 | * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
||
202 | * |
||
203 | * @param string $url incoming url |
||
204 | * @return string final assembled url |
||
205 | */ |
||
206 | public function maybe_force_admin_ajax_ssl($url) |
||
213 | |||
214 | |||
215 | |||
216 | |||
217 | |||
218 | |||
219 | /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
||
220 | |||
221 | |||
222 | /** |
||
223 | * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
||
224 | * default priority init phases have run |
||
225 | * |
||
226 | * @access public |
||
227 | * @return void |
||
228 | */ |
||
229 | public function wp_loaded() |
||
232 | |||
233 | |||
234 | |||
235 | |||
236 | |||
237 | /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
||
238 | /** |
||
239 | * _get_request |
||
240 | * |
||
241 | * @access public |
||
242 | * @param WP $WP |
||
243 | * @return void |
||
244 | */ |
||
245 | public function get_request(WP $WP) |
||
251 | |||
252 | |||
253 | |||
254 | /** |
||
255 | * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
||
256 | * |
||
257 | * @access public |
||
258 | * @param WP_Query $WP_Query |
||
259 | * @return void |
||
260 | */ |
||
261 | public function pre_get_posts($WP_Query) |
||
283 | |||
284 | |||
285 | |||
286 | |||
287 | |||
288 | /*********************************************** WP HOOK ***********************************************/ |
||
289 | |||
290 | |||
291 | /** |
||
292 | * wp - basically last chance to do stuff before headers sent |
||
293 | * |
||
294 | * @access public |
||
295 | * @return void |
||
296 | */ |
||
297 | public function wp() |
||
300 | |||
301 | |||
302 | |||
303 | /*********************** GET_HEADER && WP_HEAD HOOK ***********************/ |
||
304 | |||
305 | |||
306 | |||
307 | /** |
||
308 | * callback for the "template_redirect" hook point |
||
309 | * checks sidebars for EE widgets |
||
310 | * loads resources and assets accordingly |
||
311 | * |
||
312 | * @return void |
||
313 | */ |
||
314 | public function templateRedirect() |
||
329 | |||
330 | |||
331 | |||
332 | /** |
||
333 | * builds list of active widgets then scans active sidebars looking for them |
||
334 | * returns true is an EE widget is found in an active sidebar |
||
335 | * Please Note: this does NOT mean that the sidebar or widget |
||
336 | * is actually in use in a given template, as that is unfortunately not known |
||
337 | * until a sidebar and it's widgets are actually loaded |
||
338 | * |
||
339 | * @return boolean |
||
340 | */ |
||
341 | private function espresso_widgets_in_active_sidebars() |
||
364 | |||
365 | |||
366 | |||
367 | |||
368 | /** |
||
369 | * header_meta_tag |
||
370 | * |
||
371 | * @access public |
||
372 | * @return void |
||
373 | */ |
||
374 | public function header_meta_tag() |
||
400 | |||
401 | |||
402 | |||
403 | /** |
||
404 | * wp_print_scripts |
||
405 | * |
||
406 | * @return void |
||
407 | */ |
||
408 | public function wp_print_scripts() |
||
420 | |||
421 | |||
422 | |||
423 | public function enqueueStyle() |
||
428 | |||
429 | |||
430 | |||
431 | |||
432 | /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
||
433 | |||
434 | |||
435 | |||
436 | // /** |
||
437 | // * the_content |
||
438 | // * |
||
439 | // * @access public |
||
440 | // * @param $the_content |
||
441 | // * @return string |
||
442 | // */ |
||
443 | // public function the_content( $the_content ) { |
||
444 | // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
||
445 | // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
||
446 | // } |
||
447 | // return $the_content; |
||
448 | // } |
||
449 | |||
450 | |||
451 | |||
452 | /*********************************************** WP_FOOTER ***********************************************/ |
||
453 | |||
454 | |||
455 | |||
456 | public function enqueueScripts() |
||
460 | |||
461 | |||
462 | |||
463 | /** |
||
464 | * display_errors |
||
465 | * |
||
466 | * @access public |
||
467 | * @return void |
||
468 | * @throws DomainException |
||
469 | */ |
||
470 | public function display_errors() |
||
488 | |||
489 | |||
490 | |||
491 | |||
492 | |||
493 | /*********************************************** UTILITIES ***********************************************/ |
||
494 | /** |
||
495 | * template_include |
||
496 | * |
||
497 | * @access public |
||
498 | * @param string $template_include_path |
||
499 | * @return string |
||
500 | */ |
||
501 | public function template_include($template_include_path = null) |
||
512 | |||
513 | |||
514 | /** |
||
515 | * get_selected_template |
||
516 | * |
||
517 | * @access public |
||
518 | * @param bool $with_path |
||
519 | * @return string |
||
520 | */ |
||
521 | public function get_selected_template($with_path = false) |
||
525 | |||
526 | |||
527 | |||
528 | /** |
||
529 | * @deprecated 4.9.26 |
||
530 | * @param string $shortcode_class |
||
531 | * @param \WP $wp |
||
532 | */ |
||
533 | public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
||
545 | |||
546 | } |
||
547 | // End of file EE_Front_Controller.core.php |
||
549 |