@@ -13,121 +13,121 @@ |
||
13 | 13 | class PostRelatedCacheManager extends BasicCacheManager |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @type string |
|
18 | - */ |
|
19 | - const POST_CACHE_PREFIX = 'ee_cache_post_'; |
|
20 | - |
|
21 | - /** |
|
22 | - * wp-option option_name for tracking post related cache |
|
23 | - * |
|
24 | - * @type string |
|
25 | - */ |
|
26 | - const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * PostRelatedCacheManager constructor. |
|
31 | - * |
|
32 | - * @param CacheStorageInterface $cache_storage |
|
33 | - */ |
|
34 | - public function __construct(CacheStorageInterface $cache_storage) |
|
35 | - { |
|
36 | - parent::__construct($cache_storage); |
|
37 | - add_action('save_post', array($this, 'clearPostRelatedCache')); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * returns a string that will be prepended to all cache identifiers |
|
43 | - * |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function cachePrefix() |
|
47 | - { |
|
48 | - return PostRelatedCacheManager::POST_CACHE_PREFIX; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - protected function getPostRelatedCache() |
|
56 | - { |
|
57 | - $post_related_cache = get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
58 | - // verify that cached data was not truncated or corrupted and no longer an array |
|
59 | - if (! is_array($post_related_cache)) { |
|
60 | - // uh-oh... let's get rid of any transients using our cache prefix |
|
61 | - $this->clear(PostRelatedCacheManager::CACHE_PREFIX); |
|
62 | - // then update the post related cache tracking option |
|
63 | - $post_related_cache = array(); |
|
64 | - $this->updatePostRelatedCache($post_related_cache); |
|
65 | - } |
|
66 | - return $post_related_cache; |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @param array $post_related_cache |
|
72 | - */ |
|
73 | - protected function updatePostRelatedCache(array $post_related_cache = array()) |
|
74 | - { |
|
75 | - update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * If you are caching content that pertains to a Post of any type, |
|
81 | - * then it is recommended to pass the post id and cache id prefix to this method |
|
82 | - * so that it can be added to the post related cache tracking. |
|
83 | - * Then, whenever that post is updated, the cache will automatically be deleted, |
|
84 | - * which helps to ensure that outdated cache content will not be served |
|
85 | - * |
|
86 | - * @param int $post_ID [required] |
|
87 | - * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
|
88 | - * May also be helpful to include an additional specific identifier, |
|
89 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
90 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
91 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
92 | - */ |
|
93 | - public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
|
94 | - { |
|
95 | - $post_related_cache = $this->getPostRelatedCache(); |
|
96 | - // if post is not already being tracked |
|
97 | - if (! isset($post_related_cache[$post_ID])) { |
|
98 | - // add array to add cache ids to |
|
99 | - $post_related_cache[$post_ID] = array(); |
|
100 | - } |
|
101 | - if (! in_array($id_prefix, $post_related_cache[$post_ID], true)) { |
|
102 | - // add cache id to be tracked |
|
103 | - $post_related_cache[$post_ID][] = $id_prefix; |
|
104 | - $this->updatePostRelatedCache($post_related_cache); |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * callback hooked into the WordPress "save_post" action |
|
111 | - * deletes any cache content associated with the post |
|
112 | - * |
|
113 | - * @param int $post_ID [required] |
|
114 | - */ |
|
115 | - public function clearPostRelatedCache($post_ID) |
|
116 | - { |
|
117 | - $post_related_cache = $this->getPostRelatedCache(); |
|
118 | - // if post is not being tracked |
|
119 | - if (! isset($post_related_cache[$post_ID])) { |
|
120 | - // let's clean up some of the duplicate IDs that were getting added |
|
121 | - foreach ($post_related_cache as $other_post_ID => $cache_IDs) { |
|
122 | - // remove duplicates |
|
123 | - $post_related_cache[$other_post_ID] = array_unique($post_related_cache[$other_post_ID]); |
|
124 | - } |
|
125 | - $this->updatePostRelatedCache($post_related_cache); |
|
126 | - return; |
|
127 | - } |
|
128 | - // get cache id prefixes for post, and delete their corresponding transients |
|
129 | - $this->clear($post_related_cache[$post_ID]); |
|
130 | - unset($post_related_cache[$post_ID]); |
|
131 | - $this->updatePostRelatedCache($post_related_cache); |
|
132 | - } |
|
16 | + /** |
|
17 | + * @type string |
|
18 | + */ |
|
19 | + const POST_CACHE_PREFIX = 'ee_cache_post_'; |
|
20 | + |
|
21 | + /** |
|
22 | + * wp-option option_name for tracking post related cache |
|
23 | + * |
|
24 | + * @type string |
|
25 | + */ |
|
26 | + const POST_CACHE_OPTIONS_KEY = 'ee_post_cache'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * PostRelatedCacheManager constructor. |
|
31 | + * |
|
32 | + * @param CacheStorageInterface $cache_storage |
|
33 | + */ |
|
34 | + public function __construct(CacheStorageInterface $cache_storage) |
|
35 | + { |
|
36 | + parent::__construct($cache_storage); |
|
37 | + add_action('save_post', array($this, 'clearPostRelatedCache')); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * returns a string that will be prepended to all cache identifiers |
|
43 | + * |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function cachePrefix() |
|
47 | + { |
|
48 | + return PostRelatedCacheManager::POST_CACHE_PREFIX; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + protected function getPostRelatedCache() |
|
56 | + { |
|
57 | + $post_related_cache = get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
|
58 | + // verify that cached data was not truncated or corrupted and no longer an array |
|
59 | + if (! is_array($post_related_cache)) { |
|
60 | + // uh-oh... let's get rid of any transients using our cache prefix |
|
61 | + $this->clear(PostRelatedCacheManager::CACHE_PREFIX); |
|
62 | + // then update the post related cache tracking option |
|
63 | + $post_related_cache = array(); |
|
64 | + $this->updatePostRelatedCache($post_related_cache); |
|
65 | + } |
|
66 | + return $post_related_cache; |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @param array $post_related_cache |
|
72 | + */ |
|
73 | + protected function updatePostRelatedCache(array $post_related_cache = array()) |
|
74 | + { |
|
75 | + update_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, $post_related_cache); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * If you are caching content that pertains to a Post of any type, |
|
81 | + * then it is recommended to pass the post id and cache id prefix to this method |
|
82 | + * so that it can be added to the post related cache tracking. |
|
83 | + * Then, whenever that post is updated, the cache will automatically be deleted, |
|
84 | + * which helps to ensure that outdated cache content will not be served |
|
85 | + * |
|
86 | + * @param int $post_ID [required] |
|
87 | + * @param string $id_prefix [required] Appended to all cache IDs. Can be helpful in finding specific cache types. |
|
88 | + * May also be helpful to include an additional specific identifier, |
|
89 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
90 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
91 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
92 | + */ |
|
93 | + public function clearPostRelatedCacheOnUpdate($post_ID, $id_prefix) |
|
94 | + { |
|
95 | + $post_related_cache = $this->getPostRelatedCache(); |
|
96 | + // if post is not already being tracked |
|
97 | + if (! isset($post_related_cache[$post_ID])) { |
|
98 | + // add array to add cache ids to |
|
99 | + $post_related_cache[$post_ID] = array(); |
|
100 | + } |
|
101 | + if (! in_array($id_prefix, $post_related_cache[$post_ID], true)) { |
|
102 | + // add cache id to be tracked |
|
103 | + $post_related_cache[$post_ID][] = $id_prefix; |
|
104 | + $this->updatePostRelatedCache($post_related_cache); |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * callback hooked into the WordPress "save_post" action |
|
111 | + * deletes any cache content associated with the post |
|
112 | + * |
|
113 | + * @param int $post_ID [required] |
|
114 | + */ |
|
115 | + public function clearPostRelatedCache($post_ID) |
|
116 | + { |
|
117 | + $post_related_cache = $this->getPostRelatedCache(); |
|
118 | + // if post is not being tracked |
|
119 | + if (! isset($post_related_cache[$post_ID])) { |
|
120 | + // let's clean up some of the duplicate IDs that were getting added |
|
121 | + foreach ($post_related_cache as $other_post_ID => $cache_IDs) { |
|
122 | + // remove duplicates |
|
123 | + $post_related_cache[$other_post_ID] = array_unique($post_related_cache[$other_post_ID]); |
|
124 | + } |
|
125 | + $this->updatePostRelatedCache($post_related_cache); |
|
126 | + return; |
|
127 | + } |
|
128 | + // get cache id prefixes for post, and delete their corresponding transients |
|
129 | + $this->clear($post_related_cache[$post_ID]); |
|
130 | + unset($post_related_cache[$post_ID]); |
|
131 | + $this->updatePostRelatedCache($post_related_cache); |
|
132 | + } |
|
133 | 133 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | { |
57 | 57 | $post_related_cache = get_option(PostRelatedCacheManager::POST_CACHE_OPTIONS_KEY, array()); |
58 | 58 | // verify that cached data was not truncated or corrupted and no longer an array |
59 | - if (! is_array($post_related_cache)) { |
|
59 | + if ( ! is_array($post_related_cache)) { |
|
60 | 60 | // uh-oh... let's get rid of any transients using our cache prefix |
61 | 61 | $this->clear(PostRelatedCacheManager::CACHE_PREFIX); |
62 | 62 | // then update the post related cache tracking option |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | { |
95 | 95 | $post_related_cache = $this->getPostRelatedCache(); |
96 | 96 | // if post is not already being tracked |
97 | - if (! isset($post_related_cache[$post_ID])) { |
|
97 | + if ( ! isset($post_related_cache[$post_ID])) { |
|
98 | 98 | // add array to add cache ids to |
99 | 99 | $post_related_cache[$post_ID] = array(); |
100 | 100 | } |
101 | - if (! in_array($id_prefix, $post_related_cache[$post_ID], true)) { |
|
101 | + if ( ! in_array($id_prefix, $post_related_cache[$post_ID], true)) { |
|
102 | 102 | // add cache id to be tracked |
103 | 103 | $post_related_cache[$post_ID][] = $id_prefix; |
104 | 104 | $this->updatePostRelatedCache($post_related_cache); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | { |
117 | 117 | $post_related_cache = $this->getPostRelatedCache(); |
118 | 118 | // if post is not being tracked |
119 | - if (! isset($post_related_cache[$post_ID])) { |
|
119 | + if ( ! isset($post_related_cache[$post_ID])) { |
|
120 | 120 | // let's clean up some of the duplicate IDs that were getting added |
121 | 121 | foreach ($post_related_cache as $other_post_ID => $cache_IDs) { |
122 | 122 | // remove duplicates |
@@ -30,375 +30,375 @@ |
||
30 | 30 | class PersistentAdminNoticeManager |
31 | 31 | { |
32 | 32 | |
33 | - const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var Collection|PersistentAdminNotice[] $notice_collection |
|
37 | - */ |
|
38 | - private $notice_collection; |
|
39 | - |
|
40 | - /** |
|
41 | - * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
42 | - * persistent admin notice was displayed, and ultimately dismissed from. |
|
43 | - * |
|
44 | - * @var string $return_url |
|
45 | - */ |
|
46 | - private $return_url; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var CapabilitiesChecker $capabilities_checker |
|
50 | - */ |
|
51 | - private $capabilities_checker; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var EE_Request $request |
|
55 | - */ |
|
56 | - private $request; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * PersistentAdminNoticeManager constructor |
|
61 | - * |
|
62 | - * @param string $return_url where to redirect to after dismissing notices |
|
63 | - * @param CapabilitiesChecker $capabilities_checker |
|
64 | - * @param EE_Request $request |
|
65 | - * @throws InvalidDataTypeException |
|
66 | - */ |
|
67 | - public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request) |
|
68 | - { |
|
69 | - $this->setReturnUrl($return_url); |
|
70 | - $this->capabilities_checker = $capabilities_checker; |
|
71 | - $this->request = $request; |
|
72 | - // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
73 | - // and we want to retrieve and generate any nag notices at the last possible moment |
|
74 | - add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
75 | - add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
76 | - add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
77 | - add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $return_url |
|
83 | - * @throws InvalidDataTypeException |
|
84 | - */ |
|
85 | - public function setReturnUrl($return_url) |
|
86 | - { |
|
87 | - if (! is_string($return_url)) { |
|
88 | - throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
89 | - } |
|
90 | - $this->return_url = $return_url; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return Collection |
|
96 | - * @throws InvalidEntityException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws DomainException |
|
100 | - */ |
|
101 | - protected function getPersistentAdminNoticeCollection() |
|
102 | - { |
|
103 | - if (! $this->notice_collection instanceof Collection) { |
|
104 | - $this->notice_collection = new Collection( |
|
105 | - 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
106 | - ); |
|
107 | - $this->retrieveStoredNotices(); |
|
108 | - $this->registerNotices(); |
|
109 | - } |
|
110 | - return $this->notice_collection; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
116 | - * |
|
117 | - * @return void |
|
118 | - * @throws InvalidEntityException |
|
119 | - * @throws DomainException |
|
120 | - * @throws InvalidDataTypeException |
|
121 | - */ |
|
122 | - protected function retrieveStoredNotices() |
|
123 | - { |
|
124 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
125 | - // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
|
126 | - if (! empty($persistent_admin_notices)) { |
|
127 | - foreach ($persistent_admin_notices as $name => $details) { |
|
128 | - if (is_array($details)) { |
|
129 | - if (! isset( |
|
130 | - $details['message'], |
|
131 | - $details['capability'], |
|
132 | - $details['cap_context'], |
|
133 | - $details['dismissed'] |
|
134 | - )) { |
|
135 | - throw new DomainException( |
|
136 | - sprintf( |
|
137 | - esc_html__( |
|
138 | - 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
139 | - 'event_espresso' |
|
140 | - ), |
|
141 | - $name |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - // new format for nag notices |
|
146 | - $this->notice_collection->add( |
|
147 | - new PersistentAdminNotice( |
|
148 | - $name, |
|
149 | - $details['message'], |
|
150 | - false, |
|
151 | - $details['capability'], |
|
152 | - $details['cap_context'], |
|
153 | - $details['dismissed'] |
|
154 | - ), |
|
155 | - $name |
|
156 | - ); |
|
157 | - } else { |
|
158 | - try { |
|
159 | - // old nag notices, that we want to convert to the new format |
|
160 | - $this->notice_collection->add( |
|
161 | - new PersistentAdminNotice( |
|
162 | - $name, |
|
163 | - (string)$details, |
|
164 | - false, |
|
165 | - '', |
|
166 | - '', |
|
167 | - empty($details) |
|
168 | - ), |
|
169 | - $name |
|
170 | - ); |
|
171 | - } catch (Exception $e) { |
|
172 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
173 | - } |
|
174 | - } |
|
175 | - // each notice will self register when the action hook in registerNotices is triggered |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * exposes the Persistent Admin Notice Collection via an action |
|
183 | - * so that PersistentAdminNotice objects can be added and/or removed |
|
184 | - * without compromising the actual collection like a filter would |
|
185 | - */ |
|
186 | - protected function registerNotices() |
|
187 | - { |
|
188 | - do_action( |
|
189 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
190 | - $this->notice_collection |
|
191 | - ); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @throws DomainException |
|
197 | - * @throws InvalidClassException |
|
198 | - * @throws InvalidDataTypeException |
|
199 | - * @throws InvalidInterfaceException |
|
200 | - * @throws InvalidEntityException |
|
201 | - */ |
|
202 | - public function displayNotices() |
|
203 | - { |
|
204 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
205 | - if ($this->notice_collection->hasObjects()) { |
|
206 | - $enqueue_assets = false; |
|
207 | - // and display notices |
|
208 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
209 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
210 | - // don't display notices that have already been dismissed |
|
211 | - if ($persistent_admin_notice->getDismissed()) { |
|
212 | - continue; |
|
213 | - } |
|
214 | - try { |
|
215 | - $this->capabilities_checker->processCapCheck( |
|
216 | - $persistent_admin_notice->getCapCheck() |
|
217 | - ); |
|
218 | - } catch (InsufficientPermissionsException $e) { |
|
219 | - // user does not have required cap, so skip to next notice |
|
220 | - // and just eat the exception - nom nom nom nom |
|
221 | - continue; |
|
222 | - } |
|
223 | - if ($persistent_admin_notice->getMessage() === '') { |
|
224 | - continue; |
|
225 | - } |
|
226 | - $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
227 | - $enqueue_assets = true; |
|
228 | - } |
|
229 | - if ($enqueue_assets) { |
|
230 | - $this->enqueueAssets(); |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * does what it's named |
|
238 | - * |
|
239 | - * @return void |
|
240 | - */ |
|
241 | - public function enqueueAssets() |
|
242 | - { |
|
243 | - wp_register_script( |
|
244 | - 'espresso_core', |
|
245 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
246 | - array('jquery'), |
|
247 | - EVENT_ESPRESSO_VERSION, |
|
248 | - true |
|
249 | - ); |
|
250 | - wp_register_script( |
|
251 | - 'ee_error_js', |
|
252 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
253 | - array('espresso_core'), |
|
254 | - EVENT_ESPRESSO_VERSION, |
|
255 | - true |
|
256 | - ); |
|
257 | - wp_localize_script( |
|
258 | - 'ee_error_js', |
|
259 | - 'ee_dismiss', |
|
260 | - array( |
|
261 | - 'return_url' => urlencode($this->return_url), |
|
262 | - 'ajax_url' => WP_AJAX_URL, |
|
263 | - 'unknown_error' => esc_html__( |
|
264 | - 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
265 | - 'event_espresso' |
|
266 | - ), |
|
267 | - ) |
|
268 | - ); |
|
269 | - wp_enqueue_script('ee_error_js'); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * displayPersistentAdminNoticeHtml |
|
275 | - * |
|
276 | - * @param PersistentAdminNotice $persistent_admin_notice |
|
277 | - */ |
|
278 | - protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
279 | - { |
|
280 | - // used in template |
|
281 | - $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
282 | - $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
283 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * dismissNotice |
|
289 | - * |
|
290 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
291 | - * @param bool $purge if true, then delete it from the db |
|
292 | - * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
293 | - * @return void |
|
294 | - * @throws InvalidEntityException |
|
295 | - * @throws InvalidInterfaceException |
|
296 | - * @throws InvalidDataTypeException |
|
297 | - * @throws DomainException |
|
298 | - */ |
|
299 | - public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
300 | - { |
|
301 | - $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
|
302 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
303 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
304 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
305 | - $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
306 | - $persistent_admin_notice->setDismissed(true); |
|
307 | - $persistent_admin_notice->setPurge($purge); |
|
308 | - $this->saveNotices(); |
|
309 | - } |
|
310 | - if ($return) { |
|
311 | - return; |
|
312 | - } |
|
313 | - if ($this->request->ajax) { |
|
314 | - // grab any notices and concatenate into string |
|
315 | - echo wp_json_encode( |
|
316 | - array( |
|
317 | - 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
318 | - ) |
|
319 | - ); |
|
320 | - exit(); |
|
321 | - } |
|
322 | - // save errors to a transient to be displayed on next request (after redirect) |
|
323 | - EE_Error::get_notices(false, true); |
|
324 | - wp_safe_redirect( |
|
325 | - urldecode( |
|
326 | - $this->request->get('return_url', '') |
|
327 | - ) |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * saveNotices |
|
334 | - * |
|
335 | - * @throws DomainException |
|
336 | - * @throws InvalidDataTypeException |
|
337 | - * @throws InvalidInterfaceException |
|
338 | - * @throws InvalidEntityException |
|
339 | - */ |
|
340 | - public function saveNotices() |
|
341 | - { |
|
342 | - $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
343 | - if ($this->notice_collection->hasObjects()) { |
|
344 | - $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
345 | - // maybe initialize persistent_admin_notices |
|
346 | - if (empty($persistent_admin_notices)) { |
|
347 | - add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
348 | - } |
|
349 | - foreach ($this->notice_collection as $persistent_admin_notice) { |
|
350 | - // are we deleting this notice ? |
|
351 | - if ($persistent_admin_notice->getPurge()) { |
|
352 | - unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
353 | - } else { |
|
354 | - /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
355 | - $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
356 | - 'message' => $persistent_admin_notice->getMessage(), |
|
357 | - 'capability' => $persistent_admin_notice->getCapability(), |
|
358 | - 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
359 | - 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
360 | - ); |
|
361 | - } |
|
362 | - } |
|
363 | - update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
364 | - } |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @throws DomainException |
|
370 | - * @throws InvalidDataTypeException |
|
371 | - * @throws InvalidEntityException |
|
372 | - * @throws InvalidInterfaceException |
|
373 | - */ |
|
374 | - public function registerAndSaveNotices() |
|
375 | - { |
|
376 | - $this->getPersistentAdminNoticeCollection(); |
|
377 | - $this->registerNotices(); |
|
378 | - $this->saveNotices(); |
|
379 | - add_filter( |
|
380 | - 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
381 | - '__return_true' |
|
382 | - ); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * @throws DomainException |
|
388 | - * @throws InvalidDataTypeException |
|
389 | - * @throws InvalidEntityException |
|
390 | - * @throws InvalidInterfaceException |
|
391 | - * @throws InvalidArgumentException |
|
392 | - */ |
|
393 | - public static function loadRegisterAndSaveNotices() |
|
394 | - { |
|
395 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
396 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
397 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
398 | - ); |
|
399 | - // if shutdown has already run, then call registerAndSaveNotices() manually |
|
400 | - if (did_action('shutdown')) { |
|
401 | - $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
402 | - } |
|
403 | - } |
|
33 | + const WP_OPTION_KEY = 'ee_pers_admin_notices'; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var Collection|PersistentAdminNotice[] $notice_collection |
|
37 | + */ |
|
38 | + private $notice_collection; |
|
39 | + |
|
40 | + /** |
|
41 | + * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the |
|
42 | + * persistent admin notice was displayed, and ultimately dismissed from. |
|
43 | + * |
|
44 | + * @var string $return_url |
|
45 | + */ |
|
46 | + private $return_url; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var CapabilitiesChecker $capabilities_checker |
|
50 | + */ |
|
51 | + private $capabilities_checker; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var EE_Request $request |
|
55 | + */ |
|
56 | + private $request; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * PersistentAdminNoticeManager constructor |
|
61 | + * |
|
62 | + * @param string $return_url where to redirect to after dismissing notices |
|
63 | + * @param CapabilitiesChecker $capabilities_checker |
|
64 | + * @param EE_Request $request |
|
65 | + * @throws InvalidDataTypeException |
|
66 | + */ |
|
67 | + public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, EE_Request $request) |
|
68 | + { |
|
69 | + $this->setReturnUrl($return_url); |
|
70 | + $this->capabilities_checker = $capabilities_checker; |
|
71 | + $this->request = $request; |
|
72 | + // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10, |
|
73 | + // and we want to retrieve and generate any nag notices at the last possible moment |
|
74 | + add_action('admin_notices', array($this, 'displayNotices'), 9); |
|
75 | + add_action('network_admin_notices', array($this, 'displayNotices'), 9); |
|
76 | + add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice')); |
|
77 | + add_action('shutdown', array($this, 'registerAndSaveNotices'), 998); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $return_url |
|
83 | + * @throws InvalidDataTypeException |
|
84 | + */ |
|
85 | + public function setReturnUrl($return_url) |
|
86 | + { |
|
87 | + if (! is_string($return_url)) { |
|
88 | + throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
|
89 | + } |
|
90 | + $this->return_url = $return_url; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return Collection |
|
96 | + * @throws InvalidEntityException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws DomainException |
|
100 | + */ |
|
101 | + protected function getPersistentAdminNoticeCollection() |
|
102 | + { |
|
103 | + if (! $this->notice_collection instanceof Collection) { |
|
104 | + $this->notice_collection = new Collection( |
|
105 | + 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
106 | + ); |
|
107 | + $this->retrieveStoredNotices(); |
|
108 | + $this->registerNotices(); |
|
109 | + } |
|
110 | + return $this->notice_collection; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db |
|
116 | + * |
|
117 | + * @return void |
|
118 | + * @throws InvalidEntityException |
|
119 | + * @throws DomainException |
|
120 | + * @throws InvalidDataTypeException |
|
121 | + */ |
|
122 | + protected function retrieveStoredNotices() |
|
123 | + { |
|
124 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
125 | + // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
|
126 | + if (! empty($persistent_admin_notices)) { |
|
127 | + foreach ($persistent_admin_notices as $name => $details) { |
|
128 | + if (is_array($details)) { |
|
129 | + if (! isset( |
|
130 | + $details['message'], |
|
131 | + $details['capability'], |
|
132 | + $details['cap_context'], |
|
133 | + $details['dismissed'] |
|
134 | + )) { |
|
135 | + throw new DomainException( |
|
136 | + sprintf( |
|
137 | + esc_html__( |
|
138 | + 'The "%1$s" PersistentAdminNotice could not be retrieved from the database.', |
|
139 | + 'event_espresso' |
|
140 | + ), |
|
141 | + $name |
|
142 | + ) |
|
143 | + ); |
|
144 | + } |
|
145 | + // new format for nag notices |
|
146 | + $this->notice_collection->add( |
|
147 | + new PersistentAdminNotice( |
|
148 | + $name, |
|
149 | + $details['message'], |
|
150 | + false, |
|
151 | + $details['capability'], |
|
152 | + $details['cap_context'], |
|
153 | + $details['dismissed'] |
|
154 | + ), |
|
155 | + $name |
|
156 | + ); |
|
157 | + } else { |
|
158 | + try { |
|
159 | + // old nag notices, that we want to convert to the new format |
|
160 | + $this->notice_collection->add( |
|
161 | + new PersistentAdminNotice( |
|
162 | + $name, |
|
163 | + (string)$details, |
|
164 | + false, |
|
165 | + '', |
|
166 | + '', |
|
167 | + empty($details) |
|
168 | + ), |
|
169 | + $name |
|
170 | + ); |
|
171 | + } catch (Exception $e) { |
|
172 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
173 | + } |
|
174 | + } |
|
175 | + // each notice will self register when the action hook in registerNotices is triggered |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * exposes the Persistent Admin Notice Collection via an action |
|
183 | + * so that PersistentAdminNotice objects can be added and/or removed |
|
184 | + * without compromising the actual collection like a filter would |
|
185 | + */ |
|
186 | + protected function registerNotices() |
|
187 | + { |
|
188 | + do_action( |
|
189 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
190 | + $this->notice_collection |
|
191 | + ); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @throws DomainException |
|
197 | + * @throws InvalidClassException |
|
198 | + * @throws InvalidDataTypeException |
|
199 | + * @throws InvalidInterfaceException |
|
200 | + * @throws InvalidEntityException |
|
201 | + */ |
|
202 | + public function displayNotices() |
|
203 | + { |
|
204 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
205 | + if ($this->notice_collection->hasObjects()) { |
|
206 | + $enqueue_assets = false; |
|
207 | + // and display notices |
|
208 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
209 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
210 | + // don't display notices that have already been dismissed |
|
211 | + if ($persistent_admin_notice->getDismissed()) { |
|
212 | + continue; |
|
213 | + } |
|
214 | + try { |
|
215 | + $this->capabilities_checker->processCapCheck( |
|
216 | + $persistent_admin_notice->getCapCheck() |
|
217 | + ); |
|
218 | + } catch (InsufficientPermissionsException $e) { |
|
219 | + // user does not have required cap, so skip to next notice |
|
220 | + // and just eat the exception - nom nom nom nom |
|
221 | + continue; |
|
222 | + } |
|
223 | + if ($persistent_admin_notice->getMessage() === '') { |
|
224 | + continue; |
|
225 | + } |
|
226 | + $this->displayPersistentAdminNotice($persistent_admin_notice); |
|
227 | + $enqueue_assets = true; |
|
228 | + } |
|
229 | + if ($enqueue_assets) { |
|
230 | + $this->enqueueAssets(); |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * does what it's named |
|
238 | + * |
|
239 | + * @return void |
|
240 | + */ |
|
241 | + public function enqueueAssets() |
|
242 | + { |
|
243 | + wp_register_script( |
|
244 | + 'espresso_core', |
|
245 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
246 | + array('jquery'), |
|
247 | + EVENT_ESPRESSO_VERSION, |
|
248 | + true |
|
249 | + ); |
|
250 | + wp_register_script( |
|
251 | + 'ee_error_js', |
|
252 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
253 | + array('espresso_core'), |
|
254 | + EVENT_ESPRESSO_VERSION, |
|
255 | + true |
|
256 | + ); |
|
257 | + wp_localize_script( |
|
258 | + 'ee_error_js', |
|
259 | + 'ee_dismiss', |
|
260 | + array( |
|
261 | + 'return_url' => urlencode($this->return_url), |
|
262 | + 'ajax_url' => WP_AJAX_URL, |
|
263 | + 'unknown_error' => esc_html__( |
|
264 | + 'An unknown error has occurred on the server while attempting to dismiss this notice.', |
|
265 | + 'event_espresso' |
|
266 | + ), |
|
267 | + ) |
|
268 | + ); |
|
269 | + wp_enqueue_script('ee_error_js'); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * displayPersistentAdminNoticeHtml |
|
275 | + * |
|
276 | + * @param PersistentAdminNotice $persistent_admin_notice |
|
277 | + */ |
|
278 | + protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice) |
|
279 | + { |
|
280 | + // used in template |
|
281 | + $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
|
282 | + $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
|
283 | + require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * dismissNotice |
|
289 | + * |
|
290 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
291 | + * @param bool $purge if true, then delete it from the db |
|
292 | + * @param bool $return forget all of this AJAX or redirect nonsense, and just return |
|
293 | + * @return void |
|
294 | + * @throws InvalidEntityException |
|
295 | + * @throws InvalidInterfaceException |
|
296 | + * @throws InvalidDataTypeException |
|
297 | + * @throws DomainException |
|
298 | + */ |
|
299 | + public function dismissNotice($pan_name = '', $purge = false, $return = false) |
|
300 | + { |
|
301 | + $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
|
302 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
303 | + if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
304 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
305 | + $persistent_admin_notice = $this->notice_collection->get($pan_name); |
|
306 | + $persistent_admin_notice->setDismissed(true); |
|
307 | + $persistent_admin_notice->setPurge($purge); |
|
308 | + $this->saveNotices(); |
|
309 | + } |
|
310 | + if ($return) { |
|
311 | + return; |
|
312 | + } |
|
313 | + if ($this->request->ajax) { |
|
314 | + // grab any notices and concatenate into string |
|
315 | + echo wp_json_encode( |
|
316 | + array( |
|
317 | + 'errors' => implode('<br />', EE_Error::get_notices(false)), |
|
318 | + ) |
|
319 | + ); |
|
320 | + exit(); |
|
321 | + } |
|
322 | + // save errors to a transient to be displayed on next request (after redirect) |
|
323 | + EE_Error::get_notices(false, true); |
|
324 | + wp_safe_redirect( |
|
325 | + urldecode( |
|
326 | + $this->request->get('return_url', '') |
|
327 | + ) |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * saveNotices |
|
334 | + * |
|
335 | + * @throws DomainException |
|
336 | + * @throws InvalidDataTypeException |
|
337 | + * @throws InvalidInterfaceException |
|
338 | + * @throws InvalidEntityException |
|
339 | + */ |
|
340 | + public function saveNotices() |
|
341 | + { |
|
342 | + $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
|
343 | + if ($this->notice_collection->hasObjects()) { |
|
344 | + $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
|
345 | + // maybe initialize persistent_admin_notices |
|
346 | + if (empty($persistent_admin_notices)) { |
|
347 | + add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no'); |
|
348 | + } |
|
349 | + foreach ($this->notice_collection as $persistent_admin_notice) { |
|
350 | + // are we deleting this notice ? |
|
351 | + if ($persistent_admin_notice->getPurge()) { |
|
352 | + unset($persistent_admin_notices[$persistent_admin_notice->getName()]); |
|
353 | + } else { |
|
354 | + /** @var PersistentAdminNotice $persistent_admin_notice */ |
|
355 | + $persistent_admin_notices[$persistent_admin_notice->getName()] = array( |
|
356 | + 'message' => $persistent_admin_notice->getMessage(), |
|
357 | + 'capability' => $persistent_admin_notice->getCapability(), |
|
358 | + 'cap_context' => $persistent_admin_notice->getCapContext(), |
|
359 | + 'dismissed' => $persistent_admin_notice->getDismissed(), |
|
360 | + ); |
|
361 | + } |
|
362 | + } |
|
363 | + update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices); |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @throws DomainException |
|
370 | + * @throws InvalidDataTypeException |
|
371 | + * @throws InvalidEntityException |
|
372 | + * @throws InvalidInterfaceException |
|
373 | + */ |
|
374 | + public function registerAndSaveNotices() |
|
375 | + { |
|
376 | + $this->getPersistentAdminNoticeCollection(); |
|
377 | + $this->registerNotices(); |
|
378 | + $this->saveNotices(); |
|
379 | + add_filter( |
|
380 | + 'PersistentAdminNoticeManager__registerAndSaveNotices__complete', |
|
381 | + '__return_true' |
|
382 | + ); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * @throws DomainException |
|
388 | + * @throws InvalidDataTypeException |
|
389 | + * @throws InvalidEntityException |
|
390 | + * @throws InvalidInterfaceException |
|
391 | + * @throws InvalidArgumentException |
|
392 | + */ |
|
393 | + public static function loadRegisterAndSaveNotices() |
|
394 | + { |
|
395 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
396 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
397 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
398 | + ); |
|
399 | + // if shutdown has already run, then call registerAndSaveNotices() manually |
|
400 | + if (did_action('shutdown')) { |
|
401 | + $persistent_admin_notice_manager->registerAndSaveNotices(); |
|
402 | + } |
|
403 | + } |
|
404 | 404 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function setReturnUrl($return_url) |
86 | 86 | { |
87 | - if (! is_string($return_url)) { |
|
87 | + if ( ! is_string($return_url)) { |
|
88 | 88 | throw new InvalidDataTypeException('$return_url', $return_url, 'string'); |
89 | 89 | } |
90 | 90 | $this->return_url = $return_url; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function getPersistentAdminNoticeCollection() |
102 | 102 | { |
103 | - if (! $this->notice_collection instanceof Collection) { |
|
103 | + if ( ! $this->notice_collection instanceof Collection) { |
|
104 | 104 | $this->notice_collection = new Collection( |
105 | 105 | 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
106 | 106 | ); |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | { |
124 | 124 | $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array()); |
125 | 125 | // \EEH_Debug_Tools::printr($persistent_admin_notices, '$persistent_admin_notices', __FILE__, __LINE__); |
126 | - if (! empty($persistent_admin_notices)) { |
|
126 | + if ( ! empty($persistent_admin_notices)) { |
|
127 | 127 | foreach ($persistent_admin_notices as $name => $details) { |
128 | 128 | if (is_array($details)) { |
129 | - if (! isset( |
|
129 | + if ( ! isset( |
|
130 | 130 | $details['message'], |
131 | 131 | $details['capability'], |
132 | 132 | $details['cap_context'], |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | $this->notice_collection->add( |
161 | 161 | new PersistentAdminNotice( |
162 | 162 | $name, |
163 | - (string)$details, |
|
163 | + (string) $details, |
|
164 | 164 | false, |
165 | 165 | '', |
166 | 166 | '', |
@@ -242,14 +242,14 @@ discard block |
||
242 | 242 | { |
243 | 243 | wp_register_script( |
244 | 244 | 'espresso_core', |
245 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
245 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
246 | 246 | array('jquery'), |
247 | 247 | EVENT_ESPRESSO_VERSION, |
248 | 248 | true |
249 | 249 | ); |
250 | 250 | wp_register_script( |
251 | 251 | 'ee_error_js', |
252 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
252 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
253 | 253 | array('espresso_core'), |
254 | 254 | EVENT_ESPRESSO_VERSION, |
255 | 255 | true |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | // used in template |
281 | 281 | $persistent_admin_notice_name = $persistent_admin_notice->getName(); |
282 | 282 | $persistent_admin_notice_message = $persistent_admin_notice->getMessage(); |
283 | - require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php'; |
|
283 | + require EE_TEMPLATES.DS.'notifications'.DS.'persistent_admin_notice.template.php'; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | { |
301 | 301 | $pan_name = $this->request->get('ee_nag_notice', $pan_name); |
302 | 302 | $this->notice_collection = $this->getPersistentAdminNoticeCollection(); |
303 | - if (! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
303 | + if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)) { |
|
304 | 304 | /** @var PersistentAdminNotice $persistent_admin_notice */ |
305 | 305 | $persistent_admin_notice = $this->notice_collection->get($pan_name); |
306 | 306 | $persistent_admin_notice->setDismissed(true); |
@@ -14,42 +14,42 @@ |
||
14 | 14 | class ConvertNoticesToAdminNotices extends NoticeConverter |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Converts Notice objects into AdminNotice notifications |
|
19 | - * |
|
20 | - * @param NoticesContainerInterface $notices |
|
21 | - * @throws DomainException |
|
22 | - */ |
|
23 | - public function process(NoticesContainerInterface $notices) |
|
24 | - { |
|
25 | - if ($notices->hasAttention()) { |
|
26 | - foreach ($notices->getAttention() as $notice) { |
|
27 | - new AdminNotice($notice); |
|
28 | - } |
|
29 | - } |
|
30 | - if ($notices->hasError()) { |
|
31 | - $error_string = esc_html__('The following errors occurred:', 'event_espresso'); |
|
32 | - foreach ($notices->getError() as $notice) { |
|
33 | - if ($this->getThrowExceptions()) { |
|
34 | - $error_string .= '<br />' . $notice->message(); |
|
35 | - } else { |
|
36 | - new AdminNotice($notice); |
|
37 | - } |
|
38 | - } |
|
39 | - if ($this->getThrowExceptions()) { |
|
40 | - throw new DomainException($error_string); |
|
41 | - } |
|
42 | - } |
|
43 | - if ($notices->hasSuccess()) { |
|
44 | - foreach ($notices->getSuccess() as $notice) { |
|
45 | - new AdminNotice($notice); |
|
46 | - } |
|
47 | - } |
|
48 | - if ($notices->hasInformation()) { |
|
49 | - foreach ($notices->getInformation() as $notice) { |
|
50 | - new AdminNotice($notice); |
|
51 | - } |
|
52 | - } |
|
53 | - $this->clearNotices(); |
|
54 | - } |
|
17 | + /** |
|
18 | + * Converts Notice objects into AdminNotice notifications |
|
19 | + * |
|
20 | + * @param NoticesContainerInterface $notices |
|
21 | + * @throws DomainException |
|
22 | + */ |
|
23 | + public function process(NoticesContainerInterface $notices) |
|
24 | + { |
|
25 | + if ($notices->hasAttention()) { |
|
26 | + foreach ($notices->getAttention() as $notice) { |
|
27 | + new AdminNotice($notice); |
|
28 | + } |
|
29 | + } |
|
30 | + if ($notices->hasError()) { |
|
31 | + $error_string = esc_html__('The following errors occurred:', 'event_espresso'); |
|
32 | + foreach ($notices->getError() as $notice) { |
|
33 | + if ($this->getThrowExceptions()) { |
|
34 | + $error_string .= '<br />' . $notice->message(); |
|
35 | + } else { |
|
36 | + new AdminNotice($notice); |
|
37 | + } |
|
38 | + } |
|
39 | + if ($this->getThrowExceptions()) { |
|
40 | + throw new DomainException($error_string); |
|
41 | + } |
|
42 | + } |
|
43 | + if ($notices->hasSuccess()) { |
|
44 | + foreach ($notices->getSuccess() as $notice) { |
|
45 | + new AdminNotice($notice); |
|
46 | + } |
|
47 | + } |
|
48 | + if ($notices->hasInformation()) { |
|
49 | + foreach ($notices->getInformation() as $notice) { |
|
50 | + new AdminNotice($notice); |
|
51 | + } |
|
52 | + } |
|
53 | + $this->clearNotices(); |
|
54 | + } |
|
55 | 55 | } |
@@ -14,253 +14,253 @@ |
||
14 | 14 | class Notice implements NoticeInterface |
15 | 15 | { |
16 | 16 | |
17 | - const ERROR = 'error'; |
|
18 | - |
|
19 | - const SUCCESS = 'success'; |
|
20 | - |
|
21 | - const ATTENTION = 'attention'; // alias for warning |
|
22 | - |
|
23 | - const INFORMATION = 'information'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string $type |
|
27 | - */ |
|
28 | - private $type; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string $message |
|
33 | - */ |
|
34 | - private $message; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string $file |
|
39 | - */ |
|
40 | - private $file; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string $func |
|
45 | - */ |
|
46 | - private $func; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string $line |
|
51 | - */ |
|
52 | - private $line; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @var boolean $dismissible |
|
57 | - */ |
|
58 | - private $dismissible; |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * Notice constructor. |
|
63 | - * |
|
64 | - * @param string $type |
|
65 | - * @param string $message |
|
66 | - * @param bool $dismissible |
|
67 | - * @param string $file |
|
68 | - * @param string $func |
|
69 | - * @param string $line |
|
70 | - * @throws InvalidDataTypeException |
|
71 | - */ |
|
72 | - public function __construct($type, $message, $dismissible = true, $file = '', $func = '', $line = '') |
|
73 | - { |
|
74 | - $this->setType($type); |
|
75 | - $this->setMessage($message); |
|
76 | - $this->setDismissible($dismissible); |
|
77 | - $this->setFile($file); |
|
78 | - $this->setFunc($func); |
|
79 | - $this->setLine($line); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - private function types() |
|
87 | - { |
|
88 | - return (array)apply_filters( |
|
89 | - 'FHEE__EventEspresso_core_services_notices_Notice__types', |
|
90 | - array( |
|
91 | - Notice::ERROR, |
|
92 | - Notice::SUCCESS, |
|
93 | - Notice::ATTENTION, |
|
94 | - Notice::INFORMATION, |
|
95 | - ) |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function type() |
|
104 | - { |
|
105 | - return $this->type; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function message() |
|
113 | - { |
|
114 | - return $this->message; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public function file() |
|
122 | - { |
|
123 | - return $this->file; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - public function func() |
|
131 | - { |
|
132 | - return $this->func; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - public function line() |
|
140 | - { |
|
141 | - return $this->line; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - public function isDismissible() |
|
149 | - { |
|
150 | - return $this->dismissible; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param string $type |
|
156 | - * @throws InvalidDataTypeException |
|
157 | - */ |
|
158 | - private function setType($type) |
|
159 | - { |
|
160 | - if (! in_array($type, $this->types(), true)) { |
|
161 | - throw new InvalidDataTypeException( |
|
162 | - '$type', |
|
163 | - $type, |
|
164 | - $this->invalidTypeMessage() |
|
165 | - ); |
|
166 | - } |
|
167 | - $this->type = $type; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * gets the $invalid_type_message string |
|
173 | - */ |
|
174 | - private function invalidTypeMessage() |
|
175 | - { |
|
176 | - return apply_filters( |
|
177 | - 'FHEE__EventEspresso_core_services_notices_Notice__invalidTypeMessage', |
|
178 | - sprintf( |
|
179 | - esc_html__( |
|
180 | - ' one of the following notice types was expected: %1$s %2$s', |
|
181 | - 'event_espresso' |
|
182 | - ), |
|
183 | - '<br />', |
|
184 | - var_export($this->types(), true) |
|
185 | - ) |
|
186 | - ); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $message |
|
192 | - * @throws InvalidDataTypeException |
|
193 | - */ |
|
194 | - private function setMessage($message) |
|
195 | - { |
|
196 | - if (empty($message) || ! is_string($message)) { |
|
197 | - throw new InvalidDataTypeException( |
|
198 | - '$message', |
|
199 | - $message, |
|
200 | - esc_html__('non empty string', 'event_espresso') |
|
201 | - ); |
|
202 | - } |
|
203 | - $this->message = $message; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * @param string $file |
|
209 | - * @throws InvalidDataTypeException |
|
210 | - */ |
|
211 | - private function setFile($file) |
|
212 | - { |
|
213 | - if ($this->type === Notice::ERROR && (empty($file) || ! is_string($file))) { |
|
214 | - throw new InvalidDataTypeException( |
|
215 | - '$file', |
|
216 | - $file, |
|
217 | - esc_html__('non empty string', 'event_espresso') |
|
218 | - ); |
|
219 | - } |
|
220 | - $this->file = $file; |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * @param string $func |
|
226 | - * @throws InvalidDataTypeException |
|
227 | - */ |
|
228 | - private function setFunc($func) |
|
229 | - { |
|
230 | - if ($this->type === Notice::ERROR && (empty($func) || ! is_string($func))) { |
|
231 | - throw new InvalidDataTypeException( |
|
232 | - '$func', |
|
233 | - $func, |
|
234 | - esc_html__('non empty string', 'event_espresso') |
|
235 | - ); |
|
236 | - } |
|
237 | - $this->func = $func; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @param int $line |
|
243 | - * @throws InvalidDataTypeException |
|
244 | - */ |
|
245 | - private function setLine($line) |
|
246 | - { |
|
247 | - $line = absint($line); |
|
248 | - if ($this->type === Notice::ERROR && $line === 0) { |
|
249 | - throw new InvalidDataTypeException( |
|
250 | - '$line', |
|
251 | - $line, |
|
252 | - esc_html__('integer', 'event_espresso') |
|
253 | - ); |
|
254 | - } |
|
255 | - $this->line = $line; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * @param boolean $dismissible |
|
261 | - */ |
|
262 | - private function setDismissible($dismissible = true) |
|
263 | - { |
|
264 | - $this->dismissible = filter_var($dismissible, FILTER_VALIDATE_BOOLEAN); |
|
265 | - } |
|
17 | + const ERROR = 'error'; |
|
18 | + |
|
19 | + const SUCCESS = 'success'; |
|
20 | + |
|
21 | + const ATTENTION = 'attention'; // alias for warning |
|
22 | + |
|
23 | + const INFORMATION = 'information'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string $type |
|
27 | + */ |
|
28 | + private $type; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string $message |
|
33 | + */ |
|
34 | + private $message; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string $file |
|
39 | + */ |
|
40 | + private $file; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string $func |
|
45 | + */ |
|
46 | + private $func; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string $line |
|
51 | + */ |
|
52 | + private $line; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @var boolean $dismissible |
|
57 | + */ |
|
58 | + private $dismissible; |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * Notice constructor. |
|
63 | + * |
|
64 | + * @param string $type |
|
65 | + * @param string $message |
|
66 | + * @param bool $dismissible |
|
67 | + * @param string $file |
|
68 | + * @param string $func |
|
69 | + * @param string $line |
|
70 | + * @throws InvalidDataTypeException |
|
71 | + */ |
|
72 | + public function __construct($type, $message, $dismissible = true, $file = '', $func = '', $line = '') |
|
73 | + { |
|
74 | + $this->setType($type); |
|
75 | + $this->setMessage($message); |
|
76 | + $this->setDismissible($dismissible); |
|
77 | + $this->setFile($file); |
|
78 | + $this->setFunc($func); |
|
79 | + $this->setLine($line); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + private function types() |
|
87 | + { |
|
88 | + return (array)apply_filters( |
|
89 | + 'FHEE__EventEspresso_core_services_notices_Notice__types', |
|
90 | + array( |
|
91 | + Notice::ERROR, |
|
92 | + Notice::SUCCESS, |
|
93 | + Notice::ATTENTION, |
|
94 | + Notice::INFORMATION, |
|
95 | + ) |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function type() |
|
104 | + { |
|
105 | + return $this->type; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function message() |
|
113 | + { |
|
114 | + return $this->message; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public function file() |
|
122 | + { |
|
123 | + return $this->file; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + public function func() |
|
131 | + { |
|
132 | + return $this->func; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + public function line() |
|
140 | + { |
|
141 | + return $this->line; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + public function isDismissible() |
|
149 | + { |
|
150 | + return $this->dismissible; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param string $type |
|
156 | + * @throws InvalidDataTypeException |
|
157 | + */ |
|
158 | + private function setType($type) |
|
159 | + { |
|
160 | + if (! in_array($type, $this->types(), true)) { |
|
161 | + throw new InvalidDataTypeException( |
|
162 | + '$type', |
|
163 | + $type, |
|
164 | + $this->invalidTypeMessage() |
|
165 | + ); |
|
166 | + } |
|
167 | + $this->type = $type; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * gets the $invalid_type_message string |
|
173 | + */ |
|
174 | + private function invalidTypeMessage() |
|
175 | + { |
|
176 | + return apply_filters( |
|
177 | + 'FHEE__EventEspresso_core_services_notices_Notice__invalidTypeMessage', |
|
178 | + sprintf( |
|
179 | + esc_html__( |
|
180 | + ' one of the following notice types was expected: %1$s %2$s', |
|
181 | + 'event_espresso' |
|
182 | + ), |
|
183 | + '<br />', |
|
184 | + var_export($this->types(), true) |
|
185 | + ) |
|
186 | + ); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $message |
|
192 | + * @throws InvalidDataTypeException |
|
193 | + */ |
|
194 | + private function setMessage($message) |
|
195 | + { |
|
196 | + if (empty($message) || ! is_string($message)) { |
|
197 | + throw new InvalidDataTypeException( |
|
198 | + '$message', |
|
199 | + $message, |
|
200 | + esc_html__('non empty string', 'event_espresso') |
|
201 | + ); |
|
202 | + } |
|
203 | + $this->message = $message; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * @param string $file |
|
209 | + * @throws InvalidDataTypeException |
|
210 | + */ |
|
211 | + private function setFile($file) |
|
212 | + { |
|
213 | + if ($this->type === Notice::ERROR && (empty($file) || ! is_string($file))) { |
|
214 | + throw new InvalidDataTypeException( |
|
215 | + '$file', |
|
216 | + $file, |
|
217 | + esc_html__('non empty string', 'event_espresso') |
|
218 | + ); |
|
219 | + } |
|
220 | + $this->file = $file; |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * @param string $func |
|
226 | + * @throws InvalidDataTypeException |
|
227 | + */ |
|
228 | + private function setFunc($func) |
|
229 | + { |
|
230 | + if ($this->type === Notice::ERROR && (empty($func) || ! is_string($func))) { |
|
231 | + throw new InvalidDataTypeException( |
|
232 | + '$func', |
|
233 | + $func, |
|
234 | + esc_html__('non empty string', 'event_espresso') |
|
235 | + ); |
|
236 | + } |
|
237 | + $this->func = $func; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @param int $line |
|
243 | + * @throws InvalidDataTypeException |
|
244 | + */ |
|
245 | + private function setLine($line) |
|
246 | + { |
|
247 | + $line = absint($line); |
|
248 | + if ($this->type === Notice::ERROR && $line === 0) { |
|
249 | + throw new InvalidDataTypeException( |
|
250 | + '$line', |
|
251 | + $line, |
|
252 | + esc_html__('integer', 'event_espresso') |
|
253 | + ); |
|
254 | + } |
|
255 | + $this->line = $line; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * @param boolean $dismissible |
|
261 | + */ |
|
262 | + private function setDismissible($dismissible = true) |
|
263 | + { |
|
264 | + $this->dismissible = filter_var($dismissible, FILTER_VALIDATE_BOOLEAN); |
|
265 | + } |
|
266 | 266 | } |
@@ -12,71 +12,71 @@ |
||
12 | 12 | abstract class NoticeConverter implements NoticeConverterInterface |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @var NoticesContainerInterface $notices |
|
17 | - */ |
|
18 | - private $notices; |
|
19 | - |
|
20 | - /** |
|
21 | - * if set to true, then errors will be thrown as exceptions |
|
22 | - * |
|
23 | - * @var boolean $throw_exceptions |
|
24 | - */ |
|
25 | - private $throw_exceptions; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * NoticeConverter constructor. |
|
30 | - * |
|
31 | - * @param bool $throw_exceptions |
|
32 | - */ |
|
33 | - public function __construct($throw_exceptions = false) |
|
34 | - { |
|
35 | - $this->throw_exceptions = $throw_exceptions; |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @return NoticesContainerInterface |
|
41 | - */ |
|
42 | - public function getNotices() |
|
43 | - { |
|
44 | - return $this->notices; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param NoticesContainerInterface $notices |
|
50 | - */ |
|
51 | - protected function setNotices(NoticesContainerInterface $notices) |
|
52 | - { |
|
53 | - $this->notices = $notices; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @return bool |
|
59 | - */ |
|
60 | - public function getThrowExceptions() |
|
61 | - { |
|
62 | - return $this->throw_exceptions; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @param bool $throw_exceptions |
|
68 | - */ |
|
69 | - public function setThrowExceptions($throw_exceptions) |
|
70 | - { |
|
71 | - $this->throw_exceptions = filter_var($throw_exceptions, FILTER_VALIDATE_BOOLEAN); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return void; |
|
77 | - */ |
|
78 | - public function clearNotices() |
|
79 | - { |
|
80 | - $this->notices = null; |
|
81 | - } |
|
15 | + /** |
|
16 | + * @var NoticesContainerInterface $notices |
|
17 | + */ |
|
18 | + private $notices; |
|
19 | + |
|
20 | + /** |
|
21 | + * if set to true, then errors will be thrown as exceptions |
|
22 | + * |
|
23 | + * @var boolean $throw_exceptions |
|
24 | + */ |
|
25 | + private $throw_exceptions; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * NoticeConverter constructor. |
|
30 | + * |
|
31 | + * @param bool $throw_exceptions |
|
32 | + */ |
|
33 | + public function __construct($throw_exceptions = false) |
|
34 | + { |
|
35 | + $this->throw_exceptions = $throw_exceptions; |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @return NoticesContainerInterface |
|
41 | + */ |
|
42 | + public function getNotices() |
|
43 | + { |
|
44 | + return $this->notices; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param NoticesContainerInterface $notices |
|
50 | + */ |
|
51 | + protected function setNotices(NoticesContainerInterface $notices) |
|
52 | + { |
|
53 | + $this->notices = $notices; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @return bool |
|
59 | + */ |
|
60 | + public function getThrowExceptions() |
|
61 | + { |
|
62 | + return $this->throw_exceptions; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @param bool $throw_exceptions |
|
68 | + */ |
|
69 | + public function setThrowExceptions($throw_exceptions) |
|
70 | + { |
|
71 | + $this->throw_exceptions = filter_var($throw_exceptions, FILTER_VALIDATE_BOOLEAN); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return void; |
|
77 | + */ |
|
78 | + public function clearNotices() |
|
79 | + { |
|
80 | + $this->notices = null; |
|
81 | + } |
|
82 | 82 | } |
@@ -13,119 +13,119 @@ |
||
13 | 13 | class AdminNotice |
14 | 14 | { |
15 | 15 | |
16 | - const ERROR = 'notice-error'; |
|
17 | - |
|
18 | - const WARNING = 'notice-warning'; |
|
19 | - |
|
20 | - const SUCCESS = 'notice-success'; |
|
21 | - |
|
22 | - const INFORMATION = 'notice-info'; |
|
23 | - |
|
24 | - const DISMISSABLE = ' is-dismissible'; |
|
25 | - |
|
26 | - /** |
|
27 | - * generic system notice to be converted into a WP admin notice |
|
28 | - * |
|
29 | - * @var NoticeInterface $notice |
|
30 | - */ |
|
31 | - private $notice; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * AdminNotice constructor. |
|
36 | - * |
|
37 | - * @param NoticeInterface $notice |
|
38 | - * @param bool $display_now |
|
39 | - */ |
|
40 | - public function __construct(NoticeInterface $notice, $display_now = true) |
|
41 | - { |
|
42 | - $this->notice = $notice; |
|
43 | - if (! did_action('admin_notices')) { |
|
44 | - add_action('admin_notices', array($this, 'displayNotice')); |
|
45 | - } elseif ($display_now) { |
|
46 | - $this->displayNotice(); |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - public function displayNotice() |
|
55 | - { |
|
56 | - echo $this->getNotice(); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * produces something like: |
|
62 | - * <div class="notice notice-success is-dismissible event-espresso-admin-notice"> |
|
63 | - * <p>YOU DID IT!</p> |
|
64 | - * <button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this |
|
65 | - * notice.</span></button> |
|
66 | - * </div> |
|
67 | - * |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getNotice() |
|
71 | - { |
|
72 | - return sprintf( |
|
73 | - '<div class="notice %1$s%2$s event-espresso-admin-notice"><p>%3$s</p></div>', |
|
74 | - $this->getType(), |
|
75 | - $this->notice->isDismissible() ? AdminNotice::DISMISSABLE : '', |
|
76 | - $this->getMessage() |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - private function getType() |
|
85 | - { |
|
86 | - switch ($this->notice->type()) { |
|
87 | - case Notice::ERROR: |
|
88 | - return AdminNotice::ERROR; |
|
89 | - break; |
|
90 | - case Notice::ATTENTION: |
|
91 | - return AdminNotice::WARNING; |
|
92 | - break; |
|
93 | - case Notice::SUCCESS: |
|
94 | - return AdminNotice::SUCCESS; |
|
95 | - break; |
|
96 | - case Notice::INFORMATION: |
|
97 | - default: |
|
98 | - return AdminNotice::INFORMATION; |
|
99 | - break; |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - protected function getMessage() |
|
108 | - { |
|
109 | - $message = $this->notice->message(); |
|
110 | - if (WP_DEBUG && $this->getType() === AdminNotice::ERROR) { |
|
111 | - $message .= '<br/><span class="tiny-text">' . $this->generateErrorCode() . '</span>'; |
|
112 | - } |
|
113 | - return $message; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * create error code from filepath, function name, |
|
119 | - * and line number where notice was generated |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - protected function generateErrorCode() |
|
124 | - { |
|
125 | - $file = explode('.', basename($this->notice->file())); |
|
126 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
127 | - $error_code .= ! empty($error_code) ? ' - ' . $this->notice->func() : $this->notice->func(); |
|
128 | - $error_code .= ' - ' . $this->notice->line(); |
|
129 | - return $error_code; |
|
130 | - } |
|
16 | + const ERROR = 'notice-error'; |
|
17 | + |
|
18 | + const WARNING = 'notice-warning'; |
|
19 | + |
|
20 | + const SUCCESS = 'notice-success'; |
|
21 | + |
|
22 | + const INFORMATION = 'notice-info'; |
|
23 | + |
|
24 | + const DISMISSABLE = ' is-dismissible'; |
|
25 | + |
|
26 | + /** |
|
27 | + * generic system notice to be converted into a WP admin notice |
|
28 | + * |
|
29 | + * @var NoticeInterface $notice |
|
30 | + */ |
|
31 | + private $notice; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * AdminNotice constructor. |
|
36 | + * |
|
37 | + * @param NoticeInterface $notice |
|
38 | + * @param bool $display_now |
|
39 | + */ |
|
40 | + public function __construct(NoticeInterface $notice, $display_now = true) |
|
41 | + { |
|
42 | + $this->notice = $notice; |
|
43 | + if (! did_action('admin_notices')) { |
|
44 | + add_action('admin_notices', array($this, 'displayNotice')); |
|
45 | + } elseif ($display_now) { |
|
46 | + $this->displayNotice(); |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + public function displayNotice() |
|
55 | + { |
|
56 | + echo $this->getNotice(); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * produces something like: |
|
62 | + * <div class="notice notice-success is-dismissible event-espresso-admin-notice"> |
|
63 | + * <p>YOU DID IT!</p> |
|
64 | + * <button type="button" class="notice-dismiss"><span class="screen-reader-text">Dismiss this |
|
65 | + * notice.</span></button> |
|
66 | + * </div> |
|
67 | + * |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getNotice() |
|
71 | + { |
|
72 | + return sprintf( |
|
73 | + '<div class="notice %1$s%2$s event-espresso-admin-notice"><p>%3$s</p></div>', |
|
74 | + $this->getType(), |
|
75 | + $this->notice->isDismissible() ? AdminNotice::DISMISSABLE : '', |
|
76 | + $this->getMessage() |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + private function getType() |
|
85 | + { |
|
86 | + switch ($this->notice->type()) { |
|
87 | + case Notice::ERROR: |
|
88 | + return AdminNotice::ERROR; |
|
89 | + break; |
|
90 | + case Notice::ATTENTION: |
|
91 | + return AdminNotice::WARNING; |
|
92 | + break; |
|
93 | + case Notice::SUCCESS: |
|
94 | + return AdminNotice::SUCCESS; |
|
95 | + break; |
|
96 | + case Notice::INFORMATION: |
|
97 | + default: |
|
98 | + return AdminNotice::INFORMATION; |
|
99 | + break; |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + protected function getMessage() |
|
108 | + { |
|
109 | + $message = $this->notice->message(); |
|
110 | + if (WP_DEBUG && $this->getType() === AdminNotice::ERROR) { |
|
111 | + $message .= '<br/><span class="tiny-text">' . $this->generateErrorCode() . '</span>'; |
|
112 | + } |
|
113 | + return $message; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * create error code from filepath, function name, |
|
119 | + * and line number where notice was generated |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + protected function generateErrorCode() |
|
124 | + { |
|
125 | + $file = explode('.', basename($this->notice->file())); |
|
126 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
127 | + $error_code .= ! empty($error_code) ? ' - ' . $this->notice->func() : $this->notice->func(); |
|
128 | + $error_code .= ' - ' . $this->notice->line(); |
|
129 | + return $error_code; |
|
130 | + } |
|
131 | 131 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function __construct(NoticeInterface $notice, $display_now = true) |
41 | 41 | { |
42 | 42 | $this->notice = $notice; |
43 | - if (! did_action('admin_notices')) { |
|
43 | + if ( ! did_action('admin_notices')) { |
|
44 | 44 | add_action('admin_notices', array($this, 'displayNotice')); |
45 | 45 | } elseif ($display_now) { |
46 | 46 | $this->displayNotice(); |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | { |
109 | 109 | $message = $this->notice->message(); |
110 | 110 | if (WP_DEBUG && $this->getType() === AdminNotice::ERROR) { |
111 | - $message .= '<br/><span class="tiny-text">' . $this->generateErrorCode() . '</span>'; |
|
111 | + $message .= '<br/><span class="tiny-text">'.$this->generateErrorCode().'</span>'; |
|
112 | 112 | } |
113 | 113 | return $message; |
114 | 114 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | { |
125 | 125 | $file = explode('.', basename($this->notice->file())); |
126 | 126 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
127 | - $error_code .= ! empty($error_code) ? ' - ' . $this->notice->func() : $this->notice->func(); |
|
128 | - $error_code .= ' - ' . $this->notice->line(); |
|
127 | + $error_code .= ! empty($error_code) ? ' - '.$this->notice->func() : $this->notice->func(); |
|
128 | + $error_code .= ' - '.$this->notice->line(); |
|
129 | 129 | return $error_code; |
130 | 130 | } |
131 | 131 | } |
@@ -15,218 +15,218 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @var NoticeInterface[] $information |
|
20 | - */ |
|
21 | - private $information = array(); |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @var NoticeInterface[] $attention |
|
26 | - */ |
|
27 | - private $attention = array(); |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @var NoticeInterface[] $error |
|
32 | - */ |
|
33 | - private $error = array(); |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @var NoticeInterface[] $success |
|
38 | - */ |
|
39 | - private $success = array(); |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string $notice |
|
44 | - * @param bool $dismissible |
|
45 | - * @param string $file |
|
46 | - * @param string $func |
|
47 | - * @param string $line |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - */ |
|
50 | - public function addInformation($notice, $dismissible = true, $file = '', $func = '', $line = '') |
|
51 | - { |
|
52 | - $this->information[] = new Notice( |
|
53 | - Notice::INFORMATION, |
|
54 | - $notice, |
|
55 | - $dismissible, |
|
56 | - $file, |
|
57 | - $func, |
|
58 | - $line |
|
59 | - ); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param string $notice |
|
65 | - * @param bool $dismissible |
|
66 | - * @param string $file |
|
67 | - * @param string $func |
|
68 | - * @param string $line |
|
69 | - * @throws InvalidDataTypeException |
|
70 | - */ |
|
71 | - public function addAttention($notice, $dismissible = true, $file = '', $func = '', $line = '') |
|
72 | - { |
|
73 | - $this->attention[] = new Notice( |
|
74 | - Notice::ATTENTION, |
|
75 | - $notice, |
|
76 | - $dismissible, |
|
77 | - $file, |
|
78 | - $func, |
|
79 | - $line |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
84 | - /** |
|
85 | - * @param string $notice |
|
86 | - * @param bool $dismissible |
|
87 | - * @param string $file |
|
88 | - * @param string $func |
|
89 | - * @param string $line |
|
90 | - * @throws InvalidDataTypeException |
|
91 | - */ |
|
92 | - public function addError($notice, $dismissible = true, $file, $func, $line) |
|
93 | - { |
|
94 | - $this->error[] = new Notice( |
|
95 | - Notice::ERROR, |
|
96 | - $notice, |
|
97 | - $dismissible, |
|
98 | - $file, |
|
99 | - $func, |
|
100 | - $line |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $notice |
|
107 | - * @param bool $dismissible |
|
108 | - * @param string $file |
|
109 | - * @param string $func |
|
110 | - * @param string $line |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - */ |
|
113 | - public function addSuccess($notice, $dismissible = true, $file = '', $func = '', $line = '') |
|
114 | - { |
|
115 | - $this->success[] = new Notice( |
|
116 | - Notice::SUCCESS, |
|
117 | - $notice, |
|
118 | - $dismissible, |
|
119 | - $file, |
|
120 | - $func, |
|
121 | - $line |
|
122 | - ); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return boolean |
|
128 | - */ |
|
129 | - public function hasInformation() |
|
130 | - { |
|
131 | - return ! empty($this->information); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @return boolean |
|
137 | - */ |
|
138 | - public function hasAttention() |
|
139 | - { |
|
140 | - return ! empty($this->attention); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return boolean |
|
146 | - */ |
|
147 | - public function hasError() |
|
148 | - { |
|
149 | - return ! empty($this->error); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @return boolean |
|
155 | - */ |
|
156 | - public function hasSuccess() |
|
157 | - { |
|
158 | - return ! empty($this->success); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @return int |
|
164 | - */ |
|
165 | - public function countInformation() |
|
166 | - { |
|
167 | - return count($this->information); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @return int |
|
173 | - */ |
|
174 | - public function countAttention() |
|
175 | - { |
|
176 | - return count($this->attention); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * @return int |
|
182 | - */ |
|
183 | - public function countError() |
|
184 | - { |
|
185 | - return count($this->error); |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * @return int |
|
191 | - */ |
|
192 | - public function countSuccess() |
|
193 | - { |
|
194 | - return count($this->success); |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * @return NoticeInterface[] |
|
200 | - */ |
|
201 | - public function getInformation() |
|
202 | - { |
|
203 | - return $this->information; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * @return NoticeInterface[] |
|
209 | - */ |
|
210 | - public function getAttention() |
|
211 | - { |
|
212 | - return $this->attention; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @return NoticeInterface[] |
|
218 | - */ |
|
219 | - public function getError() |
|
220 | - { |
|
221 | - return $this->error; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return NoticeInterface[] |
|
227 | - */ |
|
228 | - public function getSuccess() |
|
229 | - { |
|
230 | - return $this->success; |
|
231 | - } |
|
18 | + /** |
|
19 | + * @var NoticeInterface[] $information |
|
20 | + */ |
|
21 | + private $information = array(); |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @var NoticeInterface[] $attention |
|
26 | + */ |
|
27 | + private $attention = array(); |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @var NoticeInterface[] $error |
|
32 | + */ |
|
33 | + private $error = array(); |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @var NoticeInterface[] $success |
|
38 | + */ |
|
39 | + private $success = array(); |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string $notice |
|
44 | + * @param bool $dismissible |
|
45 | + * @param string $file |
|
46 | + * @param string $func |
|
47 | + * @param string $line |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + */ |
|
50 | + public function addInformation($notice, $dismissible = true, $file = '', $func = '', $line = '') |
|
51 | + { |
|
52 | + $this->information[] = new Notice( |
|
53 | + Notice::INFORMATION, |
|
54 | + $notice, |
|
55 | + $dismissible, |
|
56 | + $file, |
|
57 | + $func, |
|
58 | + $line |
|
59 | + ); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param string $notice |
|
65 | + * @param bool $dismissible |
|
66 | + * @param string $file |
|
67 | + * @param string $func |
|
68 | + * @param string $line |
|
69 | + * @throws InvalidDataTypeException |
|
70 | + */ |
|
71 | + public function addAttention($notice, $dismissible = true, $file = '', $func = '', $line = '') |
|
72 | + { |
|
73 | + $this->attention[] = new Notice( |
|
74 | + Notice::ATTENTION, |
|
75 | + $notice, |
|
76 | + $dismissible, |
|
77 | + $file, |
|
78 | + $func, |
|
79 | + $line |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
84 | + /** |
|
85 | + * @param string $notice |
|
86 | + * @param bool $dismissible |
|
87 | + * @param string $file |
|
88 | + * @param string $func |
|
89 | + * @param string $line |
|
90 | + * @throws InvalidDataTypeException |
|
91 | + */ |
|
92 | + public function addError($notice, $dismissible = true, $file, $func, $line) |
|
93 | + { |
|
94 | + $this->error[] = new Notice( |
|
95 | + Notice::ERROR, |
|
96 | + $notice, |
|
97 | + $dismissible, |
|
98 | + $file, |
|
99 | + $func, |
|
100 | + $line |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $notice |
|
107 | + * @param bool $dismissible |
|
108 | + * @param string $file |
|
109 | + * @param string $func |
|
110 | + * @param string $line |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + */ |
|
113 | + public function addSuccess($notice, $dismissible = true, $file = '', $func = '', $line = '') |
|
114 | + { |
|
115 | + $this->success[] = new Notice( |
|
116 | + Notice::SUCCESS, |
|
117 | + $notice, |
|
118 | + $dismissible, |
|
119 | + $file, |
|
120 | + $func, |
|
121 | + $line |
|
122 | + ); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return boolean |
|
128 | + */ |
|
129 | + public function hasInformation() |
|
130 | + { |
|
131 | + return ! empty($this->information); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @return boolean |
|
137 | + */ |
|
138 | + public function hasAttention() |
|
139 | + { |
|
140 | + return ! empty($this->attention); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return boolean |
|
146 | + */ |
|
147 | + public function hasError() |
|
148 | + { |
|
149 | + return ! empty($this->error); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @return boolean |
|
155 | + */ |
|
156 | + public function hasSuccess() |
|
157 | + { |
|
158 | + return ! empty($this->success); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @return int |
|
164 | + */ |
|
165 | + public function countInformation() |
|
166 | + { |
|
167 | + return count($this->information); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @return int |
|
173 | + */ |
|
174 | + public function countAttention() |
|
175 | + { |
|
176 | + return count($this->attention); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * @return int |
|
182 | + */ |
|
183 | + public function countError() |
|
184 | + { |
|
185 | + return count($this->error); |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * @return int |
|
191 | + */ |
|
192 | + public function countSuccess() |
|
193 | + { |
|
194 | + return count($this->success); |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * @return NoticeInterface[] |
|
200 | + */ |
|
201 | + public function getInformation() |
|
202 | + { |
|
203 | + return $this->information; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * @return NoticeInterface[] |
|
209 | + */ |
|
210 | + public function getAttention() |
|
211 | + { |
|
212 | + return $this->attention; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @return NoticeInterface[] |
|
218 | + */ |
|
219 | + public function getError() |
|
220 | + { |
|
221 | + return $this->error; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return NoticeInterface[] |
|
227 | + */ |
|
228 | + public function getSuccess() |
|
229 | + { |
|
230 | + return $this->success; |
|
231 | + } |
|
232 | 232 | } |
@@ -22,96 +22,96 @@ |
||
22 | 22 | class BootstrapDependencyInjectionContainer |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var EE_Dependency_Map $dependency_map |
|
27 | - */ |
|
28 | - protected $dependency_map; |
|
29 | - |
|
30 | - /** |
|
31 | - * @type LoaderInterface $loader |
|
32 | - */ |
|
33 | - protected $loader; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var EE_Registry $registry |
|
37 | - */ |
|
38 | - protected $registry; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Can't use this just yet until we exorcise some more of our singleton usage from core |
|
43 | - */ |
|
44 | - public function buildDependencyInjectionContainer() |
|
45 | - { |
|
46 | - // build DI container |
|
47 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
48 | - // $OpenCoffeeShop->addRecipes(); |
|
49 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Setups EE_Registry and EE_Dependency_Map |
|
55 | - * |
|
56 | - * @throws EE_Error |
|
57 | - * @throws InvalidDataTypeException |
|
58 | - * @throws InvalidInterfaceException |
|
59 | - * @throws InvalidArgumentException |
|
60 | - */ |
|
61 | - public function buildLegacyDependencyInjectionContainer() |
|
62 | - { |
|
63 | - // EE_Dependency_Map: info about how to load classes required by other classes |
|
64 | - espresso_load_required( |
|
65 | - 'EE_Dependency_Map', |
|
66 | - EE_CORE . 'EE_Dependency_Map.core.php' |
|
67 | - ); |
|
68 | - $this->dependency_map = EE_Dependency_Map::instance(); |
|
69 | - // EE_Registry: central repository for classes (legacy) |
|
70 | - espresso_load_required( |
|
71 | - 'EE_Registry', |
|
72 | - EE_CORE . 'EE_Registry.core.php' |
|
73 | - ); |
|
74 | - $this->registry = EE_Registry::instance($this->dependency_map); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Performs initial setup for the generic Loader |
|
80 | - * |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - * @throws InvalidInterfaceException |
|
83 | - * @throws InvalidArgumentException |
|
84 | - */ |
|
85 | - public function buildLoader() |
|
86 | - { |
|
87 | - $this->loader = LoaderFactory::getLoader($this->registry); |
|
88 | - $this->dependency_map->setLoader($this->loader); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return EE_Dependency_Map |
|
94 | - */ |
|
95 | - public function getDependencyMap() |
|
96 | - { |
|
97 | - return $this->dependency_map; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return EE_Registry |
|
103 | - */ |
|
104 | - public function getRegistry() |
|
105 | - { |
|
106 | - return $this->registry; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return LoaderInterface |
|
112 | - */ |
|
113 | - public function getLoader() |
|
114 | - { |
|
115 | - return $this->loader; |
|
116 | - } |
|
25 | + /** |
|
26 | + * @var EE_Dependency_Map $dependency_map |
|
27 | + */ |
|
28 | + protected $dependency_map; |
|
29 | + |
|
30 | + /** |
|
31 | + * @type LoaderInterface $loader |
|
32 | + */ |
|
33 | + protected $loader; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var EE_Registry $registry |
|
37 | + */ |
|
38 | + protected $registry; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Can't use this just yet until we exorcise some more of our singleton usage from core |
|
43 | + */ |
|
44 | + public function buildDependencyInjectionContainer() |
|
45 | + { |
|
46 | + // build DI container |
|
47 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
48 | + // $OpenCoffeeShop->addRecipes(); |
|
49 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Setups EE_Registry and EE_Dependency_Map |
|
55 | + * |
|
56 | + * @throws EE_Error |
|
57 | + * @throws InvalidDataTypeException |
|
58 | + * @throws InvalidInterfaceException |
|
59 | + * @throws InvalidArgumentException |
|
60 | + */ |
|
61 | + public function buildLegacyDependencyInjectionContainer() |
|
62 | + { |
|
63 | + // EE_Dependency_Map: info about how to load classes required by other classes |
|
64 | + espresso_load_required( |
|
65 | + 'EE_Dependency_Map', |
|
66 | + EE_CORE . 'EE_Dependency_Map.core.php' |
|
67 | + ); |
|
68 | + $this->dependency_map = EE_Dependency_Map::instance(); |
|
69 | + // EE_Registry: central repository for classes (legacy) |
|
70 | + espresso_load_required( |
|
71 | + 'EE_Registry', |
|
72 | + EE_CORE . 'EE_Registry.core.php' |
|
73 | + ); |
|
74 | + $this->registry = EE_Registry::instance($this->dependency_map); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Performs initial setup for the generic Loader |
|
80 | + * |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + * @throws InvalidInterfaceException |
|
83 | + * @throws InvalidArgumentException |
|
84 | + */ |
|
85 | + public function buildLoader() |
|
86 | + { |
|
87 | + $this->loader = LoaderFactory::getLoader($this->registry); |
|
88 | + $this->dependency_map->setLoader($this->loader); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return EE_Dependency_Map |
|
94 | + */ |
|
95 | + public function getDependencyMap() |
|
96 | + { |
|
97 | + return $this->dependency_map; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return EE_Registry |
|
103 | + */ |
|
104 | + public function getRegistry() |
|
105 | + { |
|
106 | + return $this->registry; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return LoaderInterface |
|
112 | + */ |
|
113 | + public function getLoader() |
|
114 | + { |
|
115 | + return $this->loader; |
|
116 | + } |
|
117 | 117 | } |
@@ -25,80 +25,80 @@ |
||
25 | 25 | class BootstrapRequestResponseObjects |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @type LegacyRequestInterface $legacy_request |
|
30 | - */ |
|
31 | - protected $legacy_request; |
|
28 | + /** |
|
29 | + * @type LegacyRequestInterface $legacy_request |
|
30 | + */ |
|
31 | + protected $legacy_request; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @type LoaderInterface $loader |
|
35 | - */ |
|
36 | - protected $loader; |
|
33 | + /** |
|
34 | + * @type LoaderInterface $loader |
|
35 | + */ |
|
36 | + protected $loader; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var RequestInterface $request |
|
40 | - */ |
|
41 | - protected $request; |
|
38 | + /** |
|
39 | + * @var RequestInterface $request |
|
40 | + */ |
|
41 | + protected $request; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var ResponseInterface $response |
|
45 | - */ |
|
46 | - protected $response; |
|
43 | + /** |
|
44 | + * @var ResponseInterface $response |
|
45 | + */ |
|
46 | + protected $response; |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * BootstrapRequestResponseObjects constructor. |
|
51 | - * |
|
52 | - * @param LoaderInterface $loader |
|
53 | - */ |
|
54 | - public function __construct(LoaderInterface $loader) |
|
55 | - { |
|
56 | - $this->loader = $loader; |
|
57 | - } |
|
49 | + /** |
|
50 | + * BootstrapRequestResponseObjects constructor. |
|
51 | + * |
|
52 | + * @param LoaderInterface $loader |
|
53 | + */ |
|
54 | + public function __construct(LoaderInterface $loader) |
|
55 | + { |
|
56 | + $this->loader = $loader; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function buildRequestResponse() |
|
64 | - { |
|
65 | - // load our Request and Response objects |
|
66 | - $this->request = new Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
67 | - $this->response = new Response(); |
|
68 | - } |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function buildRequestResponse() |
|
64 | + { |
|
65 | + // load our Request and Response objects |
|
66 | + $this->request = new Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
67 | + $this->response = new Response(); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return void |
|
73 | - * @throws InvalidArgumentException |
|
74 | - */ |
|
75 | - public function shareRequestResponse() |
|
76 | - { |
|
77 | - $this->loader->share('EventEspresso\core\services\request\Request', $this->request); |
|
78 | - $this->loader->share('EventEspresso\core\services\request\Response', $this->response); |
|
79 | - EE_Dependency_Map::instance()->setRequest($this->request); |
|
80 | - EE_Dependency_Map::instance()->setResponse($this->response); |
|
81 | - } |
|
71 | + /** |
|
72 | + * @return void |
|
73 | + * @throws InvalidArgumentException |
|
74 | + */ |
|
75 | + public function shareRequestResponse() |
|
76 | + { |
|
77 | + $this->loader->share('EventEspresso\core\services\request\Request', $this->request); |
|
78 | + $this->loader->share('EventEspresso\core\services\request\Response', $this->response); |
|
79 | + EE_Dependency_Map::instance()->setRequest($this->request); |
|
80 | + EE_Dependency_Map::instance()->setResponse($this->response); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * @return void |
|
86 | - * @throws InvalidArgumentException |
|
87 | - * @throws EE_Error |
|
88 | - */ |
|
89 | - public function setupLegacyRequest() |
|
90 | - { |
|
91 | - espresso_load_required( |
|
92 | - 'EE_Request', |
|
93 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
94 | - ); |
|
95 | - $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
96 | - $this->legacy_request->setRequest($this->request); |
|
97 | - $this->legacy_request->admin = $this->request->isAdmin(); |
|
98 | - $this->legacy_request->ajax = $this->request->isAjax(); |
|
99 | - $this->legacy_request->front_ajax = $this->request->isFrontAjax(); |
|
100 | - EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request); |
|
101 | - $this->loader->share('EE_Request', $this->legacy_request); |
|
102 | - $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request); |
|
103 | - } |
|
84 | + /** |
|
85 | + * @return void |
|
86 | + * @throws InvalidArgumentException |
|
87 | + * @throws EE_Error |
|
88 | + */ |
|
89 | + public function setupLegacyRequest() |
|
90 | + { |
|
91 | + espresso_load_required( |
|
92 | + 'EE_Request', |
|
93 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
94 | + ); |
|
95 | + $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER); |
|
96 | + $this->legacy_request->setRequest($this->request); |
|
97 | + $this->legacy_request->admin = $this->request->isAdmin(); |
|
98 | + $this->legacy_request->ajax = $this->request->isAjax(); |
|
99 | + $this->legacy_request->front_ajax = $this->request->isFrontAjax(); |
|
100 | + EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request); |
|
101 | + $this->loader->share('EE_Request', $this->legacy_request); |
|
102 | + $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request); |
|
103 | + } |
|
104 | 104 | } |