@@ -13,24 +13,24 @@ |
||
| 13 | 13 | class InsufficientPermissionsException extends \RuntimeException |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @access public |
|
| 18 | - * @param string $action |
|
| 19 | - * @param string $message |
|
| 20 | - * @param int $code |
|
| 21 | - * @param \Exception $previous |
|
| 22 | - */ |
|
| 23 | - public function __construct($action, $message = '', $code = 0, \Exception $previous = null) |
|
| 24 | - { |
|
| 25 | - if (empty($message)) { |
|
| 26 | - $message = sprintf( |
|
| 27 | - __( |
|
| 28 | - 'We\'re sorry, but you do not have the required permissions to perform the following action: %1$s', |
|
| 29 | - 'event_espresso' |
|
| 30 | - ), |
|
| 31 | - ucwords(str_replace('_', ' ', $action)) |
|
| 32 | - ); |
|
| 33 | - } |
|
| 34 | - parent::__construct($message, $code, $previous); |
|
| 35 | - } |
|
| 16 | + /** |
|
| 17 | + * @access public |
|
| 18 | + * @param string $action |
|
| 19 | + * @param string $message |
|
| 20 | + * @param int $code |
|
| 21 | + * @param \Exception $previous |
|
| 22 | + */ |
|
| 23 | + public function __construct($action, $message = '', $code = 0, \Exception $previous = null) |
|
| 24 | + { |
|
| 25 | + if (empty($message)) { |
|
| 26 | + $message = sprintf( |
|
| 27 | + __( |
|
| 28 | + 'We\'re sorry, but you do not have the required permissions to perform the following action: %1$s', |
|
| 29 | + 'event_espresso' |
|
| 30 | + ), |
|
| 31 | + ucwords(str_replace('_', ' ', $action)) |
|
| 32 | + ); |
|
| 33 | + } |
|
| 34 | + parent::__construct($message, $code, $previous); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -12,27 +12,27 @@ |
||
| 12 | 12 | class UnexpectedEntityException extends \UnexpectedValueException |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * UnexpectedEntityException constructor |
|
| 17 | - * |
|
| 18 | - * @param mixed $entity the actual object or variable that was received |
|
| 19 | - * @param string $expected_class classname of the entity we wanted |
|
| 20 | - * @param string $message |
|
| 21 | - * @param int $code |
|
| 22 | - * @param \Exception $previous |
|
| 23 | - */ |
|
| 24 | - public function __construct($entity, $expected_class, $message = '', $code = 0, \Exception $previous = null) |
|
| 25 | - { |
|
| 26 | - if (empty($message)) { |
|
| 27 | - $message = sprintf( |
|
| 28 | - __( |
|
| 29 | - 'The retrieved entity is an instance of "%1$s", but an instance of "%2$s" was expected.', |
|
| 30 | - 'event_espresso' |
|
| 31 | - ), |
|
| 32 | - is_object($entity) ? get_class($entity) : gettype($entity), |
|
| 33 | - $expected_class |
|
| 34 | - ); |
|
| 35 | - } |
|
| 36 | - parent::__construct($message, $code, $previous); |
|
| 37 | - } |
|
| 15 | + /** |
|
| 16 | + * UnexpectedEntityException constructor |
|
| 17 | + * |
|
| 18 | + * @param mixed $entity the actual object or variable that was received |
|
| 19 | + * @param string $expected_class classname of the entity we wanted |
|
| 20 | + * @param string $message |
|
| 21 | + * @param int $code |
|
| 22 | + * @param \Exception $previous |
|
| 23 | + */ |
|
| 24 | + public function __construct($entity, $expected_class, $message = '', $code = 0, \Exception $previous = null) |
|
| 25 | + { |
|
| 26 | + if (empty($message)) { |
|
| 27 | + $message = sprintf( |
|
| 28 | + __( |
|
| 29 | + 'The retrieved entity is an instance of "%1$s", but an instance of "%2$s" was expected.', |
|
| 30 | + 'event_espresso' |
|
| 31 | + ), |
|
| 32 | + is_object($entity) ? get_class($entity) : gettype($entity), |
|
| 33 | + $expected_class |
|
| 34 | + ); |
|
| 35 | + } |
|
| 36 | + parent::__construct($message, $code, $previous); |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -13,25 +13,25 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * EntityConstructionException constructor |
|
| 18 | - * |
|
| 19 | - * @param string $entity_class class name of the entity being constructed |
|
| 20 | - * @param string $message |
|
| 21 | - * @param int $code |
|
| 22 | - * @param \Exception $previous |
|
| 23 | - */ |
|
| 24 | - public function __construct($entity_class, $message = '', $code = 0, \Exception $previous = null) |
|
| 25 | - { |
|
| 26 | - if (empty($message)) { |
|
| 27 | - $message = sprintf( |
|
| 28 | - __( |
|
| 29 | - 'The "%1$s" entity could not be instantiated for an unknown reason', |
|
| 30 | - 'event_espresso' |
|
| 31 | - ), |
|
| 32 | - $entity_class |
|
| 33 | - ); |
|
| 34 | - } |
|
| 35 | - parent::__construct($message, $code, $previous); |
|
| 36 | - } |
|
| 16 | + /** |
|
| 17 | + * EntityConstructionException constructor |
|
| 18 | + * |
|
| 19 | + * @param string $entity_class class name of the entity being constructed |
|
| 20 | + * @param string $message |
|
| 21 | + * @param int $code |
|
| 22 | + * @param \Exception $previous |
|
| 23 | + */ |
|
| 24 | + public function __construct($entity_class, $message = '', $code = 0, \Exception $previous = null) |
|
| 25 | + { |
|
| 26 | + if (empty($message)) { |
|
| 27 | + $message = sprintf( |
|
| 28 | + __( |
|
| 29 | + 'The "%1$s" entity could not be instantiated for an unknown reason', |
|
| 30 | + 'event_espresso' |
|
| 31 | + ), |
|
| 32 | + $entity_class |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | + parent::__construct($message, $code, $previous); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -15,26 +15,26 @@ |
||
| 15 | 15 | abstract class FormatterBase implements FormatterInterface |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
| 20 | - * |
|
| 21 | - * @param array $input |
|
| 22 | - * @return array |
|
| 23 | - * @throws InvalidDataTypeException if $input is not an array |
|
| 24 | - */ |
|
| 25 | - public function formatArray($input) |
|
| 26 | - { |
|
| 27 | - if (! is_array($input)) { |
|
| 28 | - throw new InvalidDataTypeException('input', $input, 'array'); |
|
| 29 | - } |
|
| 30 | - // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
| 31 | - $formatter = $this; |
|
| 32 | - array_walk_recursive( |
|
| 33 | - $input, |
|
| 34 | - function (&$value, $key) use ($formatter) { |
|
| 35 | - $value = $formatter->format($value); |
|
| 36 | - } |
|
| 37 | - ); |
|
| 38 | - return $input; |
|
| 39 | - } |
|
| 18 | + /** |
|
| 19 | + * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
| 20 | + * |
|
| 21 | + * @param array $input |
|
| 22 | + * @return array |
|
| 23 | + * @throws InvalidDataTypeException if $input is not an array |
|
| 24 | + */ |
|
| 25 | + public function formatArray($input) |
|
| 26 | + { |
|
| 27 | + if (! is_array($input)) { |
|
| 28 | + throw new InvalidDataTypeException('input', $input, 'array'); |
|
| 29 | + } |
|
| 30 | + // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
| 31 | + $formatter = $this; |
|
| 32 | + array_walk_recursive( |
|
| 33 | + $input, |
|
| 34 | + function (&$value, $key) use ($formatter) { |
|
| 35 | + $value = $formatter->format($value); |
|
| 36 | + } |
|
| 37 | + ); |
|
| 38 | + return $input; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -24,14 +24,14 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function formatArray($input) |
| 26 | 26 | { |
| 27 | - if (! is_array($input)) { |
|
| 27 | + if ( ! is_array($input)) { |
|
| 28 | 28 | throw new InvalidDataTypeException('input', $input, 'array'); |
| 29 | 29 | } |
| 30 | 30 | // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
| 31 | 31 | $formatter = $this; |
| 32 | 32 | array_walk_recursive( |
| 33 | 33 | $input, |
| 34 | - function (&$value, $key) use ($formatter) { |
|
| 34 | + function(&$value, $key) use ($formatter) { |
|
| 35 | 35 | $value = $formatter->format($value); |
| 36 | 36 | } |
| 37 | 37 | ); |
@@ -15,26 +15,26 @@ |
||
| 15 | 15 | class LeaveAlone extends FormatterBase |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Removes the emojis from the inputted string |
|
| 20 | - * |
|
| 21 | - * @param string|int|float $input anything easily cast into a string |
|
| 22 | - * @return string |
|
| 23 | - * @throws InvalidDataTypeException if $input is not a string |
|
| 24 | - */ |
|
| 25 | - public function format($input) |
|
| 26 | - { |
|
| 27 | - return $input; |
|
| 28 | - } |
|
| 18 | + /** |
|
| 19 | + * Removes the emojis from the inputted string |
|
| 20 | + * |
|
| 21 | + * @param string|int|float $input anything easily cast into a string |
|
| 22 | + * @return string |
|
| 23 | + * @throws InvalidDataTypeException if $input is not a string |
|
| 24 | + */ |
|
| 25 | + public function format($input) |
|
| 26 | + { |
|
| 27 | + return $input; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Just returns the inputted $input array |
|
| 32 | - * |
|
| 33 | - * @param array $input |
|
| 34 | - * @return array |
|
| 35 | - */ |
|
| 36 | - public function formatArray($input) |
|
| 37 | - { |
|
| 38 | - return $input; |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * Just returns the inputted $input array |
|
| 32 | + * |
|
| 33 | + * @param array $input |
|
| 34 | + * @return array |
|
| 35 | + */ |
|
| 36 | + public function formatArray($input) |
|
| 37 | + { |
|
| 38 | + return $input; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -23,87 +23,87 @@ |
||
| 23 | 23 | class RequestStackCoreApp implements RequestDecoratorInterface, RequestStackCoreAppInterface |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var RequestInterface $request |
|
| 28 | - */ |
|
| 29 | - protected $request; |
|
| 26 | + /** |
|
| 27 | + * @var RequestInterface $request |
|
| 28 | + */ |
|
| 29 | + protected $request; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var ResponseInterface $response |
|
| 33 | - */ |
|
| 34 | - protected $response; |
|
| 31 | + /** |
|
| 32 | + * @var ResponseInterface $response |
|
| 33 | + */ |
|
| 34 | + protected $response; |
|
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * handle |
|
| 39 | - * sets hooks for running rest of system |
|
| 40 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 41 | - * starting EE Addons from any other point may lead to problems |
|
| 42 | - * |
|
| 43 | - * @param RequestInterface $request |
|
| 44 | - * @param ResponseInterface $response |
|
| 45 | - * @return ResponseInterface |
|
| 46 | - * @throws InvalidClassException |
|
| 47 | - * @throws EE_Error |
|
| 48 | - * @throws InvalidDataTypeException |
|
| 49 | - * @throws InvalidInterfaceException |
|
| 50 | - * @throws InvalidArgumentException |
|
| 51 | - */ |
|
| 52 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 53 | - { |
|
| 54 | - $this->request = $request; |
|
| 55 | - $this->response = $response; |
|
| 56 | - espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
| 57 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
| 58 | - // workarounds for PHP < 5.3 |
|
| 59 | - espresso_load_required('EEH_Class_Tools', EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
| 60 | - do_action( |
|
| 61 | - 'EE_EventEspresso_core_services_request_RequestStackCoreApp__handle_request__initialize_core_loading' |
|
| 62 | - ); |
|
| 63 | - // legacy action for backwards compatibility |
|
| 64 | - do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
| 65 | - $this->setupFramework(); |
|
| 66 | - $loader = LoaderFactory::getLoader(); |
|
| 67 | - $loader->getShared( |
|
| 68 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 69 | - ); |
|
| 70 | - // WP cron jobs |
|
| 71 | - $loader->getShared('EE_Cron_Tasks'); |
|
| 72 | - $loader->getShared('EE_System'); |
|
| 73 | - return $this->response; |
|
| 74 | - } |
|
| 37 | + /** |
|
| 38 | + * handle |
|
| 39 | + * sets hooks for running rest of system |
|
| 40 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
| 41 | + * starting EE Addons from any other point may lead to problems |
|
| 42 | + * |
|
| 43 | + * @param RequestInterface $request |
|
| 44 | + * @param ResponseInterface $response |
|
| 45 | + * @return ResponseInterface |
|
| 46 | + * @throws InvalidClassException |
|
| 47 | + * @throws EE_Error |
|
| 48 | + * @throws InvalidDataTypeException |
|
| 49 | + * @throws InvalidInterfaceException |
|
| 50 | + * @throws InvalidArgumentException |
|
| 51 | + */ |
|
| 52 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 53 | + { |
|
| 54 | + $this->request = $request; |
|
| 55 | + $this->response = $response; |
|
| 56 | + espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
| 57 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
| 58 | + // workarounds for PHP < 5.3 |
|
| 59 | + espresso_load_required('EEH_Class_Tools', EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
| 60 | + do_action( |
|
| 61 | + 'EE_EventEspresso_core_services_request_RequestStackCoreApp__handle_request__initialize_core_loading' |
|
| 62 | + ); |
|
| 63 | + // legacy action for backwards compatibility |
|
| 64 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
| 65 | + $this->setupFramework(); |
|
| 66 | + $loader = LoaderFactory::getLoader(); |
|
| 67 | + $loader->getShared( |
|
| 68 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 69 | + ); |
|
| 70 | + // WP cron jobs |
|
| 71 | + $loader->getShared('EE_Cron_Tasks'); |
|
| 72 | + $loader->getShared('EE_System'); |
|
| 73 | + return $this->response; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * set framework for the rest of EE to hook into when loading |
|
| 79 | - * |
|
| 80 | - * @throws EE_Error |
|
| 81 | - */ |
|
| 82 | - private function setupFramework() |
|
| 83 | - { |
|
| 84 | - espresso_load_required( |
|
| 85 | - 'EE_Bootstrap', |
|
| 86 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
| 87 | - ); |
|
| 88 | - add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1); |
|
| 89 | - add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3); |
|
| 90 | - add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5); |
|
| 91 | - add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7); |
|
| 92 | - add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9); |
|
| 93 | - } |
|
| 77 | + /** |
|
| 78 | + * set framework for the rest of EE to hook into when loading |
|
| 79 | + * |
|
| 80 | + * @throws EE_Error |
|
| 81 | + */ |
|
| 82 | + private function setupFramework() |
|
| 83 | + { |
|
| 84 | + espresso_load_required( |
|
| 85 | + 'EE_Bootstrap', |
|
| 86 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
| 87 | + ); |
|
| 88 | + add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1); |
|
| 89 | + add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3); |
|
| 90 | + add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5); |
|
| 91 | + add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7); |
|
| 92 | + add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * called after the request stack has been fully processed |
|
| 98 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
| 99 | - * |
|
| 100 | - * @param RequestInterface $request |
|
| 101 | - * @param ResponseInterface $response |
|
| 102 | - */ |
|
| 103 | - public function handleResponse(RequestInterface $request, ResponseInterface $response) |
|
| 104 | - { |
|
| 105 | - if ($response->pluginDeactivated()) { |
|
| 106 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
| 107 | - } |
|
| 108 | - } |
|
| 96 | + /** |
|
| 97 | + * called after the request stack has been fully processed |
|
| 98 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
| 99 | + * |
|
| 100 | + * @param RequestInterface $request |
|
| 101 | + * @param ResponseInterface $response |
|
| 102 | + */ |
|
| 103 | + public function handleResponse(RequestInterface $request, ResponseInterface $response) |
|
| 104 | + { |
|
| 105 | + if ($response->pluginDeactivated()) { |
|
| 106 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | 109 | } |
@@ -53,10 +53,10 @@ discard block |
||
| 53 | 53 | { |
| 54 | 54 | $this->request = $request; |
| 55 | 55 | $this->response = $response; |
| 56 | - espresso_load_required('EE_Base', EE_CORE . 'EE_Base.core.php'); |
|
| 57 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
| 56 | + espresso_load_required('EE_Base', EE_CORE.'EE_Base.core.php'); |
|
| 57 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
| 58 | 58 | // workarounds for PHP < 5.3 |
| 59 | - espresso_load_required('EEH_Class_Tools', EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
| 59 | + espresso_load_required('EEH_Class_Tools', EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
| 60 | 60 | do_action( |
| 61 | 61 | 'EE_EventEspresso_core_services_request_RequestStackCoreApp__handle_request__initialize_core_loading' |
| 62 | 62 | ); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | espresso_load_required( |
| 85 | 85 | 'EE_Bootstrap', |
| 86 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
| 86 | + EE_CORE.'EE_Bootstrap.core.php' |
|
| 87 | 87 | ); |
| 88 | 88 | add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1); |
| 89 | 89 | add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3); |
@@ -15,33 +15,33 @@ |
||
| 15 | 15 | class InvalidRequestStackMiddlewareException extends InvalidDataTypeException |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @param mixed $middleware_app_class |
|
| 20 | - * @param string $message |
|
| 21 | - * @param int $code |
|
| 22 | - * @param Exception $previous |
|
| 23 | - */ |
|
| 24 | - public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
|
| 25 | - { |
|
| 26 | - if (is_array($middleware_app_class)) { |
|
| 27 | - $middleware_app_class = reset($middleware_app_class); |
|
| 28 | - } |
|
| 29 | - if (empty($message)) { |
|
| 30 | - $message = sprintf( |
|
| 31 | - esc_html__( |
|
| 32 | - 'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.', |
|
| 33 | - 'event_espresso' |
|
| 34 | - ), |
|
| 35 | - $middleware_app_class |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - parent::__construct( |
|
| 39 | - '$middleware_app_class', |
|
| 40 | - $middleware_app_class, |
|
| 41 | - 'EventEspresso\core\services\request\middleware\Middleware', |
|
| 42 | - $message, |
|
| 43 | - $code, |
|
| 44 | - $previous |
|
| 45 | - ); |
|
| 46 | - } |
|
| 18 | + /** |
|
| 19 | + * @param mixed $middleware_app_class |
|
| 20 | + * @param string $message |
|
| 21 | + * @param int $code |
|
| 22 | + * @param Exception $previous |
|
| 23 | + */ |
|
| 24 | + public function __construct($middleware_app_class, $message = '', $code = 0, Exception $previous = null) |
|
| 25 | + { |
|
| 26 | + if (is_array($middleware_app_class)) { |
|
| 27 | + $middleware_app_class = reset($middleware_app_class); |
|
| 28 | + } |
|
| 29 | + if (empty($message)) { |
|
| 30 | + $message = sprintf( |
|
| 31 | + esc_html__( |
|
| 32 | + 'The supplied Request Stack Middleware class "%1$s" is invalid or could no be found.', |
|
| 33 | + 'event_espresso' |
|
| 34 | + ), |
|
| 35 | + $middleware_app_class |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + parent::__construct( |
|
| 39 | + '$middleware_app_class', |
|
| 40 | + $middleware_app_class, |
|
| 41 | + 'EventEspresso\core\services\request\middleware\Middleware', |
|
| 42 | + $message, |
|
| 43 | + $code, |
|
| 44 | + $previous |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -20,97 +20,97 @@ |
||
| 20 | 20 | class RequestStackBuilder extends SplDoublyLinkedList |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @type LoaderInterface $loader |
|
| 25 | - */ |
|
| 26 | - private $loader; |
|
| 23 | + /** |
|
| 24 | + * @type LoaderInterface $loader |
|
| 25 | + */ |
|
| 26 | + private $loader; |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * RequestStackBuilder constructor. |
|
| 31 | - * |
|
| 32 | - * @param LoaderInterface $loader |
|
| 33 | - */ |
|
| 34 | - public function __construct(LoaderInterface $loader) |
|
| 35 | - { |
|
| 36 | - $this->loader = $loader; |
|
| 37 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 38 | - } |
|
| 29 | + /** |
|
| 30 | + * RequestStackBuilder constructor. |
|
| 31 | + * |
|
| 32 | + * @param LoaderInterface $loader |
|
| 33 | + */ |
|
| 34 | + public function __construct(LoaderInterface $loader) |
|
| 35 | + { |
|
| 36 | + $this->loader = $loader; |
|
| 37 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * builds decorated middleware stack |
|
| 43 | - * by continuously injecting previous middleware app into the next |
|
| 44 | - * |
|
| 45 | - * @param RequestStackCoreAppInterface $application |
|
| 46 | - * @return RequestStack |
|
| 47 | - * @throws Exception |
|
| 48 | - */ |
|
| 49 | - public function resolve(RequestStackCoreAppInterface $application) |
|
| 50 | - { |
|
| 51 | - $core_app = $application; |
|
| 52 | - // NOW... because the RequestStack is following the decorator pattern, |
|
| 53 | - // the first stack app we add will end up at the center of the stack, |
|
| 54 | - // and will end up being the last item to actually run, but we don't want that! |
|
| 55 | - // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 56 | - // BUT... we want the final stack to be in the same order as the first. |
|
| 57 | - // So we need to reverse the iterator mode when transferring items, |
|
| 58 | - // because if we don't, the second stack will end up in the incorrect order. |
|
| 59 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 60 | - for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 61 | - try { |
|
| 62 | - $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 63 | - $middleware_app_class = array_shift($middleware_app); |
|
| 64 | - $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 65 | - $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 66 | - $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 67 | - } catch (InvalidRequestStackMiddlewareException $exception) { |
|
| 68 | - if (WP_DEBUG) { |
|
| 69 | - new ExceptionStackTraceDisplay($exception); |
|
| 70 | - continue; |
|
| 71 | - } |
|
| 72 | - error_log($exception->getMessage()); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - return new RequestStack($application, $core_app); |
|
| 76 | - } |
|
| 41 | + /** |
|
| 42 | + * builds decorated middleware stack |
|
| 43 | + * by continuously injecting previous middleware app into the next |
|
| 44 | + * |
|
| 45 | + * @param RequestStackCoreAppInterface $application |
|
| 46 | + * @return RequestStack |
|
| 47 | + * @throws Exception |
|
| 48 | + */ |
|
| 49 | + public function resolve(RequestStackCoreAppInterface $application) |
|
| 50 | + { |
|
| 51 | + $core_app = $application; |
|
| 52 | + // NOW... because the RequestStack is following the decorator pattern, |
|
| 53 | + // the first stack app we add will end up at the center of the stack, |
|
| 54 | + // and will end up being the last item to actually run, but we don't want that! |
|
| 55 | + // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 56 | + // BUT... we want the final stack to be in the same order as the first. |
|
| 57 | + // So we need to reverse the iterator mode when transferring items, |
|
| 58 | + // because if we don't, the second stack will end up in the incorrect order. |
|
| 59 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 60 | + for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 61 | + try { |
|
| 62 | + $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 63 | + $middleware_app_class = array_shift($middleware_app); |
|
| 64 | + $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 65 | + $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 66 | + $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 67 | + } catch (InvalidRequestStackMiddlewareException $exception) { |
|
| 68 | + if (WP_DEBUG) { |
|
| 69 | + new ExceptionStackTraceDisplay($exception); |
|
| 70 | + continue; |
|
| 71 | + } |
|
| 72 | + error_log($exception->getMessage()); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + return new RequestStack($application, $core_app); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 81 | - * are all ordered correctly so that the middleware can be properly constructed |
|
| 82 | - * |
|
| 83 | - * @param array $middleware_app |
|
| 84 | - * @param bool $recurse |
|
| 85 | - * @return array |
|
| 86 | - * @throws InvalidRequestStackMiddlewareException |
|
| 87 | - */ |
|
| 88 | - protected function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 89 | - { |
|
| 90 | - $middleware_app_class = reset($middleware_app); |
|
| 91 | - // is array empty ? |
|
| 92 | - if ($middleware_app_class === false) { |
|
| 93 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 94 | - } |
|
| 95 | - // are the class and arguments in the wrong order ? |
|
| 96 | - if (is_array($middleware_app_class)) { |
|
| 97 | - if ($recurse === true) { |
|
| 98 | - return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 99 | - } |
|
| 100 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 101 | - } |
|
| 102 | - // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
| 103 | - if (is_int($middleware_app_class)) { |
|
| 104 | - if ($recurse === true) { |
|
| 105 | - $middleware_app = array_reverse($middleware_app); |
|
| 106 | - return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
| 107 | - } |
|
| 108 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 109 | - } |
|
| 110 | - // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 111 | - if (! class_exists($middleware_app_class)) { |
|
| 112 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 113 | - } |
|
| 114 | - return $middleware_app; |
|
| 115 | - } |
|
| 79 | + /** |
|
| 80 | + * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 81 | + * are all ordered correctly so that the middleware can be properly constructed |
|
| 82 | + * |
|
| 83 | + * @param array $middleware_app |
|
| 84 | + * @param bool $recurse |
|
| 85 | + * @return array |
|
| 86 | + * @throws InvalidRequestStackMiddlewareException |
|
| 87 | + */ |
|
| 88 | + protected function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 89 | + { |
|
| 90 | + $middleware_app_class = reset($middleware_app); |
|
| 91 | + // is array empty ? |
|
| 92 | + if ($middleware_app_class === false) { |
|
| 93 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 94 | + } |
|
| 95 | + // are the class and arguments in the wrong order ? |
|
| 96 | + if (is_array($middleware_app_class)) { |
|
| 97 | + if ($recurse === true) { |
|
| 98 | + return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 99 | + } |
|
| 100 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 101 | + } |
|
| 102 | + // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
| 103 | + if (is_int($middleware_app_class)) { |
|
| 104 | + if ($recurse === true) { |
|
| 105 | + $middleware_app = array_reverse($middleware_app); |
|
| 106 | + return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
| 107 | + } |
|
| 108 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 109 | + } |
|
| 110 | + // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 111 | + if (! class_exists($middleware_app_class)) { |
|
| 112 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 113 | + } |
|
| 114 | + return $middleware_app; |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 109 | 109 | } |
| 110 | 110 | // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
| 111 | - if (! class_exists($middleware_app_class)) { |
|
| 111 | + if ( ! class_exists($middleware_app_class)) { |
|
| 112 | 112 | throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
| 113 | 113 | } |
| 114 | 114 | return $middleware_app; |
@@ -17,23 +17,23 @@ |
||
| 17 | 17 | class BotDetector extends Middleware |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * converts a Request to a Response |
|
| 22 | - * |
|
| 23 | - * @param RequestInterface $request |
|
| 24 | - * @param ResponseInterface $response |
|
| 25 | - * @return ResponseInterface |
|
| 26 | - */ |
|
| 27 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 28 | - { |
|
| 29 | - $this->request = $request; |
|
| 30 | - $this->response = $response; |
|
| 31 | - /** @var CrawlerDetect $CrawlerDetect */ |
|
| 32 | - $CrawlerDetect = $this->loader->getShared('EventEspressoVendor\Jaybizzle\CrawlerDetect\CrawlerDetect'); |
|
| 33 | - // Check and record the user agent of the current 'visitor' |
|
| 34 | - $this->request->setIsBot($CrawlerDetect->isCrawler()); |
|
| 35 | - $this->request->setUserAgent($CrawlerDetect->userAgent()); |
|
| 36 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 37 | - return $this->response; |
|
| 38 | - } |
|
| 20 | + /** |
|
| 21 | + * converts a Request to a Response |
|
| 22 | + * |
|
| 23 | + * @param RequestInterface $request |
|
| 24 | + * @param ResponseInterface $response |
|
| 25 | + * @return ResponseInterface |
|
| 26 | + */ |
|
| 27 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
| 28 | + { |
|
| 29 | + $this->request = $request; |
|
| 30 | + $this->response = $response; |
|
| 31 | + /** @var CrawlerDetect $CrawlerDetect */ |
|
| 32 | + $CrawlerDetect = $this->loader->getShared('EventEspressoVendor\Jaybizzle\CrawlerDetect\CrawlerDetect'); |
|
| 33 | + // Check and record the user agent of the current 'visitor' |
|
| 34 | + $this->request->setIsBot($CrawlerDetect->isCrawler()); |
|
| 35 | + $this->request->setUserAgent($CrawlerDetect->userAgent()); |
|
| 36 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
| 37 | + return $this->response; |
|
| 38 | + } |
|
| 39 | 39 | } |