@@ -18,91 +18,91 @@ |
||
18 | 18 | class PreProductionVersionWarning extends Middleware |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * converts a Request to a Response |
|
23 | - * |
|
24 | - * @param RequestInterface $request |
|
25 | - * @param ResponseInterface $response |
|
26 | - * @return ResponseInterface |
|
27 | - */ |
|
28 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
29 | - { |
|
30 | - $this->request = $request; |
|
31 | - $this->response = $response; |
|
32 | - $this->displayPreProductionVersionWarning(); |
|
33 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
34 | - return $this->response; |
|
35 | - } |
|
21 | + /** |
|
22 | + * converts a Request to a Response |
|
23 | + * |
|
24 | + * @param RequestInterface $request |
|
25 | + * @param ResponseInterface $response |
|
26 | + * @return ResponseInterface |
|
27 | + */ |
|
28 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
29 | + { |
|
30 | + $this->request = $request; |
|
31 | + $this->response = $response; |
|
32 | + $this->displayPreProductionVersionWarning(); |
|
33 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
34 | + return $this->response; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
40 | - * |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public function displayPreProductionVersionWarning() |
|
44 | - { |
|
45 | - // skip AJAX requests |
|
46 | - if ($this->request->isAjax()) { |
|
47 | - return; |
|
48 | - } |
|
49 | - // skip stable releases |
|
50 | - if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
51 | - return; |
|
52 | - } |
|
53 | - // site admin has authorized use of non-stable release candidate for production |
|
54 | - if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
55 | - return; |
|
56 | - } |
|
57 | - // post release candidate warning |
|
58 | - if ($this->request->isAdmin()) { |
|
59 | - add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
60 | - } else { |
|
61 | - add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
62 | - } |
|
63 | - } |
|
38 | + /** |
|
39 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
40 | + * |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public function displayPreProductionVersionWarning() |
|
44 | + { |
|
45 | + // skip AJAX requests |
|
46 | + if ($this->request->isAjax()) { |
|
47 | + return; |
|
48 | + } |
|
49 | + // skip stable releases |
|
50 | + if (substr(EVENT_ESPRESSO_VERSION, -5) !== '.beta') { |
|
51 | + return; |
|
52 | + } |
|
53 | + // site admin has authorized use of non-stable release candidate for production |
|
54 | + if (defined('ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE') && ALLOW_NON_STABLE_RELEASE_ON_LIVE_SITE) { |
|
55 | + return; |
|
56 | + } |
|
57 | + // post release candidate warning |
|
58 | + if ($this->request->isAdmin()) { |
|
59 | + add_action('admin_notices', array($this, 'preProductionVersionAdminNotice'), -999); |
|
60 | + } else { |
|
61 | + add_action('shutdown', array($this, 'preProductionVersionWarningNotice'), 10); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * displays admin notice that current version of EE is not a stable release |
|
68 | - * |
|
69 | - * @return void |
|
70 | - * @throws InvalidDataTypeException |
|
71 | - */ |
|
72 | - public function preProductionVersionAdminNotice() |
|
73 | - { |
|
74 | - new PersistentAdminNotice( |
|
75 | - 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
76 | - $this->warningNotice() |
|
77 | - ); |
|
78 | - } |
|
66 | + /** |
|
67 | + * displays admin notice that current version of EE is not a stable release |
|
68 | + * |
|
69 | + * @return void |
|
70 | + * @throws InvalidDataTypeException |
|
71 | + */ |
|
72 | + public function preProductionVersionAdminNotice() |
|
73 | + { |
|
74 | + new PersistentAdminNotice( |
|
75 | + 'preProductionVersionAdminNotice_' . EVENT_ESPRESSO_VERSION, |
|
76 | + $this->warningNotice() |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
83 | - * |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public function preProductionVersionWarningNotice() |
|
87 | - { |
|
88 | - echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
89 | - echo $this->warningNotice(); |
|
90 | - echo '</p></div>'; |
|
91 | - } |
|
81 | + /** |
|
82 | + * displays message on frontend of site notifying admin that current version of EE is not a stable release |
|
83 | + * |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public function preProductionVersionWarningNotice() |
|
87 | + { |
|
88 | + echo '<div id="ee-release-candidate-notice-dv" class="ee-really-important-notice-dv"><p>'; |
|
89 | + echo $this->warningNotice(); |
|
90 | + echo '</p></div>'; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - private function warningNotice() |
|
98 | - { |
|
99 | - return sprintf( |
|
100 | - esc_html__( |
|
101 | - 'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - '<strong>', |
|
105 | - '</strong>' |
|
106 | - ); |
|
107 | - } |
|
94 | + /** |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + private function warningNotice() |
|
98 | + { |
|
99 | + return sprintf( |
|
100 | + esc_html__( |
|
101 | + 'This version of Event Espresso is for testing and/or evaluation purposes only. It is %1$snot%2$s considered a stable release and should therefore %1$snot%2$s be activated on a live or production website.', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + '<strong>', |
|
105 | + '</strong>' |
|
106 | + ); |
|
107 | + } |
|
108 | 108 | } |
@@ -16,28 +16,28 @@ |
||
16 | 16 | class DetectLogin extends Middleware |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * converts a Request to a Response |
|
21 | - * |
|
22 | - * @param RequestInterface $request |
|
23 | - * @param ResponseInterface $response |
|
24 | - * @return ResponseInterface |
|
25 | - */ |
|
26 | - public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
27 | - { |
|
28 | - $this->request = $request; |
|
29 | - $this->response = $response; |
|
30 | - global $pagenow; |
|
31 | - if (in_array( |
|
32 | - $pagenow, |
|
33 | - array('wp-login.php', 'wp-register.php'), |
|
34 | - true |
|
35 | - ) |
|
36 | - && ! filter_var($request->getRequestParam('ee_load_on_login'), FILTER_VALIDATE_BOOLEAN) |
|
37 | - ) { |
|
38 | - $this->response->terminateRequest(); |
|
39 | - } |
|
40 | - $this->response = $this->processRequestStack($this->request, $this->response); |
|
41 | - return $this->response; |
|
42 | - } |
|
19 | + /** |
|
20 | + * converts a Request to a Response |
|
21 | + * |
|
22 | + * @param RequestInterface $request |
|
23 | + * @param ResponseInterface $response |
|
24 | + * @return ResponseInterface |
|
25 | + */ |
|
26 | + public function handleRequest(RequestInterface $request, ResponseInterface $response) |
|
27 | + { |
|
28 | + $this->request = $request; |
|
29 | + $this->response = $response; |
|
30 | + global $pagenow; |
|
31 | + if (in_array( |
|
32 | + $pagenow, |
|
33 | + array('wp-login.php', 'wp-register.php'), |
|
34 | + true |
|
35 | + ) |
|
36 | + && ! filter_var($request->getRequestParam('ee_load_on_login'), FILTER_VALIDATE_BOOLEAN) |
|
37 | + ) { |
|
38 | + $this->response->terminateRequest(); |
|
39 | + } |
|
40 | + $this->response = $this->processRequestStack($this->request, $this->response); |
|
41 | + return $this->response; |
|
42 | + } |
|
43 | 43 | } |
@@ -25,52 +25,52 @@ |
||
25 | 25 | abstract class Middleware implements RequestDecoratorInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var RequestDecoratorInterface $request_stack_app |
|
30 | - */ |
|
31 | - protected $request_stack_app; |
|
28 | + /** |
|
29 | + * @var RequestDecoratorInterface $request_stack_app |
|
30 | + */ |
|
31 | + protected $request_stack_app; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var RequestInterface $request |
|
35 | - */ |
|
36 | - protected $request; |
|
33 | + /** |
|
34 | + * @var RequestInterface $request |
|
35 | + */ |
|
36 | + protected $request; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var ResponseInterface $response |
|
40 | - */ |
|
41 | - protected $response; |
|
38 | + /** |
|
39 | + * @var ResponseInterface $response |
|
40 | + */ |
|
41 | + protected $response; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var LoaderInterface |
|
45 | - */ |
|
46 | - protected $loader; |
|
43 | + /** |
|
44 | + * @var LoaderInterface |
|
45 | + */ |
|
46 | + protected $loader; |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * @param RequestDecoratorInterface $request_stack_app |
|
51 | - * @param LoaderInterface $loader |
|
52 | - */ |
|
53 | - public function __construct(RequestDecoratorInterface $request_stack_app, LoaderInterface $loader) |
|
54 | - { |
|
55 | - $this->request_stack_app = $request_stack_app; |
|
56 | - $this->loader = $loader; |
|
57 | - } |
|
49 | + /** |
|
50 | + * @param RequestDecoratorInterface $request_stack_app |
|
51 | + * @param LoaderInterface $loader |
|
52 | + */ |
|
53 | + public function __construct(RequestDecoratorInterface $request_stack_app, LoaderInterface $loader) |
|
54 | + { |
|
55 | + $this->request_stack_app = $request_stack_app; |
|
56 | + $this->loader = $loader; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * process_request_stack |
|
62 | - * |
|
63 | - * @param RequestInterface $request |
|
64 | - * @param ResponseInterface $response |
|
65 | - * @return ResponseInterface |
|
66 | - */ |
|
67 | - protected function processRequestStack(RequestInterface $request, ResponseInterface $response) |
|
68 | - { |
|
69 | - $this->request = $request; |
|
70 | - $this->response = $response; |
|
71 | - if (! $this->response->requestTerminated()) { |
|
72 | - $this->response = $this->request_stack_app->handleRequest($this->request, $this->response); |
|
73 | - } |
|
74 | - return $this->response; |
|
75 | - } |
|
60 | + /** |
|
61 | + * process_request_stack |
|
62 | + * |
|
63 | + * @param RequestInterface $request |
|
64 | + * @param ResponseInterface $response |
|
65 | + * @return ResponseInterface |
|
66 | + */ |
|
67 | + protected function processRequestStack(RequestInterface $request, ResponseInterface $response) |
|
68 | + { |
|
69 | + $this->request = $request; |
|
70 | + $this->response = $response; |
|
71 | + if (! $this->response->requestTerminated()) { |
|
72 | + $this->response = $this->request_stack_app->handleRequest($this->request, $this->response); |
|
73 | + } |
|
74 | + return $this->response; |
|
75 | + } |
|
76 | 76 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | { |
69 | 69 | $this->request = $request; |
70 | 70 | $this->response = $response; |
71 | - if (! $this->response->requestTerminated()) { |
|
71 | + if ( ! $this->response->requestTerminated()) { |
|
72 | 72 | $this->response = $this->request_stack_app->handleRequest($this->request, $this->response); |
73 | 73 | } |
74 | 74 | return $this->response; |
@@ -16,37 +16,37 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * setCollectionInterface |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @param string $collection_interface |
|
24 | - */ |
|
25 | - protected function setCollectionInterface($collection_interface) |
|
26 | - { |
|
27 | - $this->collection_interface = ''; |
|
28 | - } |
|
19 | + /** |
|
20 | + * setCollectionInterface |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @param string $collection_interface |
|
24 | + */ |
|
25 | + protected function setCollectionInterface($collection_interface) |
|
26 | + { |
|
27 | + $this->collection_interface = ''; |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * add |
|
33 | - * attaches an object to the Collection |
|
34 | - * and sets any supplied data associated with the current iterator entry |
|
35 | - * by calling EE_Object_Collection::set_identifier() |
|
36 | - * |
|
37 | - * @access public |
|
38 | - * @param mixed $object |
|
39 | - * @param mixed $identifier |
|
40 | - * @return bool |
|
41 | - * @throws InvalidEntityException |
|
42 | - */ |
|
43 | - public function add($object, $identifier = null) |
|
44 | - { |
|
45 | - if (! is_object($object)) { |
|
46 | - throw new InvalidEntityException($object, 'object'); |
|
47 | - } |
|
48 | - $this->attach($object); |
|
49 | - $this->setIdentifier($object, $identifier); |
|
50 | - return $this->contains($object); |
|
51 | - } |
|
31 | + /** |
|
32 | + * add |
|
33 | + * attaches an object to the Collection |
|
34 | + * and sets any supplied data associated with the current iterator entry |
|
35 | + * by calling EE_Object_Collection::set_identifier() |
|
36 | + * |
|
37 | + * @access public |
|
38 | + * @param mixed $object |
|
39 | + * @param mixed $identifier |
|
40 | + * @return bool |
|
41 | + * @throws InvalidEntityException |
|
42 | + */ |
|
43 | + public function add($object, $identifier = null) |
|
44 | + { |
|
45 | + if (! is_object($object)) { |
|
46 | + throw new InvalidEntityException($object, 'object'); |
|
47 | + } |
|
48 | + $this->attach($object); |
|
49 | + $this->setIdentifier($object, $identifier); |
|
50 | + return $this->contains($object); |
|
51 | + } |
|
52 | 52 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | */ |
43 | 43 | public function add($object, $identifier = null) |
44 | 44 | { |
45 | - if (! is_object($object)) { |
|
45 | + if ( ! is_object($object)) { |
|
46 | 46 | throw new InvalidEntityException($object, 'object'); |
47 | 47 | } |
48 | 48 | $this->attach($object); |
@@ -16,135 +16,135 @@ discard block |
||
16 | 16 | class BasicCacheManager implements CacheManagerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @type string |
|
21 | - */ |
|
22 | - const CACHE_PREFIX = 'ee_cache_'; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @var CacheStorageInterface $cache_storage |
|
27 | - */ |
|
28 | - private $cache_storage; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * BasicCacheManager constructor. |
|
33 | - * |
|
34 | - * @param CacheStorageInterface $cache_storage [required] |
|
35 | - */ |
|
36 | - public function __construct(CacheStorageInterface $cache_storage) |
|
37 | - { |
|
38 | - $this->cache_storage = $cache_storage; |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * returns a string that will be prepended to all cache identifiers |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function cachePrefix() |
|
48 | - { |
|
49 | - return BasicCacheManager::CACHE_PREFIX; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
55 | - * May also be helpful to include an additional specific identifier, |
|
56 | - * such as a post ID as part of the $id_prefix so that individual caches |
|
57 | - * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
58 | - * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
59 | - * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
60 | - * It is advisable to use some of the actual data |
|
61 | - * that is used to generate the content being cached, |
|
62 | - * in order to guarantee that the cache id is unique for that content. |
|
63 | - * The cache id will be md5'd before usage to make it more db friendly, |
|
64 | - * and the entire cache id string will be truncated to 190 characters. |
|
65 | - * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
66 | - * necessary, |
|
67 | - * we wrap our content creation in a Closure so that it is not executed until needed. |
|
68 | - * @param int $expiration |
|
69 | - * @return Closure|mixed |
|
70 | - */ |
|
71 | - public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
72 | - { |
|
73 | - $content = ''; |
|
74 | - $expiration = absint( |
|
75 | - apply_filters( |
|
76 | - 'FHEE__CacheManager__get__cache_expiration', |
|
77 | - $expiration, |
|
78 | - $id_prefix, |
|
79 | - $cache_id |
|
80 | - ) |
|
81 | - ); |
|
82 | - $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id); |
|
83 | - // is caching enabled for this content ? |
|
84 | - if ($expiration) { |
|
85 | - $content = $this->cache_storage->get($cache_id); |
|
86 | - } |
|
87 | - // any existing content ? |
|
88 | - if (empty($content)) { |
|
89 | - // nope! let's generate some new stuff |
|
90 | - $content = $callback(); |
|
91 | - // save the new content if caching is enabled |
|
92 | - if ($expiration) { |
|
93 | - $this->cache_storage->add($cache_id, $content, $expiration); |
|
94 | - if (EE_DEBUG) { |
|
95 | - $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE'); |
|
96 | - } |
|
97 | - } |
|
98 | - } else { |
|
99 | - if (EE_DEBUG) { |
|
100 | - $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT'); |
|
101 | - } |
|
102 | - } |
|
103 | - return $content; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Generates a unique identifier string for the cache |
|
109 | - * |
|
110 | - * @param string $id_prefix [required] see BasicCacheManager::get() |
|
111 | - * @param string $cache_id [required] see BasicCacheManager::get() |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - private function generateCacheIdentifier($id_prefix, $cache_id) |
|
115 | - { |
|
116 | - // let's make the cached content unique for this "page" |
|
117 | - $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); |
|
118 | - // with these parameters |
|
119 | - $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
|
120 | - // then md5 the above to control it's length, add all of our prefixes, and truncate |
|
121 | - return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
127 | - * or a specific ID targeting a single cache item |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - public function clear($cache_id) |
|
131 | - { |
|
132 | - // ensure incoming arg is in an array |
|
133 | - $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
134 | - // delete corresponding transients for the supplied id prefix |
|
135 | - $this->cache_storage->deleteMany($cache_id); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
141 | - * or a specific ID targeting a single cache item |
|
142 | - * @param string $type |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - private function displayCacheNotice($cache_id, $type) |
|
146 | - { |
|
147 | - return ' |
|
19 | + /** |
|
20 | + * @type string |
|
21 | + */ |
|
22 | + const CACHE_PREFIX = 'ee_cache_'; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @var CacheStorageInterface $cache_storage |
|
27 | + */ |
|
28 | + private $cache_storage; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * BasicCacheManager constructor. |
|
33 | + * |
|
34 | + * @param CacheStorageInterface $cache_storage [required] |
|
35 | + */ |
|
36 | + public function __construct(CacheStorageInterface $cache_storage) |
|
37 | + { |
|
38 | + $this->cache_storage = $cache_storage; |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * returns a string that will be prepended to all cache identifiers |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function cachePrefix() |
|
48 | + { |
|
49 | + return BasicCacheManager::CACHE_PREFIX; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @param string $id_prefix [required] Prepended to all cache IDs. Can be helpful in finding specific cache types. |
|
55 | + * May also be helpful to include an additional specific identifier, |
|
56 | + * such as a post ID as part of the $id_prefix so that individual caches |
|
57 | + * can be found and/or cleared. ex: "venue-28", or "shortcode-156". |
|
58 | + * BasicCacheManager::CACHE_PREFIX will also be prepended to the cache id. |
|
59 | + * @param string $cache_id [required] Additional identifying details that make this cache unique. |
|
60 | + * It is advisable to use some of the actual data |
|
61 | + * that is used to generate the content being cached, |
|
62 | + * in order to guarantee that the cache id is unique for that content. |
|
63 | + * The cache id will be md5'd before usage to make it more db friendly, |
|
64 | + * and the entire cache id string will be truncated to 190 characters. |
|
65 | + * @param Closure $callback [required] since the point of caching is to avoid generating content when not |
|
66 | + * necessary, |
|
67 | + * we wrap our content creation in a Closure so that it is not executed until needed. |
|
68 | + * @param int $expiration |
|
69 | + * @return Closure|mixed |
|
70 | + */ |
|
71 | + public function get($id_prefix, $cache_id, Closure $callback, $expiration = HOUR_IN_SECONDS) |
|
72 | + { |
|
73 | + $content = ''; |
|
74 | + $expiration = absint( |
|
75 | + apply_filters( |
|
76 | + 'FHEE__CacheManager__get__cache_expiration', |
|
77 | + $expiration, |
|
78 | + $id_prefix, |
|
79 | + $cache_id |
|
80 | + ) |
|
81 | + ); |
|
82 | + $cache_id = $this->generateCacheIdentifier($id_prefix, $cache_id); |
|
83 | + // is caching enabled for this content ? |
|
84 | + if ($expiration) { |
|
85 | + $content = $this->cache_storage->get($cache_id); |
|
86 | + } |
|
87 | + // any existing content ? |
|
88 | + if (empty($content)) { |
|
89 | + // nope! let's generate some new stuff |
|
90 | + $content = $callback(); |
|
91 | + // save the new content if caching is enabled |
|
92 | + if ($expiration) { |
|
93 | + $this->cache_storage->add($cache_id, $content, $expiration); |
|
94 | + if (EE_DEBUG) { |
|
95 | + $content .= $this->displayCacheNotice($cache_id, 'REFRESH CACHE'); |
|
96 | + } |
|
97 | + } |
|
98 | + } else { |
|
99 | + if (EE_DEBUG) { |
|
100 | + $content .= $this->displayCacheNotice($cache_id, 'CACHED CONTENT'); |
|
101 | + } |
|
102 | + } |
|
103 | + return $content; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Generates a unique identifier string for the cache |
|
109 | + * |
|
110 | + * @param string $id_prefix [required] see BasicCacheManager::get() |
|
111 | + * @param string $cache_id [required] see BasicCacheManager::get() |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + private function generateCacheIdentifier($id_prefix, $cache_id) |
|
115 | + { |
|
116 | + // let's make the cached content unique for this "page" |
|
117 | + $cache_id .= filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL); |
|
118 | + // with these parameters |
|
119 | + $cache_id .= filter_input(INPUT_SERVER, 'QUERY_STRING', FILTER_SANITIZE_URL); |
|
120 | + // then md5 the above to control it's length, add all of our prefixes, and truncate |
|
121 | + return substr($this->cachePrefix() . $id_prefix . '-' . md5($cache_id), 0, 182); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
127 | + * or a specific ID targeting a single cache item |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + public function clear($cache_id) |
|
131 | + { |
|
132 | + // ensure incoming arg is in an array |
|
133 | + $cache_id = is_array($cache_id) ? $cache_id : array($cache_id); |
|
134 | + // delete corresponding transients for the supplied id prefix |
|
135 | + $this->cache_storage->deleteMany($cache_id); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param array|string $cache_id [required] Could be an ID prefix affecting many caches |
|
141 | + * or a specific ID targeting a single cache item |
|
142 | + * @param string $type |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + private function displayCacheNotice($cache_id, $type) |
|
146 | + { |
|
147 | + return ' |
|
148 | 148 | <div class="ee-cached-content-notice" style="position:fixed; bottom:0; left: 0;"> |
149 | 149 | <p style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;margin:0 0 3px 5px"> |
150 | 150 | <b>' . $type . '</b><span style="color:#999"> : </span> |
@@ -152,5 +152,5 @@ discard block |
||
152 | 152 | <span style="margin-left:2em;">' . __FILE__ . '</span> |
153 | 153 | </p> |
154 | 154 | </div>'; |
155 | - } |
|
155 | + } |
|
156 | 156 | } |
@@ -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 | } |
@@ -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 | } |