@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | $this |
| 61 | 61 | ) |
| 62 | 62 | ); |
| 63 | - if (! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
|
| 63 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
|
| 64 | 64 | $this->addStylesheets(array('site_theme' => '')); |
| 65 | 65 | } |
| 66 | 66 | $this->addScripts( |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | array(), |
| 80 | 80 | $this |
| 81 | 81 | ); |
| 82 | - if (! empty($js_attributes)) { |
|
| 82 | + if ( ! empty($js_attributes)) { |
|
| 83 | 83 | $this->addScriptAttributes($js_attributes); |
| 84 | 84 | } |
| 85 | 85 | $this->addLocalizedVars( |
@@ -19,77 +19,77 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class TicketSelectorIframe extends Iframe |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * TicketSelectorIframe constructor. |
|
| 24 | - * |
|
| 25 | - * @param EEM_Event $event_model |
|
| 26 | - * @param CurrentPage $current_page |
|
| 27 | - * @param RequestInterface $request |
|
| 28 | - * @throws EE_Error |
|
| 29 | - */ |
|
| 30 | - public function __construct(EEM_Event $event_model, CurrentPage $current_page, RequestInterface $request) |
|
| 31 | - { |
|
| 32 | - $current_page->setEspressoPage(true); |
|
| 33 | - $ticket_selector = LoaderFactory::getLoader()->getNew(DisplayTicketSelector::class); |
|
| 34 | - $ticket_selector->setIframe(); |
|
| 35 | - $event = $event_model->get_one_by_ID($request->getRequestParam('event', 0, 'int')); |
|
| 36 | - parent::__construct( |
|
| 37 | - esc_html__('Ticket Selector', 'event_espresso'), |
|
| 38 | - $ticket_selector->display($event) |
|
| 39 | - ); |
|
| 40 | - $this->addStylesheets( |
|
| 41 | - apply_filters( |
|
| 42 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
| 43 | - array( |
|
| 44 | - 'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 45 | - . 'ticket_selector_embed.css?ver=' |
|
| 46 | - . EVENT_ESPRESSO_VERSION, |
|
| 47 | - 'ticket_selector' => TICKET_SELECTOR_ASSETS_URL |
|
| 48 | - . 'ticket_selector.css?ver=' |
|
| 49 | - . EVENT_ESPRESSO_VERSION, |
|
| 50 | - ), |
|
| 51 | - $this |
|
| 52 | - ) |
|
| 53 | - ); |
|
| 54 | - if (! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
|
| 55 | - $this->addStylesheets(array('site_theme' => '')); |
|
| 56 | - } |
|
| 57 | - $this->addScripts( |
|
| 58 | - apply_filters( |
|
| 59 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 60 | - array( |
|
| 61 | - 'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 62 | - . 'ticket_selector_iframe_embed.js?ver=' |
|
| 63 | - . EVENT_ESPRESSO_VERSION, |
|
| 64 | - ), |
|
| 65 | - $this |
|
| 66 | - ) |
|
| 67 | - ); |
|
| 68 | - $js_attributes = apply_filters( |
|
| 69 | - 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 70 | - array(), |
|
| 71 | - $this |
|
| 72 | - ); |
|
| 73 | - if (! empty($js_attributes)) { |
|
| 74 | - $this->addScriptAttributes($js_attributes); |
|
| 75 | - } |
|
| 76 | - $this->addLocalizedVars( |
|
| 77 | - apply_filters( |
|
| 78 | - 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars', |
|
| 79 | - array( |
|
| 80 | - 'ticket_selector_iframe' => true, |
|
| 81 | - 'EEDTicketSelectorMsg' => wp_strip_all_tags( |
|
| 82 | - __( |
|
| 83 | - 'Please choose at least one ticket before continuing.', |
|
| 84 | - 'event_espresso' |
|
| 85 | - ) |
|
| 86 | - ), |
|
| 87 | - ) |
|
| 88 | - ) |
|
| 89 | - ); |
|
| 90 | - do_action( |
|
| 91 | - 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 92 | - $this |
|
| 93 | - ); |
|
| 94 | - } |
|
| 22 | + /** |
|
| 23 | + * TicketSelectorIframe constructor. |
|
| 24 | + * |
|
| 25 | + * @param EEM_Event $event_model |
|
| 26 | + * @param CurrentPage $current_page |
|
| 27 | + * @param RequestInterface $request |
|
| 28 | + * @throws EE_Error |
|
| 29 | + */ |
|
| 30 | + public function __construct(EEM_Event $event_model, CurrentPage $current_page, RequestInterface $request) |
|
| 31 | + { |
|
| 32 | + $current_page->setEspressoPage(true); |
|
| 33 | + $ticket_selector = LoaderFactory::getLoader()->getNew(DisplayTicketSelector::class); |
|
| 34 | + $ticket_selector->setIframe(); |
|
| 35 | + $event = $event_model->get_one_by_ID($request->getRequestParam('event', 0, 'int')); |
|
| 36 | + parent::__construct( |
|
| 37 | + esc_html__('Ticket Selector', 'event_espresso'), |
|
| 38 | + $ticket_selector->display($event) |
|
| 39 | + ); |
|
| 40 | + $this->addStylesheets( |
|
| 41 | + apply_filters( |
|
| 42 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
| 43 | + array( |
|
| 44 | + 'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 45 | + . 'ticket_selector_embed.css?ver=' |
|
| 46 | + . EVENT_ESPRESSO_VERSION, |
|
| 47 | + 'ticket_selector' => TICKET_SELECTOR_ASSETS_URL |
|
| 48 | + . 'ticket_selector.css?ver=' |
|
| 49 | + . EVENT_ESPRESSO_VERSION, |
|
| 50 | + ), |
|
| 51 | + $this |
|
| 52 | + ) |
|
| 53 | + ); |
|
| 54 | + if (! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
|
| 55 | + $this->addStylesheets(array('site_theme' => '')); |
|
| 56 | + } |
|
| 57 | + $this->addScripts( |
|
| 58 | + apply_filters( |
|
| 59 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 60 | + array( |
|
| 61 | + 'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 62 | + . 'ticket_selector_iframe_embed.js?ver=' |
|
| 63 | + . EVENT_ESPRESSO_VERSION, |
|
| 64 | + ), |
|
| 65 | + $this |
|
| 66 | + ) |
|
| 67 | + ); |
|
| 68 | + $js_attributes = apply_filters( |
|
| 69 | + 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 70 | + array(), |
|
| 71 | + $this |
|
| 72 | + ); |
|
| 73 | + if (! empty($js_attributes)) { |
|
| 74 | + $this->addScriptAttributes($js_attributes); |
|
| 75 | + } |
|
| 76 | + $this->addLocalizedVars( |
|
| 77 | + apply_filters( |
|
| 78 | + 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars', |
|
| 79 | + array( |
|
| 80 | + 'ticket_selector_iframe' => true, |
|
| 81 | + 'EEDTicketSelectorMsg' => wp_strip_all_tags( |
|
| 82 | + __( |
|
| 83 | + 'Please choose at least one ticket before continuing.', |
|
| 84 | + 'event_espresso' |
|
| 85 | + ) |
|
| 86 | + ), |
|
| 87 | + ) |
|
| 88 | + ) |
|
| 89 | + ); |
|
| 90 | + do_action( |
|
| 91 | + 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 92 | + $this |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -33,87 +33,87 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class SocketPost implements RequestMethod |
| 35 | 35 | { |
| 36 | - /** |
|
| 37 | - * reCAPTCHA service host. |
|
| 38 | - * |
|
| 39 | - * @const string |
|
| 40 | - */ |
|
| 41 | - const RECAPTCHA_HOST = 'www.google.com'; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @const string reCAPTCHA service path |
|
| 45 | - */ |
|
| 46 | - const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @const string Bad request error |
|
| 50 | - */ |
|
| 51 | - const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @const string Bad response error |
|
| 55 | - */ |
|
| 56 | - const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Socket to the reCAPTCHA service |
|
| 60 | - * |
|
| 61 | - * @var Socket |
|
| 62 | - */ |
|
| 63 | - private $socket; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Constructor |
|
| 67 | - * |
|
| 68 | - * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
| 69 | - */ |
|
| 70 | - public function __construct(Socket $socket = null) |
|
| 71 | - { |
|
| 72 | - if (! is_null($socket)) { |
|
| 73 | - $this->socket = $socket; |
|
| 74 | - } else { |
|
| 75 | - $this->socket = new Socket(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Submit the POST request with the specified parameters. |
|
| 81 | - * |
|
| 82 | - * @param RequestParameters $params Request parameters |
|
| 83 | - * @return string Body of the reCAPTCHA response |
|
| 84 | - */ |
|
| 85 | - public function submit(RequestParameters $params) |
|
| 86 | - { |
|
| 87 | - $errno = 0; |
|
| 88 | - $errstr = ''; |
|
| 89 | - |
|
| 90 | - if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
| 91 | - $content = $params->toQueryString(); |
|
| 92 | - |
|
| 93 | - $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
| 94 | - $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
| 95 | - $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
| 96 | - $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
| 97 | - $request .= "Connection: close\r\n\r\n"; |
|
| 98 | - $request .= $content . "\r\n\r\n"; |
|
| 99 | - |
|
| 100 | - $this->socket->fwrite($request); |
|
| 101 | - $response = ''; |
|
| 102 | - |
|
| 103 | - while (! $this->socket->feof()) { |
|
| 104 | - $response .= $this->socket->fgets(4096); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $this->socket->fclose(); |
|
| 108 | - |
|
| 109 | - if (0 === strpos($response, 'HTTP/1.1 200 OK')) { |
|
| 110 | - $parts = preg_split("#\n\s*\n#Uis", $response); |
|
| 111 | - return $parts[1]; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return self::BAD_RESPONSE; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return self::BAD_REQUEST; |
|
| 118 | - } |
|
| 36 | + /** |
|
| 37 | + * reCAPTCHA service host. |
|
| 38 | + * |
|
| 39 | + * @const string |
|
| 40 | + */ |
|
| 41 | + const RECAPTCHA_HOST = 'www.google.com'; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @const string reCAPTCHA service path |
|
| 45 | + */ |
|
| 46 | + const SITE_VERIFY_PATH = '/recaptcha/api/siteverify'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @const string Bad request error |
|
| 50 | + */ |
|
| 51 | + const BAD_REQUEST = '{"success": false, "error-codes": ["invalid-request"]}'; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @const string Bad response error |
|
| 55 | + */ |
|
| 56 | + const BAD_RESPONSE = '{"success": false, "error-codes": ["invalid-response"]}'; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Socket to the reCAPTCHA service |
|
| 60 | + * |
|
| 61 | + * @var Socket |
|
| 62 | + */ |
|
| 63 | + private $socket; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Constructor |
|
| 67 | + * |
|
| 68 | + * @param \ReCaptcha\RequestMethod\Socket $socket optional socket, injectable for testing |
|
| 69 | + */ |
|
| 70 | + public function __construct(Socket $socket = null) |
|
| 71 | + { |
|
| 72 | + if (! is_null($socket)) { |
|
| 73 | + $this->socket = $socket; |
|
| 74 | + } else { |
|
| 75 | + $this->socket = new Socket(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Submit the POST request with the specified parameters. |
|
| 81 | + * |
|
| 82 | + * @param RequestParameters $params Request parameters |
|
| 83 | + * @return string Body of the reCAPTCHA response |
|
| 84 | + */ |
|
| 85 | + public function submit(RequestParameters $params) |
|
| 86 | + { |
|
| 87 | + $errno = 0; |
|
| 88 | + $errstr = ''; |
|
| 89 | + |
|
| 90 | + if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
| 91 | + $content = $params->toQueryString(); |
|
| 92 | + |
|
| 93 | + $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
| 94 | + $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
| 95 | + $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
| 96 | + $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
| 97 | + $request .= "Connection: close\r\n\r\n"; |
|
| 98 | + $request .= $content . "\r\n\r\n"; |
|
| 99 | + |
|
| 100 | + $this->socket->fwrite($request); |
|
| 101 | + $response = ''; |
|
| 102 | + |
|
| 103 | + while (! $this->socket->feof()) { |
|
| 104 | + $response .= $this->socket->fgets(4096); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $this->socket->fclose(); |
|
| 108 | + |
|
| 109 | + if (0 === strpos($response, 'HTTP/1.1 200 OK')) { |
|
| 110 | + $parts = preg_split("#\n\s*\n#Uis", $response); |
|
| 111 | + return $parts[1]; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return self::BAD_RESPONSE; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return self::BAD_REQUEST; |
|
| 118 | + } |
|
| 119 | 119 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function __construct(Socket $socket = null) |
| 71 | 71 | { |
| 72 | - if (! is_null($socket)) { |
|
| 72 | + if ( ! is_null($socket)) { |
|
| 73 | 73 | $this->socket = $socket; |
| 74 | 74 | } else { |
| 75 | 75 | $this->socket = new Socket(); |
@@ -87,20 +87,20 @@ discard block |
||
| 87 | 87 | $errno = 0; |
| 88 | 88 | $errstr = ''; |
| 89 | 89 | |
| 90 | - if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
| 90 | + if ($this->socket->fsockopen('ssl://'.self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { |
|
| 91 | 91 | $content = $params->toQueryString(); |
| 92 | 92 | |
| 93 | - $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; |
|
| 94 | - $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; |
|
| 93 | + $request = "POST ".self::SITE_VERIFY_PATH." HTTP/1.1\r\n"; |
|
| 94 | + $request .= "Host: ".self::RECAPTCHA_HOST."\r\n"; |
|
| 95 | 95 | $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
| 96 | - $request .= "Content-length: " . strlen($content) . "\r\n"; |
|
| 96 | + $request .= "Content-length: ".strlen($content)."\r\n"; |
|
| 97 | 97 | $request .= "Connection: close\r\n\r\n"; |
| 98 | - $request .= $content . "\r\n\r\n"; |
|
| 98 | + $request .= $content."\r\n\r\n"; |
|
| 99 | 99 | |
| 100 | 100 | $this->socket->fwrite($request); |
| 101 | 101 | $response = ''; |
| 102 | 102 | |
| 103 | - while (! $this->socket->feof()) { |
|
| 103 | + while ( ! $this->socket->feof()) { |
|
| 104 | 104 | $response .= $this->socket->fgets(4096); |
| 105 | 105 | } |
| 106 | 106 | |
@@ -29,79 +29,79 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Socket |
| 31 | 31 | { |
| 32 | - private $handle = null; |
|
| 32 | + private $handle = null; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * fsockopen |
|
| 36 | - * |
|
| 37 | - * @see http://php.net/fsockopen |
|
| 38 | - * @param string $hostname |
|
| 39 | - * @param int $port |
|
| 40 | - * @param int $errno |
|
| 41 | - * @param string $errstr |
|
| 42 | - * @param float $timeout |
|
| 43 | - * @return resource |
|
| 44 | - */ |
|
| 45 | - public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
| 46 | - { |
|
| 47 | - $this->handle = fsockopen( |
|
| 48 | - $hostname, |
|
| 49 | - $port, |
|
| 50 | - $errno, |
|
| 51 | - $errstr, |
|
| 52 | - (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout) |
|
| 53 | - ); |
|
| 34 | + /** |
|
| 35 | + * fsockopen |
|
| 36 | + * |
|
| 37 | + * @see http://php.net/fsockopen |
|
| 38 | + * @param string $hostname |
|
| 39 | + * @param int $port |
|
| 40 | + * @param int $errno |
|
| 41 | + * @param string $errstr |
|
| 42 | + * @param float $timeout |
|
| 43 | + * @return resource |
|
| 44 | + */ |
|
| 45 | + public function fsockopen($hostname, $port = -1, &$errno = 0, &$errstr = '', $timeout = null) |
|
| 46 | + { |
|
| 47 | + $this->handle = fsockopen( |
|
| 48 | + $hostname, |
|
| 49 | + $port, |
|
| 50 | + $errno, |
|
| 51 | + $errstr, |
|
| 52 | + (is_null($timeout) ? ini_get("default_socket_timeout") : $timeout) |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | - if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
| 56 | - return $this->handle; |
|
| 57 | - } else { |
|
| 58 | - return false; |
|
| 59 | - } |
|
| 60 | - } |
|
| 55 | + if ($this->handle != false && $errno === 0 && $errstr === '') { |
|
| 56 | + return $this->handle; |
|
| 57 | + } else { |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * fwrite |
|
| 64 | - * |
|
| 65 | - * @see http://php.net/fwrite |
|
| 66 | - * @param string $string |
|
| 67 | - * @param int $length |
|
| 68 | - * @return int | bool |
|
| 69 | - */ |
|
| 70 | - public function fwrite($string, $length = null) |
|
| 71 | - { |
|
| 72 | - return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
| 73 | - } |
|
| 62 | + /** |
|
| 63 | + * fwrite |
|
| 64 | + * |
|
| 65 | + * @see http://php.net/fwrite |
|
| 66 | + * @param string $string |
|
| 67 | + * @param int $length |
|
| 68 | + * @return int | bool |
|
| 69 | + */ |
|
| 70 | + public function fwrite($string, $length = null) |
|
| 71 | + { |
|
| 72 | + return fwrite($this->handle, $string, (is_null($length) ? strlen($string) : $length)); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * fgets |
|
| 77 | - * |
|
| 78 | - * @see http://php.net/fgets |
|
| 79 | - * @param int $length |
|
| 80 | - */ |
|
| 81 | - public function fgets($length = null) |
|
| 82 | - { |
|
| 83 | - return fgets($this->handle, $length); |
|
| 84 | - } |
|
| 75 | + /** |
|
| 76 | + * fgets |
|
| 77 | + * |
|
| 78 | + * @see http://php.net/fgets |
|
| 79 | + * @param int $length |
|
| 80 | + */ |
|
| 81 | + public function fgets($length = null) |
|
| 82 | + { |
|
| 83 | + return fgets($this->handle, $length); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * feof |
|
| 88 | - * |
|
| 89 | - * @see http://php.net/feof |
|
| 90 | - * @return bool |
|
| 91 | - */ |
|
| 92 | - public function feof() |
|
| 93 | - { |
|
| 94 | - return feof($this->handle); |
|
| 95 | - } |
|
| 86 | + /** |
|
| 87 | + * feof |
|
| 88 | + * |
|
| 89 | + * @see http://php.net/feof |
|
| 90 | + * @return bool |
|
| 91 | + */ |
|
| 92 | + public function feof() |
|
| 93 | + { |
|
| 94 | + return feof($this->handle); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * fclose |
|
| 99 | - * |
|
| 100 | - * @see http://php.net/fclose |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 103 | - public function fclose() |
|
| 104 | - { |
|
| 105 | - return fclose($this->handle); |
|
| 106 | - } |
|
| 97 | + /** |
|
| 98 | + * fclose |
|
| 99 | + * |
|
| 100 | + * @see http://php.net/fclose |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | + public function fclose() |
|
| 104 | + { |
|
| 105 | + return fclose($this->handle); |
|
| 106 | + } |
|
| 107 | 107 | } |
@@ -33,18 +33,18 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | public function log(\Exception $exception, $time = 0) |
| 35 | 35 | { |
| 36 | - if (! $time) { |
|
| 36 | + if ( ! $time) { |
|
| 37 | 37 | $time = time(); |
| 38 | 38 | } |
| 39 | 39 | $exception_log = '----------------------------------------------------------------------------------------'; |
| 40 | 40 | $exception_log .= PHP_EOL; |
| 41 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 42 | - $exception_log .= 'Message: ' . $exception->getMessage() . PHP_EOL; |
|
| 43 | - $exception_log .= 'Code: ' . $exception->getCode() . PHP_EOL; |
|
| 44 | - $exception_log .= 'File: ' . $exception->getFile() . PHP_EOL; |
|
| 45 | - $exception_log .= 'Line No: ' . $exception->getLine() . PHP_EOL; |
|
| 46 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 47 | - $exception_log .= $exception->getTraceAsString() . PHP_EOL; |
|
| 41 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
| 42 | + $exception_log .= 'Message: '.$exception->getMessage().PHP_EOL; |
|
| 43 | + $exception_log .= 'Code: '.$exception->getCode().PHP_EOL; |
|
| 44 | + $exception_log .= 'File: '.$exception->getFile().PHP_EOL; |
|
| 45 | + $exception_log .= 'Line No: '.$exception->getLine().PHP_EOL; |
|
| 46 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
| 47 | + $exception_log .= $exception->getTraceAsString().PHP_EOL; |
|
| 48 | 48 | $exception_log .= '----------------------------------------------------------------------------------------'; |
| 49 | 49 | $exception_log .= PHP_EOL; |
| 50 | 50 | error_log($exception_log); |
@@ -12,39 +12,39 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class ExceptionLogger |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * ExceptionLogger constructor. |
|
| 17 | - * |
|
| 18 | - * @param \Exception $exception |
|
| 19 | - */ |
|
| 20 | - public function __construct(\Exception $exception) |
|
| 21 | - { |
|
| 22 | - $this->log($exception); |
|
| 23 | - } |
|
| 15 | + /** |
|
| 16 | + * ExceptionLogger constructor. |
|
| 17 | + * |
|
| 18 | + * @param \Exception $exception |
|
| 19 | + */ |
|
| 20 | + public function __construct(\Exception $exception) |
|
| 21 | + { |
|
| 22 | + $this->log($exception); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * write exception details to log file |
|
| 28 | - * |
|
| 29 | - * @param \Exception $exception |
|
| 30 | - * @param int $time |
|
| 31 | - */ |
|
| 32 | - public function log(\Exception $exception, $time = 0) |
|
| 33 | - { |
|
| 34 | - if (! $time) { |
|
| 35 | - $time = time(); |
|
| 36 | - } |
|
| 37 | - $exception_log = '----------------------------------------------------------------------------------------'; |
|
| 38 | - $exception_log .= PHP_EOL; |
|
| 39 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 40 | - $exception_log .= 'Message: ' . $exception->getMessage() . PHP_EOL; |
|
| 41 | - $exception_log .= 'Code: ' . $exception->getCode() . PHP_EOL; |
|
| 42 | - $exception_log .= 'File: ' . $exception->getFile() . PHP_EOL; |
|
| 43 | - $exception_log .= 'Line No: ' . $exception->getLine() . PHP_EOL; |
|
| 44 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 45 | - $exception_log .= $exception->getTraceAsString() . PHP_EOL; |
|
| 46 | - $exception_log .= '----------------------------------------------------------------------------------------'; |
|
| 47 | - $exception_log .= PHP_EOL; |
|
| 48 | - error_log($exception_log); |
|
| 49 | - } |
|
| 26 | + /** |
|
| 27 | + * write exception details to log file |
|
| 28 | + * |
|
| 29 | + * @param \Exception $exception |
|
| 30 | + * @param int $time |
|
| 31 | + */ |
|
| 32 | + public function log(\Exception $exception, $time = 0) |
|
| 33 | + { |
|
| 34 | + if (! $time) { |
|
| 35 | + $time = time(); |
|
| 36 | + } |
|
| 37 | + $exception_log = '----------------------------------------------------------------------------------------'; |
|
| 38 | + $exception_log .= PHP_EOL; |
|
| 39 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
| 40 | + $exception_log .= 'Message: ' . $exception->getMessage() . PHP_EOL; |
|
| 41 | + $exception_log .= 'Code: ' . $exception->getCode() . PHP_EOL; |
|
| 42 | + $exception_log .= 'File: ' . $exception->getFile() . PHP_EOL; |
|
| 43 | + $exception_log .= 'Line No: ' . $exception->getLine() . PHP_EOL; |
|
| 44 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
| 45 | + $exception_log .= $exception->getTraceAsString() . PHP_EOL; |
|
| 46 | + $exception_log .= '----------------------------------------------------------------------------------------'; |
|
| 47 | + $exception_log .= PHP_EOL; |
|
| 48 | + error_log($exception_log); |
|
| 49 | + } |
|
| 50 | 50 | } |
@@ -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 | ); |
@@ -14,26 +14,26 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | abstract class FormatterBase implements FormatterInterface |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
| 19 | - * |
|
| 20 | - * @param array $input |
|
| 21 | - * @return array |
|
| 22 | - * @throws InvalidDataTypeException if $input is not an array |
|
| 23 | - */ |
|
| 24 | - public function formatArray($input) |
|
| 25 | - { |
|
| 26 | - if (! is_array($input)) { |
|
| 27 | - throw new InvalidDataTypeException('input', $input, 'array'); |
|
| 28 | - } |
|
| 29 | - // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
| 30 | - $formatter = $this; |
|
| 31 | - array_walk_recursive( |
|
| 32 | - $input, |
|
| 33 | - function (&$value, $key) use ($formatter) { |
|
| 34 | - $value = $formatter->format($value); |
|
| 35 | - } |
|
| 36 | - ); |
|
| 37 | - return $input; |
|
| 38 | - } |
|
| 17 | + /** |
|
| 18 | + * Recursively applies the formatting to all VALUES in this multi-dimensional array |
|
| 19 | + * |
|
| 20 | + * @param array $input |
|
| 21 | + * @return array |
|
| 22 | + * @throws InvalidDataTypeException if $input is not an array |
|
| 23 | + */ |
|
| 24 | + public function formatArray($input) |
|
| 25 | + { |
|
| 26 | + if (! is_array($input)) { |
|
| 27 | + throw new InvalidDataTypeException('input', $input, 'array'); |
|
| 28 | + } |
|
| 29 | + // we can use $this inside the closure in PHP 5.3, so pass in a variable pointing to this instead |
|
| 30 | + $formatter = $this; |
|
| 31 | + array_walk_recursive( |
|
| 32 | + $input, |
|
| 33 | + function (&$value, $key) use ($formatter) { |
|
| 34 | + $value = $formatter->format($value); |
|
| 35 | + } |
|
| 36 | + ); |
|
| 37 | + return $input; |
|
| 38 | + } |
|
| 39 | 39 | } |
@@ -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); |
@@ -23,92 +23,92 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class RequestStackCoreApp implements RequestDecoratorInterface, RequestStackCoreAppInterface |
| 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 | - $capabilities_checker = $loader->getShared( |
|
| 68 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 69 | - [EE_Capabilities::instance()] |
|
| 70 | - ); |
|
| 71 | - $loader->getShared( |
|
| 72 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager', |
|
| 73 | - [$capabilities_checker, $request] |
|
| 74 | - ); |
|
| 75 | - // WP cron jobs |
|
| 76 | - $loader->getShared('EE_Cron_Tasks'); |
|
| 77 | - $loader->getShared('EE_System'); |
|
| 78 | - return $this->response; |
|
| 79 | - } |
|
| 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 | + $capabilities_checker = $loader->getShared( |
|
| 68 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
| 69 | + [EE_Capabilities::instance()] |
|
| 70 | + ); |
|
| 71 | + $loader->getShared( |
|
| 72 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager', |
|
| 73 | + [$capabilities_checker, $request] |
|
| 74 | + ); |
|
| 75 | + // WP cron jobs |
|
| 76 | + $loader->getShared('EE_Cron_Tasks'); |
|
| 77 | + $loader->getShared('EE_System'); |
|
| 78 | + return $this->response; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * set framework for the rest of EE to hook into when loading |
|
| 84 | - * |
|
| 85 | - * @throws EE_Error |
|
| 86 | - */ |
|
| 87 | - private function setupFramework() |
|
| 88 | - { |
|
| 89 | - espresso_load_required( |
|
| 90 | - 'EE_Bootstrap', |
|
| 91 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
| 92 | - ); |
|
| 93 | - add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1); |
|
| 94 | - add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3); |
|
| 95 | - add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5); |
|
| 96 | - add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7); |
|
| 97 | - add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9); |
|
| 98 | - } |
|
| 82 | + /** |
|
| 83 | + * set framework for the rest of EE to hook into when loading |
|
| 84 | + * |
|
| 85 | + * @throws EE_Error |
|
| 86 | + */ |
|
| 87 | + private function setupFramework() |
|
| 88 | + { |
|
| 89 | + espresso_load_required( |
|
| 90 | + 'EE_Bootstrap', |
|
| 91 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
| 92 | + ); |
|
| 93 | + add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1); |
|
| 94 | + add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3); |
|
| 95 | + add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5); |
|
| 96 | + add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7); |
|
| 97 | + add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * called after the request stack has been fully processed |
|
| 103 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
| 104 | - * |
|
| 105 | - * @param RequestInterface $request |
|
| 106 | - * @param ResponseInterface $response |
|
| 107 | - */ |
|
| 108 | - public function handleResponse(RequestInterface $request, ResponseInterface $response) |
|
| 109 | - { |
|
| 110 | - if ($response->pluginDeactivated()) { |
|
| 111 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
| 112 | - } |
|
| 113 | - } |
|
| 101 | + /** |
|
| 102 | + * called after the request stack has been fully processed |
|
| 103 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
| 104 | + * |
|
| 105 | + * @param RequestInterface $request |
|
| 106 | + * @param ResponseInterface $response |
|
| 107 | + */ |
|
| 108 | + public function handleResponse(RequestInterface $request, ResponseInterface $response) |
|
| 109 | + { |
|
| 110 | + if ($response->pluginDeactivated()) { |
|
| 111 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -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; |
@@ -19,97 +19,97 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class RequestStackBuilder extends SplDoublyLinkedList |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @type LoaderInterface $loader |
|
| 24 | - */ |
|
| 25 | - private $loader; |
|
| 22 | + /** |
|
| 23 | + * @type LoaderInterface $loader |
|
| 24 | + */ |
|
| 25 | + private $loader; |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * RequestStackBuilder constructor. |
|
| 30 | - * |
|
| 31 | - * @param LoaderInterface $loader |
|
| 32 | - */ |
|
| 33 | - public function __construct(LoaderInterface $loader) |
|
| 34 | - { |
|
| 35 | - $this->loader = $loader; |
|
| 36 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 37 | - } |
|
| 28 | + /** |
|
| 29 | + * RequestStackBuilder constructor. |
|
| 30 | + * |
|
| 31 | + * @param LoaderInterface $loader |
|
| 32 | + */ |
|
| 33 | + public function __construct(LoaderInterface $loader) |
|
| 34 | + { |
|
| 35 | + $this->loader = $loader; |
|
| 36 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * builds decorated middleware stack |
|
| 42 | - * by continuously injecting previous middleware app into the next |
|
| 43 | - * |
|
| 44 | - * @param RequestStackCoreAppInterface $application |
|
| 45 | - * @return RequestStack |
|
| 46 | - * @throws Exception |
|
| 47 | - */ |
|
| 48 | - public function resolve(RequestStackCoreAppInterface $application) |
|
| 49 | - { |
|
| 50 | - $core_app = $application; |
|
| 51 | - // NOW... because the RequestStack is following the decorator pattern, |
|
| 52 | - // the first stack app we add will end up at the center of the stack, |
|
| 53 | - // and will end up being the last item to actually run, but we don't want that! |
|
| 54 | - // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 55 | - // BUT... we want the final stack to be in the same order as the first. |
|
| 56 | - // So we need to reverse the iterator mode when transferring items, |
|
| 57 | - // because if we don't, the second stack will end up in the incorrect order. |
|
| 58 | - $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 59 | - for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 60 | - try { |
|
| 61 | - $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 62 | - $middleware_app_class = array_shift($middleware_app); |
|
| 63 | - $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 64 | - $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 65 | - $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 66 | - } catch (InvalidRequestStackMiddlewareException $exception) { |
|
| 67 | - if (WP_DEBUG) { |
|
| 68 | - new ExceptionStackTraceDisplay($exception); |
|
| 69 | - continue; |
|
| 70 | - } |
|
| 71 | - error_log($exception->getMessage()); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - return new RequestStack($application, $core_app); |
|
| 75 | - } |
|
| 40 | + /** |
|
| 41 | + * builds decorated middleware stack |
|
| 42 | + * by continuously injecting previous middleware app into the next |
|
| 43 | + * |
|
| 44 | + * @param RequestStackCoreAppInterface $application |
|
| 45 | + * @return RequestStack |
|
| 46 | + * @throws Exception |
|
| 47 | + */ |
|
| 48 | + public function resolve(RequestStackCoreAppInterface $application) |
|
| 49 | + { |
|
| 50 | + $core_app = $application; |
|
| 51 | + // NOW... because the RequestStack is following the decorator pattern, |
|
| 52 | + // the first stack app we add will end up at the center of the stack, |
|
| 53 | + // and will end up being the last item to actually run, but we don't want that! |
|
| 54 | + // Basically we're dealing with TWO stacks, and transferring items from one to the other, |
|
| 55 | + // BUT... we want the final stack to be in the same order as the first. |
|
| 56 | + // So we need to reverse the iterator mode when transferring items, |
|
| 57 | + // because if we don't, the second stack will end up in the incorrect order. |
|
| 58 | + $this->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); |
|
| 59 | + for ($this->rewind(); $this->valid(); $this->next()) { |
|
| 60 | + try { |
|
| 61 | + $middleware_app = $this->validateMiddlewareAppDetails($this->current(), true); |
|
| 62 | + $middleware_app_class = array_shift($middleware_app); |
|
| 63 | + $middleware_app_args = is_array($middleware_app) ? $middleware_app : array(); |
|
| 64 | + $middleware_app_args = array($application, $this->loader) + $middleware_app_args; |
|
| 65 | + $application = $this->loader->getShared($middleware_app_class, $middleware_app_args); |
|
| 66 | + } catch (InvalidRequestStackMiddlewareException $exception) { |
|
| 67 | + if (WP_DEBUG) { |
|
| 68 | + new ExceptionStackTraceDisplay($exception); |
|
| 69 | + continue; |
|
| 70 | + } |
|
| 71 | + error_log($exception->getMessage()); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + return new RequestStack($application, $core_app); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 80 | - * are all ordered correctly so that the middleware can be properly constructed |
|
| 81 | - * |
|
| 82 | - * @param array $middleware_app |
|
| 83 | - * @param bool $recurse |
|
| 84 | - * @return array |
|
| 85 | - * @throws InvalidRequestStackMiddlewareException |
|
| 86 | - */ |
|
| 87 | - protected function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 88 | - { |
|
| 89 | - $middleware_app_class = reset($middleware_app); |
|
| 90 | - // is array empty ? |
|
| 91 | - if ($middleware_app_class === false) { |
|
| 92 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 93 | - } |
|
| 94 | - // are the class and arguments in the wrong order ? |
|
| 95 | - if (is_array($middleware_app_class)) { |
|
| 96 | - if ($recurse === true) { |
|
| 97 | - return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 98 | - } |
|
| 99 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 100 | - } |
|
| 101 | - // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
| 102 | - if (is_int($middleware_app_class)) { |
|
| 103 | - if ($recurse === true) { |
|
| 104 | - $middleware_app = array_reverse($middleware_app); |
|
| 105 | - return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
| 106 | - } |
|
| 107 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 108 | - } |
|
| 109 | - // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 110 | - if (! class_exists($middleware_app_class)) { |
|
| 111 | - throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 112 | - } |
|
| 113 | - return $middleware_app; |
|
| 114 | - } |
|
| 78 | + /** |
|
| 79 | + * Ensures that the app details that have been pushed onto RequestStackBuilder |
|
| 80 | + * are all ordered correctly so that the middleware can be properly constructed |
|
| 81 | + * |
|
| 82 | + * @param array $middleware_app |
|
| 83 | + * @param bool $recurse |
|
| 84 | + * @return array |
|
| 85 | + * @throws InvalidRequestStackMiddlewareException |
|
| 86 | + */ |
|
| 87 | + protected function validateMiddlewareAppDetails(array $middleware_app, $recurse = false) |
|
| 88 | + { |
|
| 89 | + $middleware_app_class = reset($middleware_app); |
|
| 90 | + // is array empty ? |
|
| 91 | + if ($middleware_app_class === false) { |
|
| 92 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 93 | + } |
|
| 94 | + // are the class and arguments in the wrong order ? |
|
| 95 | + if (is_array($middleware_app_class)) { |
|
| 96 | + if ($recurse === true) { |
|
| 97 | + return $this->validateMiddlewareAppDetails(array_reverse($middleware_app)); |
|
| 98 | + } |
|
| 99 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 100 | + } |
|
| 101 | + // is filter callback working like legacy middleware and sending a numerically indexed array ? |
|
| 102 | + if (is_int($middleware_app_class)) { |
|
| 103 | + if ($recurse === true) { |
|
| 104 | + $middleware_app = array_reverse($middleware_app); |
|
| 105 | + return $this->validateMiddlewareAppDetails(array(reset($middleware_app), array())); |
|
| 106 | + } |
|
| 107 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 108 | + } |
|
| 109 | + // is $middleware_app_class a valid FQCN (or class is already loaded) ? |
|
| 110 | + if (! class_exists($middleware_app_class)) { |
|
| 111 | + throw new InvalidRequestStackMiddlewareException($middleware_app_class); |
|
| 112 | + } |
|
| 113 | + return $middleware_app; |
|
| 114 | + } |
|
| 115 | 115 | } |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | { |
| 69 | 69 | $this->request = $request; |
| 70 | 70 | $this->response = $response; |
| 71 | - if (! $this->response->requestTerminated()) { |
|
| 71 | + if ( ! $this->response->requestTerminated()) { |
|
| 72 | 72 | $this->response = $this->request_stack_app->handleRequest($this->request, $this->response); |
| 73 | 73 | } |
| 74 | 74 | return $this->response; |
@@ -24,52 +24,52 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | abstract class Middleware implements RequestDecoratorInterface |
| 26 | 26 | { |
| 27 | - /** |
|
| 28 | - * @var RequestDecoratorInterface $request_stack_app |
|
| 29 | - */ |
|
| 30 | - protected $request_stack_app; |
|
| 27 | + /** |
|
| 28 | + * @var RequestDecoratorInterface $request_stack_app |
|
| 29 | + */ |
|
| 30 | + protected $request_stack_app; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var RequestInterface $request |
|
| 34 | - */ |
|
| 35 | - protected $request; |
|
| 32 | + /** |
|
| 33 | + * @var RequestInterface $request |
|
| 34 | + */ |
|
| 35 | + protected $request; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var ResponseInterface $response |
|
| 39 | - */ |
|
| 40 | - protected $response; |
|
| 37 | + /** |
|
| 38 | + * @var ResponseInterface $response |
|
| 39 | + */ |
|
| 40 | + protected $response; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var LoaderInterface |
|
| 44 | - */ |
|
| 45 | - protected $loader; |
|
| 42 | + /** |
|
| 43 | + * @var LoaderInterface |
|
| 44 | + */ |
|
| 45 | + protected $loader; |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param RequestDecoratorInterface $request_stack_app |
|
| 50 | - * @param LoaderInterface $loader |
|
| 51 | - */ |
|
| 52 | - public function __construct(RequestDecoratorInterface $request_stack_app, LoaderInterface $loader) |
|
| 53 | - { |
|
| 54 | - $this->request_stack_app = $request_stack_app; |
|
| 55 | - $this->loader = $loader; |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * @param RequestDecoratorInterface $request_stack_app |
|
| 50 | + * @param LoaderInterface $loader |
|
| 51 | + */ |
|
| 52 | + public function __construct(RequestDecoratorInterface $request_stack_app, LoaderInterface $loader) |
|
| 53 | + { |
|
| 54 | + $this->request_stack_app = $request_stack_app; |
|
| 55 | + $this->loader = $loader; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * process_request_stack |
|
| 61 | - * |
|
| 62 | - * @param RequestInterface $request |
|
| 63 | - * @param ResponseInterface $response |
|
| 64 | - * @return ResponseInterface |
|
| 65 | - */ |
|
| 66 | - protected function processRequestStack(RequestInterface $request, ResponseInterface $response) |
|
| 67 | - { |
|
| 68 | - $this->request = $request; |
|
| 69 | - $this->response = $response; |
|
| 70 | - if (! $this->response->requestTerminated()) { |
|
| 71 | - $this->response = $this->request_stack_app->handleRequest($this->request, $this->response); |
|
| 72 | - } |
|
| 73 | - return $this->response; |
|
| 74 | - } |
|
| 59 | + /** |
|
| 60 | + * process_request_stack |
|
| 61 | + * |
|
| 62 | + * @param RequestInterface $request |
|
| 63 | + * @param ResponseInterface $response |
|
| 64 | + * @return ResponseInterface |
|
| 65 | + */ |
|
| 66 | + protected function processRequestStack(RequestInterface $request, ResponseInterface $response) |
|
| 67 | + { |
|
| 68 | + $this->request = $request; |
|
| 69 | + $this->response = $response; |
|
| 70 | + if (! $this->response->requestTerminated()) { |
|
| 71 | + $this->response = $this->request_stack_app->handleRequest($this->request, $this->response); |
|
| 72 | + } |
|
| 73 | + return $this->response; |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | public function add($object, $identifier = null) |
| 44 | 44 | { |
| 45 | - if (! is_object($object)) { |
|
| 45 | + if ( ! is_object($object)) { |
|
| 46 | 46 | throw new InvalidEntityException($object, 'object'); |
| 47 | 47 | } |
| 48 | 48 | $this->attach($object); |
@@ -14,37 +14,37 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class LooseCollection extends Collection |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * setCollectionInterface |
|
| 19 | - * |
|
| 20 | - * @access protected |
|
| 21 | - * @param string $collection_interface |
|
| 22 | - */ |
|
| 23 | - protected function setCollectionInterface($collection_interface) |
|
| 24 | - { |
|
| 25 | - $this->collection_interface = ''; |
|
| 26 | - } |
|
| 17 | + /** |
|
| 18 | + * setCollectionInterface |
|
| 19 | + * |
|
| 20 | + * @access protected |
|
| 21 | + * @param string $collection_interface |
|
| 22 | + */ |
|
| 23 | + protected function setCollectionInterface($collection_interface) |
|
| 24 | + { |
|
| 25 | + $this->collection_interface = ''; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * add |
|
| 31 | - * attaches an object to the Collection |
|
| 32 | - * and sets any supplied data associated with the current iterator entry |
|
| 33 | - * by calling EE_Object_Collection::set_identifier() |
|
| 34 | - * |
|
| 35 | - * @access public |
|
| 36 | - * @param mixed $object |
|
| 37 | - * @param mixed $identifier |
|
| 38 | - * @return bool |
|
| 39 | - * @throws InvalidEntityException |
|
| 40 | - */ |
|
| 41 | - public function add($object, $identifier = null) |
|
| 42 | - { |
|
| 43 | - if (! is_object($object)) { |
|
| 44 | - throw new InvalidEntityException($object, 'object'); |
|
| 45 | - } |
|
| 46 | - $this->attach($object); |
|
| 47 | - $this->setIdentifier($object, $identifier); |
|
| 48 | - return $this->contains($object); |
|
| 49 | - } |
|
| 29 | + /** |
|
| 30 | + * add |
|
| 31 | + * attaches an object to the Collection |
|
| 32 | + * and sets any supplied data associated with the current iterator entry |
|
| 33 | + * by calling EE_Object_Collection::set_identifier() |
|
| 34 | + * |
|
| 35 | + * @access public |
|
| 36 | + * @param mixed $object |
|
| 37 | + * @param mixed $identifier |
|
| 38 | + * @return bool |
|
| 39 | + * @throws InvalidEntityException |
|
| 40 | + */ |
|
| 41 | + public function add($object, $identifier = null) |
|
| 42 | + { |
|
| 43 | + if (! is_object($object)) { |
|
| 44 | + throw new InvalidEntityException($object, 'object'); |
|
| 45 | + } |
|
| 46 | + $this->attach($object); |
|
| 47 | + $this->setIdentifier($object, $identifier); |
|
| 48 | + return $this->contains($object); |
|
| 49 | + } |
|
| 50 | 50 | } |