@@ -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 | |
| 64 | 64 | } else { |
| 65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | - /** |
|
| 68 | - * espresso_minimum_php_version_error |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - function espresso_minimum_php_version_error() |
|
| 72 | - { |
|
| 73 | - ?> |
|
| 65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
| 66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
| 67 | + /** |
|
| 68 | + * espresso_minimum_php_version_error |
|
| 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.59.rc.013'); |
|
| 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.59.rc.013'); |
|
| 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 | } |
@@ -45,208 +45,208 @@ |
||
| 45 | 45 | class BootstrapCore |
| 46 | 46 | { |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @type LoaderInterface $loader |
|
| 50 | - */ |
|
| 51 | - private $loader; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var RequestInterface $request |
|
| 55 | - */ |
|
| 56 | - protected $request; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var ResponseInterface $response |
|
| 60 | - */ |
|
| 61 | - protected $response; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var RequestStackBuilder $request_stack_builder |
|
| 65 | - */ |
|
| 66 | - protected $request_stack_builder; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var RequestStack $request_stack |
|
| 70 | - */ |
|
| 71 | - protected $request_stack; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * BootstrapCore constructor. |
|
| 76 | - */ |
|
| 77 | - public function __construct() |
|
| 78 | - { |
|
| 79 | - // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
| 80 | - add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @throws InvalidRequestStackMiddlewareException |
|
| 86 | - * @throws EE_Error |
|
| 87 | - * @throws InvalidArgumentException |
|
| 88 | - * @throws InvalidDataTypeException |
|
| 89 | - * @throws InvalidInterfaceException |
|
| 90 | - * @throws ReflectionException |
|
| 91 | - */ |
|
| 92 | - public function initialize() |
|
| 93 | - { |
|
| 94 | - $this->bootstrapDependencyInjectionContainer(); |
|
| 95 | - $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
| 96 | - add_action( |
|
| 97 | - 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
| 98 | - array($bootstrap_request, 'setupLegacyRequest') |
|
| 99 | - ); |
|
| 100 | - $this->runRequestStack(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @throws ReflectionException |
|
| 106 | - * @throws EE_Error |
|
| 107 | - * @throws InvalidArgumentException |
|
| 108 | - * @throws InvalidDataTypeException |
|
| 109 | - * @throws InvalidInterfaceException |
|
| 110 | - */ |
|
| 111 | - private function bootstrapDependencyInjectionContainer() |
|
| 112 | - { |
|
| 113 | - $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
| 114 | - $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
| 115 | - $bootstrap_di->buildLoader(); |
|
| 116 | - $registry = $bootstrap_di->getRegistry(); |
|
| 117 | - $dependency_map = $bootstrap_di->getDependencyMap(); |
|
| 118 | - $dependency_map->initialize(); |
|
| 119 | - $registry->initialize(); |
|
| 120 | - $this->loader = $bootstrap_di->getLoader(); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * sets up the request and response objects |
|
| 126 | - * |
|
| 127 | - * @return BootstrapRequestResponseObjects |
|
| 128 | - * @throws InvalidArgumentException |
|
| 129 | - */ |
|
| 130 | - private function bootstrapRequestResponseObjects() |
|
| 131 | - { |
|
| 132 | - /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
| 133 | - $bootstrap_request = $this->loader->getShared( |
|
| 134 | - 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
| 135 | - array($this->loader) |
|
| 136 | - ); |
|
| 137 | - $bootstrap_request->buildRequestResponse(); |
|
| 138 | - $bootstrap_request->shareRequestResponse(); |
|
| 139 | - $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 140 | - $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
| 141 | - return $bootstrap_request; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * run_request_stack |
|
| 147 | - * construct request stack and run middleware apps |
|
| 148 | - * |
|
| 149 | - * @throws InvalidRequestStackMiddlewareException |
|
| 150 | - * @throws InvalidInterfaceException |
|
| 151 | - * @throws InvalidDataTypeException |
|
| 152 | - * @throws EE_Error |
|
| 153 | - * @throws InvalidArgumentException |
|
| 154 | - * @throws ReflectionException |
|
| 155 | - */ |
|
| 156 | - public function runRequestStack() |
|
| 157 | - { |
|
| 158 | - $this->loadAutoloader(); |
|
| 159 | - $this->setAutoloadersForRequiredFiles(); |
|
| 160 | - $this->request_stack_builder = $this->buildRequestStack(); |
|
| 161 | - $this->request_stack = $this->request_stack_builder->resolve( |
|
| 162 | - new RequestStackCoreApp() |
|
| 163 | - ); |
|
| 164 | - $this->request_stack->handleRequest($this->request, $this->response); |
|
| 165 | - $this->request_stack->handleResponse(); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * load_autoloader |
|
| 171 | - * |
|
| 172 | - * @throws EE_Error |
|
| 173 | - */ |
|
| 174 | - protected function loadAutoloader() |
|
| 175 | - { |
|
| 176 | - // load interfaces |
|
| 177 | - espresso_load_required( |
|
| 178 | - 'EEH_Autoloader', |
|
| 179 | - EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
| 180 | - ); |
|
| 181 | - EEH_Autoloader::instance(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * load_required_files |
|
| 188 | - * |
|
| 189 | - * @throws EE_Error |
|
| 190 | - */ |
|
| 191 | - protected function setAutoloadersForRequiredFiles() |
|
| 192 | - { |
|
| 193 | - // load interfaces |
|
| 194 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
| 195 | - // load helpers |
|
| 196 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 197 | - // load request stack |
|
| 198 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
| 199 | - // load middleware |
|
| 200 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * build_request_stack |
|
| 207 | - * |
|
| 208 | - * @return RequestStackBuilder |
|
| 209 | - */ |
|
| 210 | - public function buildRequestStack() |
|
| 211 | - { |
|
| 212 | - $request_stack_builder = new RequestStackBuilder($this->loader); |
|
| 213 | - /** |
|
| 214 | - * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
| 215 | - * so items at the beginning of the final middleware stack will run last. |
|
| 216 | - * First parameter is the middleware classname, second is an array of arguments |
|
| 217 | - */ |
|
| 218 | - $stack_apps = apply_filters( |
|
| 219 | - 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
| 220 | - array( |
|
| 221 | - // first in last out |
|
| 222 | - 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
| 223 | - 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
| 224 | - 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
| 225 | - 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
| 226 | - // last in first out |
|
| 227 | - 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
| 228 | - ) |
|
| 229 | - ); |
|
| 230 | - // legacy filter for backwards compatibility |
|
| 231 | - $stack_apps = apply_filters( |
|
| 232 | - 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
| 233 | - $stack_apps |
|
| 234 | - ); |
|
| 235 | - // load middleware onto stack : FILO (First In Last Out) |
|
| 236 | - // items at the beginning of the $stack_apps array will run last |
|
| 237 | - foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
| 238 | - $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
| 239 | - } |
|
| 240 | - // finally, we'll add this on its own because we need it to always be part of the stack |
|
| 241 | - // and we also need it to always run first because the rest of the system relies on it |
|
| 242 | - $request_stack_builder->push( |
|
| 243 | - array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
| 244 | - ); |
|
| 245 | - return apply_filters( |
|
| 246 | - 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
| 247 | - $request_stack_builder |
|
| 248 | - ); |
|
| 249 | - } |
|
| 48 | + /** |
|
| 49 | + * @type LoaderInterface $loader |
|
| 50 | + */ |
|
| 51 | + private $loader; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var RequestInterface $request |
|
| 55 | + */ |
|
| 56 | + protected $request; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var ResponseInterface $response |
|
| 60 | + */ |
|
| 61 | + protected $response; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var RequestStackBuilder $request_stack_builder |
|
| 65 | + */ |
|
| 66 | + protected $request_stack_builder; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var RequestStack $request_stack |
|
| 70 | + */ |
|
| 71 | + protected $request_stack; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * BootstrapCore constructor. |
|
| 76 | + */ |
|
| 77 | + public function __construct() |
|
| 78 | + { |
|
| 79 | + // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
| 80 | + add_action('plugins_loaded', array($this, 'initialize'), 0); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @throws InvalidRequestStackMiddlewareException |
|
| 86 | + * @throws EE_Error |
|
| 87 | + * @throws InvalidArgumentException |
|
| 88 | + * @throws InvalidDataTypeException |
|
| 89 | + * @throws InvalidInterfaceException |
|
| 90 | + * @throws ReflectionException |
|
| 91 | + */ |
|
| 92 | + public function initialize() |
|
| 93 | + { |
|
| 94 | + $this->bootstrapDependencyInjectionContainer(); |
|
| 95 | + $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
| 96 | + add_action( |
|
| 97 | + 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
| 98 | + array($bootstrap_request, 'setupLegacyRequest') |
|
| 99 | + ); |
|
| 100 | + $this->runRequestStack(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @throws ReflectionException |
|
| 106 | + * @throws EE_Error |
|
| 107 | + * @throws InvalidArgumentException |
|
| 108 | + * @throws InvalidDataTypeException |
|
| 109 | + * @throws InvalidInterfaceException |
|
| 110 | + */ |
|
| 111 | + private function bootstrapDependencyInjectionContainer() |
|
| 112 | + { |
|
| 113 | + $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
| 114 | + $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
| 115 | + $bootstrap_di->buildLoader(); |
|
| 116 | + $registry = $bootstrap_di->getRegistry(); |
|
| 117 | + $dependency_map = $bootstrap_di->getDependencyMap(); |
|
| 118 | + $dependency_map->initialize(); |
|
| 119 | + $registry->initialize(); |
|
| 120 | + $this->loader = $bootstrap_di->getLoader(); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * sets up the request and response objects |
|
| 126 | + * |
|
| 127 | + * @return BootstrapRequestResponseObjects |
|
| 128 | + * @throws InvalidArgumentException |
|
| 129 | + */ |
|
| 130 | + private function bootstrapRequestResponseObjects() |
|
| 131 | + { |
|
| 132 | + /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
| 133 | + $bootstrap_request = $this->loader->getShared( |
|
| 134 | + 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
| 135 | + array($this->loader) |
|
| 136 | + ); |
|
| 137 | + $bootstrap_request->buildRequestResponse(); |
|
| 138 | + $bootstrap_request->shareRequestResponse(); |
|
| 139 | + $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 140 | + $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
| 141 | + return $bootstrap_request; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * run_request_stack |
|
| 147 | + * construct request stack and run middleware apps |
|
| 148 | + * |
|
| 149 | + * @throws InvalidRequestStackMiddlewareException |
|
| 150 | + * @throws InvalidInterfaceException |
|
| 151 | + * @throws InvalidDataTypeException |
|
| 152 | + * @throws EE_Error |
|
| 153 | + * @throws InvalidArgumentException |
|
| 154 | + * @throws ReflectionException |
|
| 155 | + */ |
|
| 156 | + public function runRequestStack() |
|
| 157 | + { |
|
| 158 | + $this->loadAutoloader(); |
|
| 159 | + $this->setAutoloadersForRequiredFiles(); |
|
| 160 | + $this->request_stack_builder = $this->buildRequestStack(); |
|
| 161 | + $this->request_stack = $this->request_stack_builder->resolve( |
|
| 162 | + new RequestStackCoreApp() |
|
| 163 | + ); |
|
| 164 | + $this->request_stack->handleRequest($this->request, $this->response); |
|
| 165 | + $this->request_stack->handleResponse(); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * load_autoloader |
|
| 171 | + * |
|
| 172 | + * @throws EE_Error |
|
| 173 | + */ |
|
| 174 | + protected function loadAutoloader() |
|
| 175 | + { |
|
| 176 | + // load interfaces |
|
| 177 | + espresso_load_required( |
|
| 178 | + 'EEH_Autoloader', |
|
| 179 | + EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' |
|
| 180 | + ); |
|
| 181 | + EEH_Autoloader::instance(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * load_required_files |
|
| 188 | + * |
|
| 189 | + * @throws EE_Error |
|
| 190 | + */ |
|
| 191 | + protected function setAutoloadersForRequiredFiles() |
|
| 192 | + { |
|
| 193 | + // load interfaces |
|
| 194 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
| 195 | + // load helpers |
|
| 196 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
| 197 | + // load request stack |
|
| 198 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack' . DS); |
|
| 199 | + // load middleware |
|
| 200 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware' . DS); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * build_request_stack |
|
| 207 | + * |
|
| 208 | + * @return RequestStackBuilder |
|
| 209 | + */ |
|
| 210 | + public function buildRequestStack() |
|
| 211 | + { |
|
| 212 | + $request_stack_builder = new RequestStackBuilder($this->loader); |
|
| 213 | + /** |
|
| 214 | + * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
| 215 | + * so items at the beginning of the final middleware stack will run last. |
|
| 216 | + * First parameter is the middleware classname, second is an array of arguments |
|
| 217 | + */ |
|
| 218 | + $stack_apps = apply_filters( |
|
| 219 | + 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
| 220 | + array( |
|
| 221 | + // first in last out |
|
| 222 | + 'EventEspresso\core\services\request\middleware\BotDetector' => array(), |
|
| 223 | + 'EventEspresso\core\services\request\middleware\DetectFileEditorRequest' => array(), |
|
| 224 | + 'EventEspresso\core\services\request\middleware\PreProductionVersionWarning' => array(), |
|
| 225 | + 'EventEspresso\core\services\request\middleware\RecommendedVersions' => array(), |
|
| 226 | + // last in first out |
|
| 227 | + 'EventEspresso\core\services\request\middleware\DetectLogin' => array(), |
|
| 228 | + ) |
|
| 229 | + ); |
|
| 230 | + // legacy filter for backwards compatibility |
|
| 231 | + $stack_apps = apply_filters( |
|
| 232 | + 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
| 233 | + $stack_apps |
|
| 234 | + ); |
|
| 235 | + // load middleware onto stack : FILO (First In Last Out) |
|
| 236 | + // items at the beginning of the $stack_apps array will run last |
|
| 237 | + foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
| 238 | + $request_stack_builder->push(array($stack_app, $stack_app_args)); |
|
| 239 | + } |
|
| 240 | + // finally, we'll add this on its own because we need it to always be part of the stack |
|
| 241 | + // and we also need it to always run first because the rest of the system relies on it |
|
| 242 | + $request_stack_builder->push( |
|
| 243 | + array('EventEspresso\core\services\request\middleware\SetRequestTypeContextChecker', array()) |
|
| 244 | + ); |
|
| 245 | + return apply_filters( |
|
| 246 | + 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
| 247 | + $request_stack_builder |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | 251 | |
| 252 | 252 | } |
@@ -22,81 +22,81 @@ |
||
| 22 | 22 | class RequestStackBuilder extends SplDoublyLinkedList |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @type LoaderInterface $loader |
|
| 27 | - */ |
|
| 28 | - private $loader; |
|
| 25 | + /** |
|
| 26 | + * @type LoaderInterface $loader |
|
| 27 | + */ |
|
| 28 | + private $loader; |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * RequestStackBuilder constructor. |
|
| 33 | - * |
|
| 34 | - * @param LoaderInterface $loader |
|
| 35 | - */ |
|
| 36 | - public function __construct(LoaderInterface $loader) |
|
| 37 | - { |
|
| 38 | - $this->loader = $loader; |
|
| 39 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 40 | - } |
|
| 31 | + /** |
|
| 32 | + * RequestStackBuilder constructor. |
|
| 33 | + * |
|
| 34 | + * @param LoaderInterface $loader |
|
| 35 | + */ |
|
| 36 | + public function __construct(LoaderInterface $loader) |
|
| 37 | + { |
|
| 38 | + $this->loader = $loader; |
|
| 39 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * builds decorated middleware stack |
|
| 45 | - * by continuously injecting previous middleware app into the next |
|
| 46 | - * |
|
| 47 | - * @param RequestStackCoreAppInterface $application |
|
| 48 | - * @return RequestStack |
|
| 49 | - * @throws InvalidRequestStackMiddlewareException |
|
| 50 | - */ |
|
| 51 | - public function resolve(RequestStackCoreAppInterface $application) |
|
| 52 | - { |
|
| 53 | - $core_app = $application; |
|
| 54 | - // NOW... because the RequestStack is following the decorator pattern, |
|
| 55 | - // the first stack app we add will end up at the center of the stack, |
|
| 56 | - // and will end up being the last item to actually run, but we don't want that! |
|
| 57 | - // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 58 | - // BUT... we want the final stack to be in the same order as the first. |
|
| 59 | - // So we need to reverse the iterator mode when transferring items, |
|
| 60 | - // because if we don't, the second stack will end up in the incorrect order. |
|
| 61 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 62 | - for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 63 | - $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 64 | - $middleware_app_class = array_shift($middleware_app); |
|
| 65 | - $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 66 | - $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 67 | - $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 68 | - } |
|
| 69 | - return new RequestStack($application, $core_app); |
|
| 70 | - } |
|
| 43 | + /** |
|
| 44 | + * builds decorated middleware stack |
|
| 45 | + * by continuously injecting previous middleware app into the next |
|
| 46 | + * |
|
| 47 | + * @param RequestStackCoreAppInterface $application |
|
| 48 | + * @return RequestStack |
|
| 49 | + * @throws InvalidRequestStackMiddlewareException |
|
| 50 | + */ |
|
| 51 | + public function resolve(RequestStackCoreAppInterface $application) |
|
| 52 | + { |
|
| 53 | + $core_app = $application; |
|
| 54 | + // NOW... because the RequestStack is following the decorator pattern, |
|
| 55 | + // the first stack app we add will end up at the center of the stack, |
|
| 56 | + // and will end up being the last item to actually run, but we don't want that! |
|
| 57 | + // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 58 | + // BUT... we want the final stack to be in the same order as the first. |
|
| 59 | + // So we need to reverse the iterator mode when transferring items, |
|
| 60 | + // because if we don't, the second stack will end up in the incorrect order. |
|
| 61 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 62 | + for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 63 | + $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 64 | + $middleware_app_class = array_shift($middleware_app); |
|
| 65 | + $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 66 | + $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 67 | + $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 68 | + } |
|
| 69 | + return new RequestStack($application, $core_app); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 75 | - * are all ordered correctly so that the middleware can be properly constructed |
|
| 76 | - * |
|
| 77 | - * @param array $middleware_app |
|
| 78 | - * @param bool $recurse |
|
| 79 | - * @return array |
|
| 80 | - * @throws InvalidRequestStackMiddlewareException |
|
| 81 | - */ |
|
| 82 | - private function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 83 | - { |
|
| 84 | - $middleware_app_class = reset($middleware_app); |
|
| 85 | - // is array empty ? |
|
| 86 | - if($middleware_app_class === false) { |
|
| 87 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 88 | - } |
|
| 89 | - // are the class and arguments in the wrong order ? |
|
| 90 | - if(is_array($middleware_app_class)) { |
|
| 91 | - if ($recurse === true) { |
|
| 92 | - return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 93 | - } |
|
| 94 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 95 | - } |
|
| 96 | - // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 97 | - if(! class_exists($middleware_app_class)) { |
|
| 98 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 99 | - } |
|
| 100 | - return $middleware_app; |
|
| 101 | - } |
|
| 73 | + /** |
|
| 74 | + * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 75 | + * are all ordered correctly so that the middleware can be properly constructed |
|
| 76 | + * |
|
| 77 | + * @param array $middleware_app |
|
| 78 | + * @param bool $recurse |
|
| 79 | + * @return array |
|
| 80 | + * @throws InvalidRequestStackMiddlewareException |
|
| 81 | + */ |
|
| 82 | + private function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 83 | + { |
|
| 84 | + $middleware_app_class = reset($middleware_app); |
|
| 85 | + // is array empty ? |
|
| 86 | + if($middleware_app_class === false) { |
|
| 87 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 88 | + } |
|
| 89 | + // are the class and arguments in the wrong order ? |
|
| 90 | + if(is_array($middleware_app_class)) { |
|
| 91 | + if ($recurse === true) { |
|
| 92 | + return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 93 | + } |
|
| 94 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 95 | + } |
|
| 96 | + // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 97 | + if(! class_exists($middleware_app_class)) { |
|
| 98 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 99 | + } |
|
| 100 | + return $middleware_app; |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -83,18 +83,18 @@ |
||
| 83 | 83 | { |
| 84 | 84 | $middleware_app_class = reset($middleware_app); |
| 85 | 85 | // is array empty ? |
| 86 | - if($middleware_app_class === false) { |
|
| 86 | + if ($middleware_app_class === false) { |
|
| 87 | 87 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 88 | 88 | } |
| 89 | 89 | // are the class and arguments in the wrong order ? |
| 90 | - if(is_array($middleware_app_class)) { |
|
| 90 | + if (is_array($middleware_app_class)) { |
|
| 91 | 91 | if ($recurse === true) { |
| 92 | 92 | return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
| 93 | 93 | } |
| 94 | 94 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 95 | 95 | } |
| 96 | 96 | // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
| 97 | - if(! class_exists($middleware_app_class)) { |
|
| 97 | + if ( ! class_exists($middleware_app_class)) { |
|
| 98 | 98 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 99 | 99 | } |
| 100 | 100 | return $middleware_app; |
@@ -19,30 +19,30 @@ |
||
| 19 | 19 | class InvalidRequestStackMiddlewareException extends InvalidDataTypeException |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param mixed $middleware_app_class |
|
| 24 | - * @param string $message |
|
| 25 | - * @param int $code |
|
| 26 | - * @param Exception $previous |
|
| 27 | - */ |
|
| 28 | - public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
|
| 29 | - { |
|
| 30 | - if (empty($message)) { |
|
| 31 | - $message = sprintf( |
|
| 32 | - esc_html__( |
|
| 33 | - 'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.', |
|
| 34 | - 'event_espresso' |
|
| 35 | - ), |
|
| 36 | - $middleware_app_class |
|
| 37 | - ); |
|
| 38 | - } |
|
| 39 | - parent::__construct( |
|
| 40 | - '$middleware_app_class', |
|
| 41 | - $middleware_app_class, |
|
| 42 | - 'EventEspresso\core\services\request\middleware\Middleware', |
|
| 43 | - $message, |
|
| 44 | - $code, |
|
| 45 | - $previous |
|
| 46 | - ); |
|
| 47 | - } |
|
| 22 | + /** |
|
| 23 | + * @param mixed $middleware_app_class |
|
| 24 | + * @param string $message |
|
| 25 | + * @param int $code |
|
| 26 | + * @param Exception $previous |
|
| 27 | + */ |
|
| 28 | + public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
|
| 29 | + { |
|
| 30 | + if (empty($message)) { |
|
| 31 | + $message = sprintf( |
|
| 32 | + esc_html__( |
|
| 33 | + 'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.', |
|
| 34 | + 'event_espresso' |
|
| 35 | + ), |
|
| 36 | + $middleware_app_class |
|
| 37 | + ); |
|
| 38 | + } |
|
| 39 | + parent::__construct( |
|
| 40 | + '$middleware_app_class', |
|
| 41 | + $middleware_app_class, |
|
| 42 | + 'EventEspresso\core\services\request\middleware\Middleware', |
|
| 43 | + $message, |
|
| 44 | + $code, |
|
| 45 | + $previous |
|
| 46 | + ); |
|
| 47 | + } |
|
| 48 | 48 | } |