@@ -91,7 +91,7 @@ |
||
91 | 91 | public function __construct($slug, $description) |
92 | 92 | { |
93 | 93 | parent::__construct($slug, $description); |
94 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
94 | + if ( ! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
95 | 95 | throw new InvalidArgumentException( |
96 | 96 | sprintf( |
97 | 97 | esc_html__( |
@@ -16,155 +16,155 @@ |
||
16 | 16 | class RequestTypeContext extends Context |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * indicates that the current request involves some form of activation |
|
21 | - */ |
|
22 | - const ACTIVATION = 'activation-request'; |
|
23 | - |
|
24 | - /** |
|
25 | - * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | - */ |
|
27 | - const ADMIN = 'non-ajax-admin-request'; |
|
28 | - |
|
29 | - /** |
|
30 | - * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | - */ |
|
32 | - const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | - |
|
34 | - /** |
|
35 | - * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | - */ |
|
37 | - const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | - |
|
39 | - /** |
|
40 | - * indicates that the current request is for the WP Heartbeat |
|
41 | - */ |
|
42 | - const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
43 | - |
|
44 | - /** |
|
45 | - * indicates that the current request is being made via AJAX, but is NOT for EE |
|
46 | - */ |
|
47 | - const AJAX_OTHER = 'other-ajax-request'; |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates that the current request is for the EE REST API |
|
51 | - */ |
|
52 | - const API = 'rest-api'; |
|
53 | - |
|
54 | - /** |
|
55 | - * indicates that the current request is from the command line |
|
56 | - */ |
|
57 | - const CLI = 'command-line'; |
|
58 | - |
|
59 | - /** |
|
60 | - * indicates that the current request is for a WP_Cron |
|
61 | - */ |
|
62 | - const CRON = 'wp-cron'; |
|
63 | - |
|
64 | - /** |
|
65 | - * indicates that the current request is for a feed (ie: RSS) |
|
66 | - */ |
|
67 | - const FEED = 'feed-request'; |
|
68 | - |
|
69 | - /** |
|
70 | - * indicates that the current request is for the frontend but is not being made via AJAX |
|
71 | - */ |
|
72 | - const FRONTEND = 'non-ajax-frontend-request'; |
|
73 | - |
|
74 | - /** |
|
75 | - * indicates that the current request is for content that is to be displayed within an iframe |
|
76 | - */ |
|
77 | - const IFRAME = 'iframe-request'; |
|
78 | - |
|
79 | - /** |
|
80 | - * indicates that the current request is for the WP REST API |
|
81 | - */ |
|
82 | - const WP_API = 'wp-rest-api'; |
|
83 | - |
|
84 | - /** |
|
85 | - * indicates that the current request is a loopback sent from WP core to test for errors |
|
86 | - */ |
|
87 | - const WP_SCRAPE = 'wordpress-scrape'; |
|
88 | - |
|
89 | - /** |
|
90 | - * @var boolean $is_activation |
|
91 | - */ |
|
92 | - private $is_activation = false; |
|
93 | - |
|
94 | - /** |
|
95 | - * @var array $valid_request_types |
|
96 | - */ |
|
97 | - private $valid_request_types = array(); |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * RequestTypeContext constructor. |
|
102 | - * |
|
103 | - * @param string $slug |
|
104 | - * @param string $description |
|
105 | - * @throws InvalidArgumentException |
|
106 | - */ |
|
107 | - public function __construct($slug, $description) |
|
108 | - { |
|
109 | - parent::__construct($slug, $description); |
|
110 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
111 | - throw new InvalidArgumentException( |
|
112 | - sprintf( |
|
113 | - esc_html__( |
|
114 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - var_export($this->validRequestTypes(), true) |
|
118 | - ) |
|
119 | - ); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return array |
|
126 | - */ |
|
127 | - public function validRequestTypes() |
|
128 | - { |
|
129 | - if (empty($this->valid_request_types)) { |
|
130 | - $this->valid_request_types = apply_filters( |
|
131 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
132 | - array( |
|
133 | - RequestTypeContext::ACTIVATION, |
|
134 | - RequestTypeContext::ADMIN, |
|
135 | - RequestTypeContext::AJAX_ADMIN, |
|
136 | - RequestTypeContext::AJAX_FRONT, |
|
137 | - RequestTypeContext::AJAX_HEARTBEAT, |
|
138 | - RequestTypeContext::AJAX_OTHER, |
|
139 | - RequestTypeContext::API, |
|
140 | - RequestTypeContext::CLI, |
|
141 | - RequestTypeContext::CRON, |
|
142 | - RequestTypeContext::FEED, |
|
143 | - RequestTypeContext::FRONTEND, |
|
144 | - RequestTypeContext::IFRAME, |
|
145 | - RequestTypeContext::WP_API, |
|
146 | - RequestTypeContext::WP_SCRAPE, |
|
147 | - ) |
|
148 | - ); |
|
149 | - } |
|
150 | - return $this->valid_request_types; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function isActivation() |
|
158 | - { |
|
159 | - return $this->is_activation; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param bool $is_activation |
|
165 | - */ |
|
166 | - public function setIsActivation($is_activation) |
|
167 | - { |
|
168 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
169 | - } |
|
19 | + /** |
|
20 | + * indicates that the current request involves some form of activation |
|
21 | + */ |
|
22 | + const ACTIVATION = 'activation-request'; |
|
23 | + |
|
24 | + /** |
|
25 | + * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | + */ |
|
27 | + const ADMIN = 'non-ajax-admin-request'; |
|
28 | + |
|
29 | + /** |
|
30 | + * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | + */ |
|
32 | + const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | + |
|
34 | + /** |
|
35 | + * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | + */ |
|
37 | + const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | + |
|
39 | + /** |
|
40 | + * indicates that the current request is for the WP Heartbeat |
|
41 | + */ |
|
42 | + const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
43 | + |
|
44 | + /** |
|
45 | + * indicates that the current request is being made via AJAX, but is NOT for EE |
|
46 | + */ |
|
47 | + const AJAX_OTHER = 'other-ajax-request'; |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates that the current request is for the EE REST API |
|
51 | + */ |
|
52 | + const API = 'rest-api'; |
|
53 | + |
|
54 | + /** |
|
55 | + * indicates that the current request is from the command line |
|
56 | + */ |
|
57 | + const CLI = 'command-line'; |
|
58 | + |
|
59 | + /** |
|
60 | + * indicates that the current request is for a WP_Cron |
|
61 | + */ |
|
62 | + const CRON = 'wp-cron'; |
|
63 | + |
|
64 | + /** |
|
65 | + * indicates that the current request is for a feed (ie: RSS) |
|
66 | + */ |
|
67 | + const FEED = 'feed-request'; |
|
68 | + |
|
69 | + /** |
|
70 | + * indicates that the current request is for the frontend but is not being made via AJAX |
|
71 | + */ |
|
72 | + const FRONTEND = 'non-ajax-frontend-request'; |
|
73 | + |
|
74 | + /** |
|
75 | + * indicates that the current request is for content that is to be displayed within an iframe |
|
76 | + */ |
|
77 | + const IFRAME = 'iframe-request'; |
|
78 | + |
|
79 | + /** |
|
80 | + * indicates that the current request is for the WP REST API |
|
81 | + */ |
|
82 | + const WP_API = 'wp-rest-api'; |
|
83 | + |
|
84 | + /** |
|
85 | + * indicates that the current request is a loopback sent from WP core to test for errors |
|
86 | + */ |
|
87 | + const WP_SCRAPE = 'wordpress-scrape'; |
|
88 | + |
|
89 | + /** |
|
90 | + * @var boolean $is_activation |
|
91 | + */ |
|
92 | + private $is_activation = false; |
|
93 | + |
|
94 | + /** |
|
95 | + * @var array $valid_request_types |
|
96 | + */ |
|
97 | + private $valid_request_types = array(); |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * RequestTypeContext constructor. |
|
102 | + * |
|
103 | + * @param string $slug |
|
104 | + * @param string $description |
|
105 | + * @throws InvalidArgumentException |
|
106 | + */ |
|
107 | + public function __construct($slug, $description) |
|
108 | + { |
|
109 | + parent::__construct($slug, $description); |
|
110 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
111 | + throw new InvalidArgumentException( |
|
112 | + sprintf( |
|
113 | + esc_html__( |
|
114 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + var_export($this->validRequestTypes(), true) |
|
118 | + ) |
|
119 | + ); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return array |
|
126 | + */ |
|
127 | + public function validRequestTypes() |
|
128 | + { |
|
129 | + if (empty($this->valid_request_types)) { |
|
130 | + $this->valid_request_types = apply_filters( |
|
131 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
132 | + array( |
|
133 | + RequestTypeContext::ACTIVATION, |
|
134 | + RequestTypeContext::ADMIN, |
|
135 | + RequestTypeContext::AJAX_ADMIN, |
|
136 | + RequestTypeContext::AJAX_FRONT, |
|
137 | + RequestTypeContext::AJAX_HEARTBEAT, |
|
138 | + RequestTypeContext::AJAX_OTHER, |
|
139 | + RequestTypeContext::API, |
|
140 | + RequestTypeContext::CLI, |
|
141 | + RequestTypeContext::CRON, |
|
142 | + RequestTypeContext::FEED, |
|
143 | + RequestTypeContext::FRONTEND, |
|
144 | + RequestTypeContext::IFRAME, |
|
145 | + RequestTypeContext::WP_API, |
|
146 | + RequestTypeContext::WP_SCRAPE, |
|
147 | + ) |
|
148 | + ); |
|
149 | + } |
|
150 | + return $this->valid_request_types; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function isActivation() |
|
158 | + { |
|
159 | + return $this->is_activation; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param bool $is_activation |
|
165 | + */ |
|
166 | + public function setIsActivation($is_activation) |
|
167 | + { |
|
168 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
169 | + } |
|
170 | 170 | } |
@@ -11,14 +11,14 @@ |
||
11 | 11 | |
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * removes all tags which a WP Post wouldn't allow in its content normally |
|
16 | - * |
|
17 | - * @param string $value |
|
18 | - * @return string |
|
19 | - */ |
|
20 | - public function prepare_for_set($value) |
|
21 | - { |
|
22 | - return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags())); |
|
23 | - } |
|
14 | + /** |
|
15 | + * removes all tags which a WP Post wouldn't allow in its content normally |
|
16 | + * |
|
17 | + * @param string $value |
|
18 | + * @return string |
|
19 | + */ |
|
20 | + public function prepare_for_set($value) |
|
21 | + { |
|
22 | + return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags())); |
|
23 | + } |
|
24 | 24 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | */ |
52 | 52 | public function wp_user_obj() |
53 | 53 | { |
54 | - if (! $this->_wp_user_obj) { |
|
54 | + if ( ! $this->_wp_user_obj) { |
|
55 | 55 | $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
56 | 56 | } |
57 | 57 | return $this->_wp_user_obj; |
@@ -13,111 +13,111 @@ |
||
13 | 13 | class EE_WP_User extends EE_Base_Class implements EEI_Admin_Links |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var WP_User |
|
18 | - */ |
|
19 | - protected $_wp_user_obj; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @param array $props_n_values |
|
24 | - * @return EE_WP_User|mixed |
|
25 | - * @throws EE_Error |
|
26 | - * @throws ReflectionException |
|
27 | - */ |
|
28 | - public static function new_instance($props_n_values = []) |
|
29 | - { |
|
30 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
31 | - return $has_object ?: new self($props_n_values); |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @param array $props_n_values |
|
37 | - * @return EE_WP_User |
|
38 | - * @throws EE_Error |
|
39 | - * @throws ReflectionException |
|
40 | - */ |
|
41 | - public static function new_instance_from_db($props_n_values = []) |
|
42 | - { |
|
43 | - return new self($props_n_values, true); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Return a normal WP_User object (caches the object for future calls) |
|
49 | - * |
|
50 | - * @return WP_User |
|
51 | - * @throws EE_Error |
|
52 | - * @throws ReflectionException |
|
53 | - */ |
|
54 | - public function wp_user_obj() |
|
55 | - { |
|
56 | - if (! $this->_wp_user_obj) { |
|
57 | - $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
|
58 | - } |
|
59 | - return $this->_wp_user_obj; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Return the link to the admin details for the object. |
|
65 | - * |
|
66 | - * @return string |
|
67 | - * @throws EE_Error |
|
68 | - * @throws ReflectionException |
|
69 | - */ |
|
70 | - public function get_admin_details_link() |
|
71 | - { |
|
72 | - return $this->get_admin_edit_link(); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
78 | - * |
|
79 | - * @return string |
|
80 | - * @throws EE_Error |
|
81 | - * @throws ReflectionException |
|
82 | - */ |
|
83 | - public function get_admin_edit_link() |
|
84 | - { |
|
85 | - /** @var RequestInterface $request */ |
|
86 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
87 | - return esc_url( |
|
88 | - add_query_arg( |
|
89 | - 'wp_http_referer', |
|
90 | - urlencode( |
|
91 | - wp_unslash( |
|
92 | - $request->getServerParam('REQUEST_URI') |
|
93 | - ) |
|
94 | - ), |
|
95 | - get_edit_user_link($this->ID()) |
|
96 | - ) |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Returns the link to a settings page for the object. |
|
103 | - * |
|
104 | - * @return string |
|
105 | - * @throws EE_Error |
|
106 | - * @throws ReflectionException |
|
107 | - */ |
|
108 | - public function get_admin_settings_link() |
|
109 | - { |
|
110 | - return $this->get_admin_edit_link(); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
116 | - * |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public function get_admin_overview_link() |
|
120 | - { |
|
121 | - return admin_url('users.php'); |
|
122 | - } |
|
16 | + /** |
|
17 | + * @var WP_User |
|
18 | + */ |
|
19 | + protected $_wp_user_obj; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @param array $props_n_values |
|
24 | + * @return EE_WP_User|mixed |
|
25 | + * @throws EE_Error |
|
26 | + * @throws ReflectionException |
|
27 | + */ |
|
28 | + public static function new_instance($props_n_values = []) |
|
29 | + { |
|
30 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
31 | + return $has_object ?: new self($props_n_values); |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @param array $props_n_values |
|
37 | + * @return EE_WP_User |
|
38 | + * @throws EE_Error |
|
39 | + * @throws ReflectionException |
|
40 | + */ |
|
41 | + public static function new_instance_from_db($props_n_values = []) |
|
42 | + { |
|
43 | + return new self($props_n_values, true); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Return a normal WP_User object (caches the object for future calls) |
|
49 | + * |
|
50 | + * @return WP_User |
|
51 | + * @throws EE_Error |
|
52 | + * @throws ReflectionException |
|
53 | + */ |
|
54 | + public function wp_user_obj() |
|
55 | + { |
|
56 | + if (! $this->_wp_user_obj) { |
|
57 | + $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
|
58 | + } |
|
59 | + return $this->_wp_user_obj; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Return the link to the admin details for the object. |
|
65 | + * |
|
66 | + * @return string |
|
67 | + * @throws EE_Error |
|
68 | + * @throws ReflectionException |
|
69 | + */ |
|
70 | + public function get_admin_details_link() |
|
71 | + { |
|
72 | + return $this->get_admin_edit_link(); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
78 | + * |
|
79 | + * @return string |
|
80 | + * @throws EE_Error |
|
81 | + * @throws ReflectionException |
|
82 | + */ |
|
83 | + public function get_admin_edit_link() |
|
84 | + { |
|
85 | + /** @var RequestInterface $request */ |
|
86 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
87 | + return esc_url( |
|
88 | + add_query_arg( |
|
89 | + 'wp_http_referer', |
|
90 | + urlencode( |
|
91 | + wp_unslash( |
|
92 | + $request->getServerParam('REQUEST_URI') |
|
93 | + ) |
|
94 | + ), |
|
95 | + get_edit_user_link($this->ID()) |
|
96 | + ) |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Returns the link to a settings page for the object. |
|
103 | + * |
|
104 | + * @return string |
|
105 | + * @throws EE_Error |
|
106 | + * @throws ReflectionException |
|
107 | + */ |
|
108 | + public function get_admin_settings_link() |
|
109 | + { |
|
110 | + return $this->get_admin_edit_link(); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
116 | + * |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public function get_admin_overview_link() |
|
120 | + { |
|
121 | + return admin_url('users.php'); |
|
122 | + } |
|
123 | 123 | } |
@@ -9,24 +9,24 @@ |
||
9 | 9 | interface EEI_Request_Decorator |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * converts a Request to a Response |
|
14 | - * can perform their logic either before or after the core application has run like so: |
|
15 | - * public function handle_request( EE_Request $request, EE_Response $response ) { |
|
16 | - * $this->request = $request; |
|
17 | - * $this->response = $response; |
|
18 | - * // logic performed BEFORE core app has run |
|
19 | - * $this->process_request_stack( $this->request, $this->response ); |
|
20 | - * // logic performed AFTER core app has run |
|
21 | - * return $response; |
|
22 | - * } |
|
23 | - * |
|
24 | - * @deprecated 4.9.53 |
|
25 | - * @param EE_Request $request |
|
26 | - * @param EE_Response $response |
|
27 | - * @return EE_Response |
|
28 | - */ |
|
29 | - public function handle_request(EE_Request $request, EE_Response $response); |
|
12 | + /** |
|
13 | + * converts a Request to a Response |
|
14 | + * can perform their logic either before or after the core application has run like so: |
|
15 | + * public function handle_request( EE_Request $request, EE_Response $response ) { |
|
16 | + * $this->request = $request; |
|
17 | + * $this->response = $response; |
|
18 | + * // logic performed BEFORE core app has run |
|
19 | + * $this->process_request_stack( $this->request, $this->response ); |
|
20 | + * // logic performed AFTER core app has run |
|
21 | + * return $response; |
|
22 | + * } |
|
23 | + * |
|
24 | + * @deprecated 4.9.53 |
|
25 | + * @param EE_Request $request |
|
26 | + * @param EE_Response $response |
|
27 | + * @return EE_Response |
|
28 | + */ |
|
29 | + public function handle_request(EE_Request $request, EE_Response $response); |
|
30 | 30 | |
31 | 31 | |
32 | 32 | } |
@@ -78,7 +78,7 @@ |
||
78 | 78 | public function preProductionVersionAdminNotice() |
79 | 79 | { |
80 | 80 | new PersistentAdminNotice( |
81 | - 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
81 | + 'preProductionVersionAdminNotice_'.EVENT_ESPRESSO_VERSION, |
|
82 | 82 | $this->warningNotice() |
83 | 83 | ); |
84 | 84 | } |
@@ -18,91 +18,91 @@ |
||
18 | 18 | class PreProductionVersionWarning extends Middleware |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * converts a Request to a Response |
|
23 | - * |
|
24 | - * @param RequestInterface $request |
|
25 | - * @param ResponseInterface $response |
|
26 | - * @return ResponseInterface |
|
27 | - */ |
|
28 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
29 | - { |
|
30 | - $this->request = $request; |
|
31 | - $this->response = $response; |
|
32 | - $this->displayPreProductionVersionWarning(); |
|
33 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
34 | - return $this->response; |
|
35 | - } |
|
21 | + /** |
|
22 | + * converts a Request to a Response |
|
23 | + * |
|
24 | + * @param RequestInterface $request |
|
25 | + * @param ResponseInterface $response |
|
26 | + * @return ResponseInterface |
|
27 | + */ |
|
28 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
29 | + { |
|
30 | + $this->request = $request; |
|
31 | + $this->response = $response; |
|
32 | + $this->displayPreProductionVersionWarning(); |
|
33 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
34 | + return $this->response; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
40 | - * |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function displayPreProductionVersionWarning() |
|
44 | - { |
|
45 | - // skip AJAX requests |
|
46 | - if ($this->request->isAjax()) { |
|
47 | - return; |
|
48 | - } |
|
49 | - // skip stable releases |
|
50 | - if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
51 | - return; |
|
52 | - } |
|
53 | - // site admin has authorized use of non-stable release candidate for production |
|
54 | - if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
55 | - return; |
|
56 | - } |
|
57 | - // post release candidate warning |
|
58 | - if ($this->request->isAdmin()) { |
|
59 | - add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
60 | - } else { |
|
61 | - add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
62 | - } |
|
63 | - } |
|
38 | + /** |
|
39 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
40 | + * |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function displayPreProductionVersionWarning() |
|
44 | + { |
|
45 | + // skip AJAX requests |
|
46 | + if ($this->request->isAjax()) { |
|
47 | + return; |
|
48 | + } |
|
49 | + // skip stable releases |
|
50 | + if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
51 | + return; |
|
52 | + } |
|
53 | + // site admin has authorized use of non-stable release candidate for production |
|
54 | + if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
55 | + return; |
|
56 | + } |
|
57 | + // post release candidate warning |
|
58 | + if ($this->request->isAdmin()) { |
|
59 | + add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
60 | + } else { |
|
61 | + add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * displays admin notice that current version of EE is not a stable release |
|
68 | - * |
|
69 | - * @return void |
|
70 | - * @throws InvalidDataTypeException |
|
71 | - */ |
|
72 | - public function preProductionVersionAdminNotice() |
|
73 | - { |
|
74 | - new PersistentAdminNotice( |
|
75 | - 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
76 | - $this->warningNotice() |
|
77 | - ); |
|
78 | - } |
|
66 | + /** |
|
67 | + * displays admin notice that current version of EE is not a stable release |
|
68 | + * |
|
69 | + * @return void |
|
70 | + * @throws InvalidDataTypeException |
|
71 | + */ |
|
72 | + public function preProductionVersionAdminNotice() |
|
73 | + { |
|
74 | + new PersistentAdminNotice( |
|
75 | + 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
76 | + $this->warningNotice() |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
83 | - * |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function preProductionVersionWarningNotice() |
|
87 | - { |
|
88 | - echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
89 | - echo $this->warningNotice(); |
|
90 | - echo '</p></div>'; |
|
91 | - } |
|
81 | + /** |
|
82 | + * displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
83 | + * |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function preProductionVersionWarningNotice() |
|
87 | + { |
|
88 | + echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
89 | + echo $this->warningNotice(); |
|
90 | + echo '</p></div>'; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - private function warningNotice() |
|
98 | - { |
|
99 | - return sprintf( |
|
100 | - esc_html__( |
|
101 | - 'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - '<strong>', |
|
105 | - '</strong>' |
|
106 | - ); |
|
107 | - } |
|
94 | + /** |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + private function warningNotice() |
|
98 | + { |
|
99 | + return sprintf( |
|
100 | + esc_html__( |
|
101 | + 'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + '<strong>', |
|
105 | + '</strong>' |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | } |
@@ -19,59 +19,59 @@ |
||
19 | 19 | class RequestStack |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var RequestDecoratorInterface $request_stack_app |
|
24 | - */ |
|
25 | - protected $request_stack_app; |
|
22 | + /** |
|
23 | + * @var RequestDecoratorInterface $request_stack_app |
|
24 | + */ |
|
25 | + protected $request_stack_app; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var RequestStackCoreAppInterface $core_app |
|
29 | - */ |
|
30 | - protected $core_app; |
|
27 | + /** |
|
28 | + * @var RequestStackCoreAppInterface $core_app |
|
29 | + */ |
|
30 | + protected $core_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 | 42 | |
43 | - /** |
|
44 | - * @param RequestDecoratorInterface $request_stack_app |
|
45 | - * @param RequestStackCoreAppInterface $core_app |
|
46 | - */ |
|
47 | - public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app) |
|
48 | - { |
|
49 | - $this->request_stack_app = $request_stack_app; |
|
50 | - $this->core_app = $core_app; |
|
51 | - } |
|
43 | + /** |
|
44 | + * @param RequestDecoratorInterface $request_stack_app |
|
45 | + * @param RequestStackCoreAppInterface $core_app |
|
46 | + */ |
|
47 | + public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app) |
|
48 | + { |
|
49 | + $this->request_stack_app = $request_stack_app; |
|
50 | + $this->core_app = $core_app; |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * @param RequestInterface $request |
|
56 | - * @param ResponseInterface $response |
|
57 | - * @return ResponseInterface |
|
58 | - */ |
|
59 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
60 | - { |
|
61 | - $this->request = $request; |
|
62 | - $this->response = $response; |
|
63 | - return $this->request_stack_app->handleRequest($request, $response); |
|
64 | - } |
|
54 | + /** |
|
55 | + * @param RequestInterface $request |
|
56 | + * @param ResponseInterface $response |
|
57 | + * @return ResponseInterface |
|
58 | + */ |
|
59 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
60 | + { |
|
61 | + $this->request = $request; |
|
62 | + $this->response = $response; |
|
63 | + return $this->request_stack_app->handleRequest($request, $response); |
|
64 | + } |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * handle_response |
|
69 | - * executes the handle_response() method on the RequestStackCoreAppInterface object |
|
70 | - * after the request stack has been fully processed |
|
71 | - */ |
|
72 | - public function handleResponse() |
|
73 | - { |
|
74 | - $this->core_app->handleResponse($this->request, $this->response); |
|
75 | - } |
|
67 | + /** |
|
68 | + * handle_response |
|
69 | + * executes the handle_response() method on the RequestStackCoreAppInterface object |
|
70 | + * after the request stack has been fully processed |
|
71 | + */ |
|
72 | + public function handleResponse() |
|
73 | + { |
|
74 | + $this->core_app->handleResponse($this->request, $this->response); |
|
75 | + } |
|
76 | 76 | } |
77 | 77 | // Location: RequestStack.php |
@@ -47,7 +47,7 @@ |
||
47 | 47 | public function __construct(RequestDecoratorInterface $request_stack_app, RequestStackCoreAppInterface $core_app) |
48 | 48 | { |
49 | 49 | $this->request_stack_app = $request_stack_app; |
50 | - $this->core_app = $core_app; |
|
50 | + $this->core_app = $core_app; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 |
@@ -9,51 +9,51 @@ |
||
9 | 9 | class CollectionFilterCallbackIterator extends FilterIterator |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * Used for determining whether the iterated object in the Collection is "valid" or not. |
|
14 | - * @var Closure |
|
15 | - */ |
|
16 | - private $acceptance_callback; |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * CollectionFilterCallbackIterator constructor. |
|
21 | - * |
|
22 | - * @param Collection $collection |
|
23 | - * @param Closure $acceptance_callback The closure will receive an instance of whatever object is stored on the |
|
24 | - * collection when iterating over the collection and should return boolean. |
|
25 | - */ |
|
26 | - public function __construct(Collection $collection, Closure $acceptance_callback) |
|
27 | - { |
|
28 | - $this->acceptance_callback = $acceptance_callback; |
|
29 | - parent::__construct($collection); |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Check whether the current element of the iterator is acceptable |
|
34 | - * |
|
35 | - * @link http://php.net/manual/en/filteriterator.accept.php |
|
36 | - * @return bool true if the current element is acceptable, otherwise false. |
|
37 | - */ |
|
38 | - public function accept() |
|
39 | - { |
|
40 | - $acceptance_callback = $this->acceptance_callback; |
|
41 | - return $acceptance_callback($this->getInnerIterator()->current()); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Returns a filtered array of objects from the collection using the provided acceptance callback |
|
48 | - * @return array |
|
49 | - */ |
|
50 | - public function getFiltered() |
|
51 | - { |
|
52 | - $filtered_array = array(); |
|
53 | - $this->rewind(); |
|
54 | - foreach ($this as $filtered_object) { |
|
55 | - $filtered_array[] = $filtered_object; |
|
56 | - } |
|
57 | - return $filtered_array; |
|
58 | - } |
|
12 | + /** |
|
13 | + * Used for determining whether the iterated object in the Collection is "valid" or not. |
|
14 | + * @var Closure |
|
15 | + */ |
|
16 | + private $acceptance_callback; |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * CollectionFilterCallbackIterator constructor. |
|
21 | + * |
|
22 | + * @param Collection $collection |
|
23 | + * @param Closure $acceptance_callback The closure will receive an instance of whatever object is stored on the |
|
24 | + * collection when iterating over the collection and should return boolean. |
|
25 | + */ |
|
26 | + public function __construct(Collection $collection, Closure $acceptance_callback) |
|
27 | + { |
|
28 | + $this->acceptance_callback = $acceptance_callback; |
|
29 | + parent::__construct($collection); |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Check whether the current element of the iterator is acceptable |
|
34 | + * |
|
35 | + * @link http://php.net/manual/en/filteriterator.accept.php |
|
36 | + * @return bool true if the current element is acceptable, otherwise false. |
|
37 | + */ |
|
38 | + public function accept() |
|
39 | + { |
|
40 | + $acceptance_callback = $this->acceptance_callback; |
|
41 | + return $acceptance_callback($this->getInnerIterator()->current()); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Returns a filtered array of objects from the collection using the provided acceptance callback |
|
48 | + * @return array |
|
49 | + */ |
|
50 | + public function getFiltered() |
|
51 | + { |
|
52 | + $filtered_array = array(); |
|
53 | + $this->rewind(); |
|
54 | + foreach ($this as $filtered_object) { |
|
55 | + $filtered_array[] = $filtered_object; |
|
56 | + } |
|
57 | + return $filtered_array; |
|
58 | + } |
|
59 | 59 | } |
@@ -16,94 +16,94 @@ |
||
16 | 16 | interface HelperInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Ensures that a valid timezone string is returned. |
|
21 | - * |
|
22 | - * @param string $timezone_string When not provided then attempt to use the timezone_string set in the WP Time |
|
23 | - * settings (or derive from set UTC offset). |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getValidTimezoneString($timezone_string = ''); |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
31 | - * |
|
32 | - * @param string $timezone_string |
|
33 | - * @param bool $throw_error |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function validateTimezone($timezone_string, $throw_error = true); |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Returns a timezone string for the provided gmt_offset. |
|
41 | - * @param float|string $gmt_offset |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function getTimezoneStringFromGmtOffset($gmt_offset = ''); |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Gets the site's GMT offset based on either the timezone string |
|
49 | - * (in which case the gmt offset will vary depending on the location's |
|
50 | - * observance of daylight savings time) or the gmt_offset wp option |
|
51 | - * |
|
52 | - * @return int seconds offset |
|
53 | - */ |
|
54 | - public function getSiteTimezoneGmtOffset(); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Get timezone transitions |
|
59 | - * @param DateTimeZone $date_time_zone |
|
60 | - * @param int|null $time |
|
61 | - * @param bool $first_only |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true); |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Get Timezone offset for given timezone object |
|
69 | - * @param DateTimeZone $date_time_zone |
|
70 | - * @param null|int $time |
|
71 | - * @return int |
|
72 | - */ |
|
73 | - public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null); |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Provide a timezone select input |
|
78 | - * @param string $timezone_string |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function timezoneSelectInput($timezone_string = ''); |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
86 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
87 | - * the site is used. |
|
88 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
89 | - * computed timestamp (i.e. date_i18n() ) |
|
90 | - * |
|
91 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
92 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
93 | - * site will be used. |
|
94 | - * @return int unix_timestamp value with the offset applied for the given timezone. |
|
95 | - */ |
|
96 | - public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = ''); |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Depending on PHP version, |
|
101 | - * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
102 | - * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
103 | - * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
104 | - * |
|
105 | - * @param int $gmt_offset |
|
106 | - * @return int |
|
107 | - */ |
|
108 | - public function adjustInvalidGmtOffsets($gmt_offset); |
|
19 | + /** |
|
20 | + * Ensures that a valid timezone string is returned. |
|
21 | + * |
|
22 | + * @param string $timezone_string When not provided then attempt to use the timezone_string set in the WP Time |
|
23 | + * settings (or derive from set UTC offset). |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getValidTimezoneString($timezone_string = ''); |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * The only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
31 | + * |
|
32 | + * @param string $timezone_string |
|
33 | + * @param bool $throw_error |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function validateTimezone($timezone_string, $throw_error = true); |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Returns a timezone string for the provided gmt_offset. |
|
41 | + * @param float|string $gmt_offset |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function getTimezoneStringFromGmtOffset($gmt_offset = ''); |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Gets the site's GMT offset based on either the timezone string |
|
49 | + * (in which case the gmt offset will vary depending on the location's |
|
50 | + * observance of daylight savings time) or the gmt_offset wp option |
|
51 | + * |
|
52 | + * @return int seconds offset |
|
53 | + */ |
|
54 | + public function getSiteTimezoneGmtOffset(); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Get timezone transitions |
|
59 | + * @param DateTimeZone $date_time_zone |
|
60 | + * @param int|null $time |
|
61 | + * @param bool $first_only |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + public function getTimezoneTransitions(DateTimeZone $date_time_zone, $time = null, $first_only = true); |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Get Timezone offset for given timezone object |
|
69 | + * @param DateTimeZone $date_time_zone |
|
70 | + * @param null|int $time |
|
71 | + * @return int |
|
72 | + */ |
|
73 | + public function getTimezoneOffset(DateTimeZone $date_time_zone, $time = null); |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Provide a timezone select input |
|
78 | + * @param string $timezone_string |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function timezoneSelectInput($timezone_string = ''); |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
86 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
87 | + * the site is used. |
|
88 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
89 | + * computed timestamp (i.e. date_i18n() ) |
|
90 | + * |
|
91 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
92 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
93 | + * site will be used. |
|
94 | + * @return int unix_timestamp value with the offset applied for the given timezone. |
|
95 | + */ |
|
96 | + public function getTimestampWithOffset($unix_timestamp = 0, $timezone_string = ''); |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Depending on PHP version, |
|
101 | + * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
102 | + * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
103 | + * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
104 | + * |
|
105 | + * @param int $gmt_offset |
|
106 | + * @return int |
|
107 | + */ |
|
108 | + public function adjustInvalidGmtOffsets($gmt_offset); |
|
109 | 109 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | private function setScheme($url) |
93 | 93 | { |
94 | - $this->scheme = $url['scheme'] . '://'; |
|
94 | + $this->scheme = $url['scheme'].'://'; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function queryString() |
147 | 147 | { |
148 | - return $this->query !== '' ? '?' . $this->query : ''; |
|
148 | + return $this->query !== '' ? '?'.$this->query : ''; |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function fragment() |
180 | 180 | { |
181 | - return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
181 | + return $this->fragment !== '' ? '#'.$this->fragment : ''; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function getFullUrl() |
201 | 201 | { |
202 | - return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
202 | + return $this->scheme().$this->host().$this->path().$this->queryString().$this->fragment(); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 |
@@ -17,199 +17,199 @@ |
||
17 | 17 | class Url |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $scheme |
|
22 | - */ |
|
23 | - private $scheme; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string $host |
|
27 | - */ |
|
28 | - private $host; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $path |
|
32 | - */ |
|
33 | - private $path; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string $query |
|
37 | - */ |
|
38 | - private $query; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string $fragment |
|
42 | - */ |
|
43 | - private $fragment; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Url constructor. |
|
48 | - * |
|
49 | - * @param $url |
|
50 | - * @throws InvalidArgumentException |
|
51 | - */ |
|
52 | - public function __construct($url) |
|
53 | - { |
|
54 | - if ( |
|
55 | - ! filter_var( |
|
56 | - $url, |
|
57 | - FILTER_VALIDATE_URL |
|
58 | - ) |
|
59 | - ) { |
|
60 | - throw new InvalidArgumentException( |
|
61 | - esc_html__( |
|
62 | - 'Invalid URL. Both the "Scheme" and "Host" are required.', |
|
63 | - 'event_espresso' |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
67 | - $url = parse_url($url); |
|
68 | - $this->setScheme($url); |
|
69 | - $this->setHost($url); |
|
70 | - $this->setPath($url); |
|
71 | - $this->setQuery($url); |
|
72 | - $this->setFragment($url); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
78 | - * will return a string like: 'abc://' |
|
79 | - * |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function scheme() |
|
83 | - { |
|
84 | - return $this->scheme; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @param array $url |
|
90 | - */ |
|
91 | - private function setScheme($url) |
|
92 | - { |
|
93 | - $this->scheme = $url['scheme'] . '://'; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
99 | - * will return a string like: 'example.com' |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function host() |
|
104 | - { |
|
105 | - return $this->host; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param array $url |
|
111 | - */ |
|
112 | - private function setHost($url) |
|
113 | - { |
|
114 | - $this->host = $url['host']; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
120 | - * will return a string like: '/path/data' |
|
121 | - * |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function path() |
|
125 | - { |
|
126 | - return $this->path; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @param array $url |
|
132 | - */ |
|
133 | - private function setPath($url) |
|
134 | - { |
|
135 | - $this->path = isset($url['path']) ? $url['path'] : ''; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
141 | - * will return a string like: '?key=value' |
|
142 | - * |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - public function queryString() |
|
146 | - { |
|
147 | - return $this->query !== '' ? '?' . $this->query : ''; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
153 | - * will return an array like: array('key' => 'value') |
|
154 | - * |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - public function queryParams() |
|
158 | - { |
|
159 | - return wp_parse_args($this->query); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param array $url |
|
165 | - */ |
|
166 | - private function setQuery($url) |
|
167 | - { |
|
168 | - $this->query = isset($url['query']) ? $url['query'] : ''; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
174 | - * will return a string like: '#id' |
|
175 | - * |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - public function fragment() |
|
179 | - { |
|
180 | - return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @param array $url |
|
186 | - */ |
|
187 | - private function setFragment($url) |
|
188 | - { |
|
189 | - $this->fragment = isset($url['fragment']) ? $url['fragment'] : ''; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
195 | - * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
196 | - * |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function getFullUrl() |
|
200 | - { |
|
201 | - return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
207 | - * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
208 | - * |
|
209 | - * @return string |
|
210 | - */ |
|
211 | - public function __toString() |
|
212 | - { |
|
213 | - return $this->getFullUrl(); |
|
214 | - } |
|
20 | + /** |
|
21 | + * @var string $scheme |
|
22 | + */ |
|
23 | + private $scheme; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string $host |
|
27 | + */ |
|
28 | + private $host; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $path |
|
32 | + */ |
|
33 | + private $path; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string $query |
|
37 | + */ |
|
38 | + private $query; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string $fragment |
|
42 | + */ |
|
43 | + private $fragment; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Url constructor. |
|
48 | + * |
|
49 | + * @param $url |
|
50 | + * @throws InvalidArgumentException |
|
51 | + */ |
|
52 | + public function __construct($url) |
|
53 | + { |
|
54 | + if ( |
|
55 | + ! filter_var( |
|
56 | + $url, |
|
57 | + FILTER_VALIDATE_URL |
|
58 | + ) |
|
59 | + ) { |
|
60 | + throw new InvalidArgumentException( |
|
61 | + esc_html__( |
|
62 | + 'Invalid URL. Both the "Scheme" and "Host" are required.', |
|
63 | + 'event_espresso' |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | + $url = parse_url($url); |
|
68 | + $this->setScheme($url); |
|
69 | + $this->setHost($url); |
|
70 | + $this->setPath($url); |
|
71 | + $this->setQuery($url); |
|
72 | + $this->setFragment($url); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
78 | + * will return a string like: 'abc://' |
|
79 | + * |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function scheme() |
|
83 | + { |
|
84 | + return $this->scheme; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @param array $url |
|
90 | + */ |
|
91 | + private function setScheme($url) |
|
92 | + { |
|
93 | + $this->scheme = $url['scheme'] . '://'; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
99 | + * will return a string like: 'example.com' |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function host() |
|
104 | + { |
|
105 | + return $this->host; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param array $url |
|
111 | + */ |
|
112 | + private function setHost($url) |
|
113 | + { |
|
114 | + $this->host = $url['host']; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
120 | + * will return a string like: '/path/data' |
|
121 | + * |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function path() |
|
125 | + { |
|
126 | + return $this->path; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @param array $url |
|
132 | + */ |
|
133 | + private function setPath($url) |
|
134 | + { |
|
135 | + $this->path = isset($url['path']) ? $url['path'] : ''; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
141 | + * will return a string like: '?key=value' |
|
142 | + * |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + public function queryString() |
|
146 | + { |
|
147 | + return $this->query !== '' ? '?' . $this->query : ''; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
153 | + * will return an array like: array('key' => 'value') |
|
154 | + * |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + public function queryParams() |
|
158 | + { |
|
159 | + return wp_parse_args($this->query); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param array $url |
|
165 | + */ |
|
166 | + private function setQuery($url) |
|
167 | + { |
|
168 | + $this->query = isset($url['query']) ? $url['query'] : ''; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
174 | + * will return a string like: '#id' |
|
175 | + * |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + public function fragment() |
|
179 | + { |
|
180 | + return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @param array $url |
|
186 | + */ |
|
187 | + private function setFragment($url) |
|
188 | + { |
|
189 | + $this->fragment = isset($url['fragment']) ? $url['fragment'] : ''; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
195 | + * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
196 | + * |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function getFullUrl() |
|
200 | + { |
|
201 | + return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
207 | + * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
208 | + * |
|
209 | + * @return string |
|
210 | + */ |
|
211 | + public function __toString() |
|
212 | + { |
|
213 | + return $this->getFullUrl(); |
|
214 | + } |
|
215 | 215 | } |