@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.065'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.065'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | // if you're a dev and want to receive all errors via email |
12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -27,258 +27,258 @@ discard block |
||
27 | 27 | class EE_Error extends Exception |
28 | 28 | { |
29 | 29 | |
30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * name of the file to log exceptions to |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | - |
|
40 | - /** |
|
41 | - * stores details for all exception |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private static $_all_exceptions = array(); |
|
46 | - |
|
47 | - /** |
|
48 | - * tracks number of errors |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - private static $_error_count = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $_espresso_notices |
|
56 | - */ |
|
57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @override default exception handling |
|
63 | - * @param string $message |
|
64 | - * @param int $code |
|
65 | - * @param Exception|null $previous |
|
66 | - */ |
|
67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | - { |
|
69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | - parent::__construct($message, $code); |
|
71 | - } else { |
|
72 | - parent::__construct($message, $code, $previous); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * error_handler |
|
79 | - * |
|
80 | - * @param $code |
|
81 | - * @param $message |
|
82 | - * @param $file |
|
83 | - * @param $line |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public static function error_handler($code, $message, $file, $line) |
|
87 | - { |
|
88 | - $type = EE_Error::error_type($code); |
|
89 | - $site = site_url(); |
|
90 | - switch ($site) { |
|
91 | - case 'http://ee4.eventespresso.com/' : |
|
92 | - case 'http://ee4decaf.eventespresso.com/' : |
|
93 | - case 'http://ee4hf.eventespresso.com/' : |
|
94 | - case 'http://ee4a.eventespresso.com/' : |
|
95 | - case 'http://ee4ad.eventespresso.com/' : |
|
96 | - case 'http://ee4b.eventespresso.com/' : |
|
97 | - case 'http://ee4bd.eventespresso.com/' : |
|
98 | - case 'http://ee4d.eventespresso.com/' : |
|
99 | - case 'http://ee4dd.eventespresso.com/' : |
|
100 | - $to = '[email protected]'; |
|
101 | - break; |
|
102 | - default : |
|
103 | - $to = get_option('admin_email'); |
|
104 | - } |
|
105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
106 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
107 | - if (function_exists('wp_mail')) { |
|
108 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
109 | - wp_mail($to, $subject, $msg); |
|
110 | - } |
|
111 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
113 | - echo '<br /></p></div>'; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * error_type |
|
120 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
121 | - * |
|
122 | - * @param $code |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public static function error_type($code) |
|
126 | - { |
|
127 | - switch ($code) { |
|
128 | - case E_ERROR: // 1 // |
|
129 | - return 'E_ERROR'; |
|
130 | - case E_WARNING: // 2 // |
|
131 | - return 'E_WARNING'; |
|
132 | - case E_PARSE: // 4 // |
|
133 | - return 'E_PARSE'; |
|
134 | - case E_NOTICE: // 8 // |
|
135 | - return 'E_NOTICE'; |
|
136 | - case E_CORE_ERROR: // 16 // |
|
137 | - return 'E_CORE_ERROR'; |
|
138 | - case E_CORE_WARNING: // 32 // |
|
139 | - return 'E_CORE_WARNING'; |
|
140 | - case E_COMPILE_ERROR: // 64 // |
|
141 | - return 'E_COMPILE_ERROR'; |
|
142 | - case E_COMPILE_WARNING: // 128 // |
|
143 | - return 'E_COMPILE_WARNING'; |
|
144 | - case E_USER_ERROR: // 256 // |
|
145 | - return 'E_USER_ERROR'; |
|
146 | - case E_USER_WARNING: // 512 // |
|
147 | - return 'E_USER_WARNING'; |
|
148 | - case E_USER_NOTICE: // 1024 // |
|
149 | - return 'E_USER_NOTICE'; |
|
150 | - case E_STRICT: // 2048 // |
|
151 | - return 'E_STRICT'; |
|
152 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
153 | - return 'E_RECOVERABLE_ERROR'; |
|
154 | - case E_DEPRECATED: // 8192 // |
|
155 | - return 'E_DEPRECATED'; |
|
156 | - case E_USER_DEPRECATED: // 16384 // |
|
157 | - return 'E_USER_DEPRECATED'; |
|
158 | - case E_ALL: // 16384 // |
|
159 | - return 'E_ALL'; |
|
160 | - } |
|
161 | - return ''; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * fatal_error_handler |
|
168 | - * |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - public static function fatal_error_handler() |
|
172 | - { |
|
173 | - $last_error = error_get_last(); |
|
174 | - if ($last_error['type'] === E_ERROR) { |
|
175 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * _format_error |
|
183 | - * |
|
184 | - * @param $code |
|
185 | - * @param $message |
|
186 | - * @param $file |
|
187 | - * @param $line |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - private static function _format_error($code, $message, $file, $line) |
|
191 | - { |
|
192 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
193 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
194 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
195 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
196 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
197 | - $html .= '</tbody></table>'; |
|
198 | - return $html; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * set_content_type |
|
205 | - * |
|
206 | - * @param $content_type |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public static function set_content_type($content_type) |
|
210 | - { |
|
211 | - return 'text/html'; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @return void |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function get_error() |
|
222 | - { |
|
223 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
224 | - throw $this; |
|
225 | - } |
|
226 | - // get separate user and developer messages if they exist |
|
227 | - $msg = explode('||', $this->getMessage()); |
|
228 | - $user_msg = $msg[0]; |
|
229 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
230 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
231 | - // add details to _all_exceptions array |
|
232 | - $x_time = time(); |
|
233 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
234 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
235 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
236 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
237 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
238 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
239 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
240 | - self::$_error_count++; |
|
241 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
242 | - $this->display_errors(); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param bool $check_stored |
|
248 | - * @param string $type_to_check |
|
249 | - * @return bool |
|
250 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
251 | - * @throws \InvalidArgumentException |
|
252 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
253 | - * @throws InvalidInterfaceException |
|
254 | - */ |
|
255 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
256 | - { |
|
257 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
258 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
259 | - ? true |
|
260 | - : false; |
|
261 | - if ($check_stored && ! $has_error) { |
|
262 | - $notices = EE_Error::getStoredNotices(); |
|
263 | - foreach ($notices as $type => $notice) { |
|
264 | - if ($type === $type_to_check && $notice) { |
|
265 | - return true; |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - return $has_error; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @echo string |
|
276 | - * @throws \ReflectionException |
|
277 | - */ |
|
278 | - public function display_errors() |
|
279 | - { |
|
280 | - $trace_details = ''; |
|
281 | - $output = ' |
|
30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * name of the file to log exceptions to |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | + |
|
40 | + /** |
|
41 | + * stores details for all exception |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private static $_all_exceptions = array(); |
|
46 | + |
|
47 | + /** |
|
48 | + * tracks number of errors |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + private static $_error_count = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $_espresso_notices |
|
56 | + */ |
|
57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @override default exception handling |
|
63 | + * @param string $message |
|
64 | + * @param int $code |
|
65 | + * @param Exception|null $previous |
|
66 | + */ |
|
67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | + { |
|
69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | + parent::__construct($message, $code); |
|
71 | + } else { |
|
72 | + parent::__construct($message, $code, $previous); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * error_handler |
|
79 | + * |
|
80 | + * @param $code |
|
81 | + * @param $message |
|
82 | + * @param $file |
|
83 | + * @param $line |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public static function error_handler($code, $message, $file, $line) |
|
87 | + { |
|
88 | + $type = EE_Error::error_type($code); |
|
89 | + $site = site_url(); |
|
90 | + switch ($site) { |
|
91 | + case 'http://ee4.eventespresso.com/' : |
|
92 | + case 'http://ee4decaf.eventespresso.com/' : |
|
93 | + case 'http://ee4hf.eventespresso.com/' : |
|
94 | + case 'http://ee4a.eventespresso.com/' : |
|
95 | + case 'http://ee4ad.eventespresso.com/' : |
|
96 | + case 'http://ee4b.eventespresso.com/' : |
|
97 | + case 'http://ee4bd.eventespresso.com/' : |
|
98 | + case 'http://ee4d.eventespresso.com/' : |
|
99 | + case 'http://ee4dd.eventespresso.com/' : |
|
100 | + $to = '[email protected]'; |
|
101 | + break; |
|
102 | + default : |
|
103 | + $to = get_option('admin_email'); |
|
104 | + } |
|
105 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
106 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
107 | + if (function_exists('wp_mail')) { |
|
108 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
109 | + wp_mail($to, $subject, $msg); |
|
110 | + } |
|
111 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
112 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
113 | + echo '<br /></p></div>'; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * error_type |
|
120 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
121 | + * |
|
122 | + * @param $code |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public static function error_type($code) |
|
126 | + { |
|
127 | + switch ($code) { |
|
128 | + case E_ERROR: // 1 // |
|
129 | + return 'E_ERROR'; |
|
130 | + case E_WARNING: // 2 // |
|
131 | + return 'E_WARNING'; |
|
132 | + case E_PARSE: // 4 // |
|
133 | + return 'E_PARSE'; |
|
134 | + case E_NOTICE: // 8 // |
|
135 | + return 'E_NOTICE'; |
|
136 | + case E_CORE_ERROR: // 16 // |
|
137 | + return 'E_CORE_ERROR'; |
|
138 | + case E_CORE_WARNING: // 32 // |
|
139 | + return 'E_CORE_WARNING'; |
|
140 | + case E_COMPILE_ERROR: // 64 // |
|
141 | + return 'E_COMPILE_ERROR'; |
|
142 | + case E_COMPILE_WARNING: // 128 // |
|
143 | + return 'E_COMPILE_WARNING'; |
|
144 | + case E_USER_ERROR: // 256 // |
|
145 | + return 'E_USER_ERROR'; |
|
146 | + case E_USER_WARNING: // 512 // |
|
147 | + return 'E_USER_WARNING'; |
|
148 | + case E_USER_NOTICE: // 1024 // |
|
149 | + return 'E_USER_NOTICE'; |
|
150 | + case E_STRICT: // 2048 // |
|
151 | + return 'E_STRICT'; |
|
152 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
153 | + return 'E_RECOVERABLE_ERROR'; |
|
154 | + case E_DEPRECATED: // 8192 // |
|
155 | + return 'E_DEPRECATED'; |
|
156 | + case E_USER_DEPRECATED: // 16384 // |
|
157 | + return 'E_USER_DEPRECATED'; |
|
158 | + case E_ALL: // 16384 // |
|
159 | + return 'E_ALL'; |
|
160 | + } |
|
161 | + return ''; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * fatal_error_handler |
|
168 | + * |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + public static function fatal_error_handler() |
|
172 | + { |
|
173 | + $last_error = error_get_last(); |
|
174 | + if ($last_error['type'] === E_ERROR) { |
|
175 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * _format_error |
|
183 | + * |
|
184 | + * @param $code |
|
185 | + * @param $message |
|
186 | + * @param $file |
|
187 | + * @param $line |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + private static function _format_error($code, $message, $file, $line) |
|
191 | + { |
|
192 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
193 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
194 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
195 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
196 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
197 | + $html .= '</tbody></table>'; |
|
198 | + return $html; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * set_content_type |
|
205 | + * |
|
206 | + * @param $content_type |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public static function set_content_type($content_type) |
|
210 | + { |
|
211 | + return 'text/html'; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @return void |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function get_error() |
|
222 | + { |
|
223 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
224 | + throw $this; |
|
225 | + } |
|
226 | + // get separate user and developer messages if they exist |
|
227 | + $msg = explode('||', $this->getMessage()); |
|
228 | + $user_msg = $msg[0]; |
|
229 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
230 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
231 | + // add details to _all_exceptions array |
|
232 | + $x_time = time(); |
|
233 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
234 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
235 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
236 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
237 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
238 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
239 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
240 | + self::$_error_count++; |
|
241 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
242 | + $this->display_errors(); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param bool $check_stored |
|
248 | + * @param string $type_to_check |
|
249 | + * @return bool |
|
250 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
251 | + * @throws \InvalidArgumentException |
|
252 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
253 | + * @throws InvalidInterfaceException |
|
254 | + */ |
|
255 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
256 | + { |
|
257 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
258 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
259 | + ? true |
|
260 | + : false; |
|
261 | + if ($check_stored && ! $has_error) { |
|
262 | + $notices = EE_Error::getStoredNotices(); |
|
263 | + foreach ($notices as $type => $notice) { |
|
264 | + if ($type === $type_to_check && $notice) { |
|
265 | + return true; |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + return $has_error; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @echo string |
|
276 | + * @throws \ReflectionException |
|
277 | + */ |
|
278 | + public function display_errors() |
|
279 | + { |
|
280 | + $trace_details = ''; |
|
281 | + $output = ' |
|
282 | 282 | <style type="text/css"> |
283 | 283 | #ee-error-message { |
284 | 284 | max-width:90% !important; |
@@ -334,21 +334,21 @@ discard block |
||
334 | 334 | } |
335 | 335 | </style> |
336 | 336 | <div id="ee-error-message" class="error">'; |
337 | - if (! WP_DEBUG) { |
|
338 | - $output .= ' |
|
337 | + if (! WP_DEBUG) { |
|
338 | + $output .= ' |
|
339 | 339 | <p>'; |
340 | - } |
|
341 | - // cycle thru errors |
|
342 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
343 | - $error_code = ''; |
|
344 | - // process trace info |
|
345 | - if (empty($ex['trace'])) { |
|
346 | - $trace_details .= __( |
|
347 | - 'Sorry, but no trace information was available for this exception.', |
|
348 | - 'event_espresso' |
|
349 | - ); |
|
350 | - } else { |
|
351 | - $trace_details .= ' |
|
340 | + } |
|
341 | + // cycle thru errors |
|
342 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
343 | + $error_code = ''; |
|
344 | + // process trace info |
|
345 | + if (empty($ex['trace'])) { |
|
346 | + $trace_details .= __( |
|
347 | + 'Sorry, but no trace information was available for this exception.', |
|
348 | + 'event_espresso' |
|
349 | + ); |
|
350 | + } else { |
|
351 | + $trace_details .= ' |
|
352 | 352 | <div id="ee-trace-details"> |
353 | 353 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
354 | 354 | <tr> |
@@ -358,43 +358,43 @@ discard block |
||
358 | 358 | <th scope="col" align="left">Class</th> |
359 | 359 | <th scope="col" align="left">Method( arguments )</th> |
360 | 360 | </tr>'; |
361 | - $last_on_stack = count($ex['trace']) - 1; |
|
362 | - // reverse array so that stack is in proper chronological order |
|
363 | - $sorted_trace = array_reverse($ex['trace']); |
|
364 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
365 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
366 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
367 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
368 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
369 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
370 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
371 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
372 | - if (empty($file) && ! empty($class)) { |
|
373 | - $a = new ReflectionClass($class); |
|
374 | - $file = $a->getFileName(); |
|
375 | - if (empty($line) && ! empty($function)) { |
|
376 | - try { |
|
377 | - //if $function is a closure, this throws an exception |
|
378 | - $b = new ReflectionMethod($class, $function); |
|
379 | - $line = $b->getStartLine(); |
|
380 | - } catch (Exception $closure_exception) { |
|
381 | - $line = 'unknown'; |
|
382 | - } |
|
383 | - } |
|
384 | - } |
|
385 | - if ($nmbr === $last_on_stack) { |
|
386 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
387 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
388 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
389 | - } |
|
390 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
391 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
392 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
393 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
394 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
395 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
397 | - $trace_details .= ' |
|
361 | + $last_on_stack = count($ex['trace']) - 1; |
|
362 | + // reverse array so that stack is in proper chronological order |
|
363 | + $sorted_trace = array_reverse($ex['trace']); |
|
364 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
365 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
366 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
367 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
368 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
369 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
370 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
371 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
372 | + if (empty($file) && ! empty($class)) { |
|
373 | + $a = new ReflectionClass($class); |
|
374 | + $file = $a->getFileName(); |
|
375 | + if (empty($line) && ! empty($function)) { |
|
376 | + try { |
|
377 | + //if $function is a closure, this throws an exception |
|
378 | + $b = new ReflectionMethod($class, $function); |
|
379 | + $line = $b->getStartLine(); |
|
380 | + } catch (Exception $closure_exception) { |
|
381 | + $line = 'unknown'; |
|
382 | + } |
|
383 | + } |
|
384 | + } |
|
385 | + if ($nmbr === $last_on_stack) { |
|
386 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
387 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
388 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
389 | + } |
|
390 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
391 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
392 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
393 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
394 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
395 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
396 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
397 | + $trace_details .= ' |
|
398 | 398 | <tr> |
399 | 399 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
400 | 400 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -402,633 +402,633 @@ discard block |
||
402 | 402 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
403 | 403 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
404 | 404 | </tr>'; |
405 | - } |
|
406 | - $trace_details .= ' |
|
405 | + } |
|
406 | + $trace_details .= ' |
|
407 | 407 | </table> |
408 | 408 | </div>'; |
409 | - } |
|
410 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
411 | - // add generic non-identifying messages for non-privileged users |
|
412 | - if (! WP_DEBUG) { |
|
413 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
414 | - . trim($ex['msg']) |
|
415 | - . '</span> <sup>' |
|
416 | - . $ex['code'] |
|
417 | - . '</sup><br />'; |
|
418 | - } else { |
|
419 | - // or helpful developer messages if debugging is on |
|
420 | - $output .= ' |
|
409 | + } |
|
410 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
411 | + // add generic non-identifying messages for non-privileged users |
|
412 | + if (! WP_DEBUG) { |
|
413 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
414 | + . trim($ex['msg']) |
|
415 | + . '</span> <sup>' |
|
416 | + . $ex['code'] |
|
417 | + . '</sup><br />'; |
|
418 | + } else { |
|
419 | + // or helpful developer messages if debugging is on |
|
420 | + $output .= ' |
|
421 | 421 | <div class="ee-error-dev-msg-dv"> |
422 | 422 | <p class="ee-error-dev-msg-pg"> |
423 | 423 | <strong class="ee-error-dev-msg-str">An ' |
424 | - . $ex['name'] |
|
425 | - . ' exception was thrown!</strong> <span>code: ' |
|
426 | - . $ex['code'] |
|
427 | - . '</span><br /> |
|
424 | + . $ex['name'] |
|
425 | + . ' exception was thrown!</strong> <span>code: ' |
|
426 | + . $ex['code'] |
|
427 | + . '</span><br /> |
|
428 | 428 | <span class="big-text">"' |
429 | - . trim($ex['msg']) |
|
430 | - . '"</span><br/> |
|
429 | + . trim($ex['msg']) |
|
430 | + . '"</span><br/> |
|
431 | 431 | <a id="display-ee-error-trace-' |
432 | - . self::$_error_count |
|
433 | - . $time |
|
434 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
435 | - . self::$_error_count |
|
436 | - . $time |
|
437 | - . '"> |
|
432 | + . self::$_error_count |
|
433 | + . $time |
|
434 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
435 | + . self::$_error_count |
|
436 | + . $time |
|
437 | + . '"> |
|
438 | 438 | ' |
439 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
440 | - . ' |
|
439 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
440 | + . ' |
|
441 | 441 | </a><br /> |
442 | 442 | <span class="small-text lt-grey-text">' |
443 | - . $ex['file'] |
|
444 | - . ' ( line no: ' |
|
445 | - . $ex['line'] |
|
446 | - . ' )</span> |
|
443 | + . $ex['file'] |
|
444 | + . ' ( line no: ' |
|
445 | + . $ex['line'] |
|
446 | + . ' )</span> |
|
447 | 447 | </p> |
448 | 448 | <div id="ee-error-trace-' |
449 | - . self::$_error_count |
|
450 | - . $time |
|
451 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
449 | + . self::$_error_count |
|
450 | + . $time |
|
451 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
452 | 452 | ' |
453 | - . $trace_details; |
|
454 | - if (! empty($class)) { |
|
455 | - $output .= ' |
|
453 | + . $trace_details; |
|
454 | + if (! empty($class)) { |
|
455 | + $output .= ' |
|
456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
458 | 458 | <h3>Class Details</h3>'; |
459 | - $a = new ReflectionClass($class); |
|
460 | - $output .= ' |
|
459 | + $a = new ReflectionClass($class); |
|
460 | + $output .= ' |
|
461 | 461 | <pre>' . $a . '</pre> |
462 | 462 | </div> |
463 | 463 | </div>'; |
464 | - } |
|
465 | - $output .= ' |
|
464 | + } |
|
465 | + $output .= ' |
|
466 | 466 | </div> |
467 | 467 | </div> |
468 | 468 | <br />'; |
469 | - } |
|
470 | - $this->write_to_error_log($time, $ex); |
|
471 | - } |
|
472 | - // remove last linebreak |
|
473 | - $output = substr($output, 0, -6); |
|
474 | - if (! WP_DEBUG) { |
|
475 | - $output .= ' |
|
469 | + } |
|
470 | + $this->write_to_error_log($time, $ex); |
|
471 | + } |
|
472 | + // remove last linebreak |
|
473 | + $output = substr($output, 0, -6); |
|
474 | + if (! WP_DEBUG) { |
|
475 | + $output .= ' |
|
476 | 476 | </p>'; |
477 | - } |
|
478 | - $output .= ' |
|
477 | + } |
|
478 | + $output .= ' |
|
479 | 479 | </div>'; |
480 | - $output .= self::_print_scripts(true); |
|
481 | - if (defined('DOING_AJAX')) { |
|
482 | - echo wp_json_encode(array('error' => $output)); |
|
483 | - exit(); |
|
484 | - } |
|
485 | - echo $output; |
|
486 | - die(); |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * generate string from exception trace args |
|
493 | - * |
|
494 | - * @param array $arguments |
|
495 | - * @param bool $array |
|
496 | - * @return string |
|
497 | - */ |
|
498 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
499 | - { |
|
500 | - $arg_string = ''; |
|
501 | - if (! empty($arguments)) { |
|
502 | - $args = array(); |
|
503 | - foreach ($arguments as $arg) { |
|
504 | - if (! empty($arg)) { |
|
505 | - if (is_string($arg)) { |
|
506 | - $args[] = " '" . $arg . "'"; |
|
507 | - } elseif (is_array($arg)) { |
|
508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
509 | - } elseif ($arg === null) { |
|
510 | - $args[] = ' NULL'; |
|
511 | - } elseif (is_bool($arg)) { |
|
512 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
513 | - } elseif (is_object($arg)) { |
|
514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
515 | - } elseif (is_resource($arg)) { |
|
516 | - $args[] = get_resource_type($arg); |
|
517 | - } else { |
|
518 | - $args[] = $arg; |
|
519 | - } |
|
520 | - } |
|
521 | - } |
|
522 | - $arg_string = implode(', ', $args); |
|
523 | - } |
|
524 | - if ($array) { |
|
525 | - $arg_string .= ' )'; |
|
526 | - } |
|
527 | - return $arg_string; |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * add error message |
|
534 | - * |
|
535 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
536 | - * separate messages for user || dev |
|
537 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
538 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
539 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
540 | - * @return void |
|
541 | - */ |
|
542 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
543 | - { |
|
544 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
545 | - self::$_error_count++; |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
552 | - * adds an error |
|
553 | - * |
|
554 | - * @param string $msg |
|
555 | - * @param string $file |
|
556 | - * @param string $func |
|
557 | - * @param string $line |
|
558 | - * @throws EE_Error |
|
559 | - */ |
|
560 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
561 | - { |
|
562 | - if (WP_DEBUG) { |
|
563 | - throw new EE_Error($msg); |
|
564 | - } |
|
565 | - EE_Error::add_error($msg, $file, $func, $line); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * add success message |
|
572 | - * |
|
573 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
574 | - * separate messages for user || dev |
|
575 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
576 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
577 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
578 | - * @return void |
|
579 | - */ |
|
580 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
581 | - { |
|
582 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * add attention message |
|
589 | - * |
|
590 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
591 | - * separate messages for user || dev |
|
592 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
593 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
594 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
595 | - * @return void |
|
596 | - */ |
|
597 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
598 | - { |
|
599 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
600 | - } |
|
601 | - |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * @param string $type whether the message is for a success or error notification |
|
606 | - * @param string $msg the message to display to users or developers |
|
607 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
608 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
609 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
610 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
611 | - * @return void |
|
612 | - */ |
|
613 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
614 | - { |
|
615 | - if (empty($msg)) { |
|
616 | - EE_Error::doing_it_wrong( |
|
617 | - 'EE_Error::add_' . $type . '()', |
|
618 | - sprintf( |
|
619 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
620 | - 'event_espresso'), |
|
621 | - $type, |
|
622 | - $file, |
|
623 | - $line |
|
624 | - ), |
|
625 | - EVENT_ESPRESSO_VERSION |
|
626 | - ); |
|
627 | - } |
|
628 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
629 | - EE_Error::doing_it_wrong( |
|
630 | - 'EE_Error::add_error()', |
|
631 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
632 | - 'event_espresso'), |
|
633 | - EVENT_ESPRESSO_VERSION |
|
634 | - ); |
|
635 | - } |
|
636 | - // get separate user and developer messages if they exist |
|
637 | - $msg = explode('||', $msg); |
|
638 | - $user_msg = $msg[0]; |
|
639 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
640 | - /** |
|
641 | - * Do an action so other code can be triggered when a notice is created |
|
642 | - * |
|
643 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
644 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
645 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
646 | - * @param string $file file where error was generated |
|
647 | - * @param string $func function where error was generated |
|
648 | - * @param string $line line where error was generated |
|
649 | - */ |
|
650 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
651 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
652 | - // add notice if message exists |
|
653 | - if (! empty($msg)) { |
|
654 | - // get error code |
|
655 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
656 | - if (WP_DEBUG && $type === 'errors') { |
|
657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
658 | - } |
|
659 | - // add notice. Index by code if it's not blank |
|
660 | - if ($notice_code) { |
|
661 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
662 | - } else { |
|
663 | - self::$_espresso_notices[$type][] = $msg; |
|
664 | - } |
|
665 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
666 | - } |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * in some case it may be necessary to overwrite the existing success messages |
|
672 | - * |
|
673 | - * @return void |
|
674 | - */ |
|
675 | - public static function overwrite_success() |
|
676 | - { |
|
677 | - self::$_espresso_notices['success'] = false; |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * in some case it may be necessary to overwrite the existing attention messages |
|
684 | - * |
|
685 | - * @return void |
|
686 | - */ |
|
687 | - public static function overwrite_attention() |
|
688 | - { |
|
689 | - self::$_espresso_notices['attention'] = false; |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * in some case it may be necessary to overwrite the existing error messages |
|
696 | - * |
|
697 | - * @return void |
|
698 | - */ |
|
699 | - public static function overwrite_errors() |
|
700 | - { |
|
701 | - self::$_espresso_notices['errors'] = false; |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * @return void |
|
708 | - */ |
|
709 | - public static function reset_notices() |
|
710 | - { |
|
711 | - self::$_espresso_notices['success'] = false; |
|
712 | - self::$_espresso_notices['attention'] = false; |
|
713 | - self::$_espresso_notices['errors'] = false; |
|
714 | - } |
|
715 | - |
|
716 | - |
|
717 | - |
|
718 | - /** |
|
719 | - * @return int |
|
720 | - */ |
|
721 | - public static function has_notices() |
|
722 | - { |
|
723 | - $has_notices = 0; |
|
724 | - // check for success messages |
|
725 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
726 | - ? 3 |
|
727 | - : $has_notices; |
|
728 | - // check for attention messages |
|
729 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
730 | - ? 2 |
|
731 | - : $has_notices; |
|
732 | - // check for error messages |
|
733 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
734 | - ? 1 |
|
735 | - : $has_notices; |
|
736 | - return $has_notices; |
|
737 | - } |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
742 | - * |
|
743 | - * @since 4.9.0 |
|
744 | - * @return array |
|
745 | - */ |
|
746 | - public static function get_vanilla_notices() |
|
747 | - { |
|
748 | - return array( |
|
749 | - 'success' => isset(self::$_espresso_notices['success']) |
|
750 | - ? self::$_espresso_notices['success'] |
|
751 | - : array(), |
|
752 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
753 | - ? self::$_espresso_notices['attention'] |
|
754 | - : array(), |
|
755 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
756 | - ? self::$_espresso_notices['errors'] |
|
757 | - : array(), |
|
758 | - ); |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * @return array |
|
764 | - * @throws InvalidArgumentException |
|
765 | - * @throws InvalidDataTypeException |
|
766 | - * @throws InvalidInterfaceException |
|
767 | - */ |
|
768 | - public static function getStoredNotices() |
|
769 | - { |
|
770 | - if ($user_id = get_current_user_id()) { |
|
771 | - // get notices for logged in user |
|
772 | - $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
773 | - return is_array($notices) ? $notices : array(); |
|
774 | - } |
|
775 | - if (EE_Session::isLoadedAndActive()) { |
|
776 | - // get notices for user currently engaged in a session |
|
777 | - $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
778 | - return is_array($session_data) ? $session_data : array(); |
|
779 | - } |
|
780 | - // get global notices and hope they apply to the current site visitor |
|
781 | - $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | - return is_array($notices) ? $notices : array(); |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * @param array $notices |
|
788 | - * @return bool |
|
789 | - * @throws InvalidArgumentException |
|
790 | - * @throws InvalidDataTypeException |
|
791 | - * @throws InvalidInterfaceException |
|
792 | - */ |
|
793 | - public static function storeNotices(array $notices) |
|
794 | - { |
|
795 | - if ($user_id = get_current_user_id()) { |
|
796 | - // store notices for logged in user |
|
797 | - return (bool) update_user_option( |
|
798 | - $user_id, |
|
799 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
800 | - $notices |
|
801 | - ); |
|
802 | - } |
|
803 | - if (EE_Session::isLoadedAndActive()) { |
|
804 | - // store notices for user currently engaged in a session |
|
805 | - return EE_Session::instance()->set_session_data( |
|
806 | - array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
807 | - ); |
|
808 | - } |
|
809 | - // store global notices and hope they apply to the same site visitor on the next request |
|
810 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * @return bool|TRUE |
|
816 | - * @throws InvalidArgumentException |
|
817 | - * @throws InvalidDataTypeException |
|
818 | - * @throws InvalidInterfaceException |
|
819 | - */ |
|
820 | - public static function clearNotices() |
|
821 | - { |
|
822 | - if ($user_id = get_current_user_id()) { |
|
823 | - // clear notices for logged in user |
|
824 | - return (bool) update_user_option( |
|
825 | - $user_id, |
|
826 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
827 | - array() |
|
828 | - ); |
|
829 | - } |
|
830 | - if (EE_Session::isLoadedAndActive()) { |
|
831 | - // clear notices for user currently engaged in a session |
|
832 | - return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
833 | - } |
|
834 | - // clear global notices and hope none belonged to some for some other site visitor |
|
835 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
836 | - } |
|
837 | - |
|
838 | - |
|
839 | - /** |
|
840 | - * saves notices to the db for retrieval on next request |
|
841 | - * |
|
842 | - * @return void |
|
843 | - * @throws InvalidArgumentException |
|
844 | - * @throws InvalidDataTypeException |
|
845 | - * @throws InvalidInterfaceException |
|
846 | - */ |
|
847 | - public static function stashNoticesBeforeRedirect() |
|
848 | - { |
|
849 | - EE_Error::get_notices(false, true); |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * compile all error or success messages into one string |
|
855 | - * |
|
856 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
857 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
858 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
859 | - * - ONLY do this just before redirecting |
|
860 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
861 | - * @return array |
|
862 | - * @throws InvalidArgumentException |
|
863 | - * @throws InvalidDataTypeException |
|
864 | - * @throws InvalidInterfaceException |
|
865 | - */ |
|
866 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
867 | - { |
|
868 | - $success_messages = ''; |
|
869 | - $attention_messages = ''; |
|
870 | - $error_messages = ''; |
|
871 | - // either save notices to the db |
|
872 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
873 | - self::$_espresso_notices = array_merge( |
|
874 | - EE_Error::getStoredNotices(), |
|
875 | - self::$_espresso_notices |
|
876 | - ); |
|
877 | - EE_Error::storeNotices(self::$_espresso_notices); |
|
878 | - return array(); |
|
879 | - } |
|
880 | - $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
881 | - // check for success messages |
|
882 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
883 | - // combine messages |
|
884 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
885 | - $print_scripts = true; |
|
886 | - } |
|
887 | - // check for attention messages |
|
888 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
889 | - // combine messages |
|
890 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
891 | - $print_scripts = true; |
|
892 | - } |
|
893 | - // check for error messages |
|
894 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
895 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
896 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
897 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
898 | - // combine messages |
|
899 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
900 | - $print_scripts = true; |
|
901 | - } |
|
902 | - if ($format_output) { |
|
903 | - $notices = EE_Error::formatNoticesOutput( |
|
904 | - $success_messages, |
|
905 | - $attention_messages, |
|
906 | - $error_messages |
|
907 | - ); |
|
908 | - } else { |
|
909 | - $notices = array( |
|
910 | - 'success' => $success_messages, |
|
911 | - 'attention' => $attention_messages, |
|
912 | - 'errors' => $error_messages, |
|
913 | - ); |
|
914 | - if ($remove_empty) { |
|
915 | - // remove empty notices |
|
916 | - foreach ($notices as $type => $notice) { |
|
917 | - if (empty($notice)) { |
|
918 | - unset($notices[$type]); |
|
919 | - } |
|
920 | - } |
|
921 | - } |
|
922 | - } |
|
923 | - if ($print_scripts) { |
|
924 | - self::_print_scripts(); |
|
925 | - } |
|
926 | - return $notices; |
|
927 | - } |
|
928 | - |
|
929 | - |
|
930 | - /** |
|
931 | - * @return bool |
|
932 | - * @throws InvalidArgumentException |
|
933 | - * @throws InvalidDataTypeException |
|
934 | - * @throws InvalidInterfaceException |
|
935 | - */ |
|
936 | - private static function combineExistingAndNewNotices() |
|
937 | - { |
|
938 | - $print_scripts = false; |
|
939 | - // grab any notices that have been previously saved |
|
940 | - $notices = EE_Error::getStoredNotices(); |
|
941 | - if (! empty($notices)) { |
|
942 | - foreach ($notices as $type => $notice) { |
|
943 | - if (is_array($notice) && ! empty($notice)) { |
|
944 | - // make sure that existing notice type is an array |
|
945 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
946 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
947 | - ? self::$_espresso_notices[ $type ] |
|
948 | - : array(); |
|
949 | - // add newly created notices to existing ones |
|
950 | - self::$_espresso_notices[ $type ] += $notice; |
|
951 | - $print_scripts = true; |
|
952 | - } |
|
953 | - } |
|
954 | - // now clear any stored notices |
|
955 | - EE_Error::clearNotices(); |
|
956 | - } |
|
957 | - return $print_scripts; |
|
958 | - } |
|
959 | - |
|
960 | - |
|
961 | - /** |
|
962 | - * @param string $success_messages |
|
963 | - * @param string $attention_messages |
|
964 | - * @param string $error_messages |
|
965 | - * @return string |
|
966 | - */ |
|
967 | - private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
968 | - { |
|
969 | - $notices = '<div id="espresso-notices">'; |
|
970 | - $close = is_admin() |
|
971 | - ? '' |
|
972 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
973 | - if ($success_messages !== '') { |
|
974 | - $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
975 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
976 | - //showMessage( $success_messages ); |
|
977 | - $notices .= '<div id="' . $css_id . '" ' |
|
978 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
979 | - . 'style="display:none;">' |
|
980 | - . '<p>' . $success_messages . '</p>' |
|
981 | - . $close |
|
982 | - . '</div>'; |
|
983 | - } |
|
984 | - if ($attention_messages !== '') { |
|
985 | - $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
986 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
987 | - //showMessage( $error_messages, TRUE ); |
|
988 | - $notices .= '<div id="' . $css_id . '" ' |
|
989 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
990 | - . 'style="display:none;">' |
|
991 | - . '<p>' . $attention_messages . '</p>' |
|
992 | - . $close |
|
993 | - . '</div>'; |
|
994 | - } |
|
995 | - if ($error_messages !== '') { |
|
996 | - $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
997 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
998 | - //showMessage( $error_messages, TRUE ); |
|
999 | - $notices .= '<div id="' . $css_id . '" ' |
|
1000 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
1001 | - . 'style="display:none;">' |
|
1002 | - . '<p>' . $error_messages . '</p>' |
|
1003 | - . $close |
|
1004 | - . '</div>'; |
|
1005 | - } |
|
1006 | - $notices .= '</div>'; |
|
1007 | - return $notices; |
|
1008 | - } |
|
1009 | - |
|
1010 | - |
|
1011 | - |
|
1012 | - /** |
|
1013 | - * _print_scripts |
|
1014 | - * |
|
1015 | - * @param bool $force_print |
|
1016 | - * @return string |
|
1017 | - */ |
|
1018 | - private static function _print_scripts($force_print = false) |
|
1019 | - { |
|
1020 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1021 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
1022 | - return ''; |
|
1023 | - } |
|
1024 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
1025 | - wp_enqueue_style('espresso_default'); |
|
1026 | - wp_enqueue_style('espresso_custom_css'); |
|
1027 | - wp_enqueue_script('ee_error_js'); |
|
1028 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
1029 | - } |
|
1030 | - } else { |
|
1031 | - return ' |
|
480 | + $output .= self::_print_scripts(true); |
|
481 | + if (defined('DOING_AJAX')) { |
|
482 | + echo wp_json_encode(array('error' => $output)); |
|
483 | + exit(); |
|
484 | + } |
|
485 | + echo $output; |
|
486 | + die(); |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * generate string from exception trace args |
|
493 | + * |
|
494 | + * @param array $arguments |
|
495 | + * @param bool $array |
|
496 | + * @return string |
|
497 | + */ |
|
498 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
499 | + { |
|
500 | + $arg_string = ''; |
|
501 | + if (! empty($arguments)) { |
|
502 | + $args = array(); |
|
503 | + foreach ($arguments as $arg) { |
|
504 | + if (! empty($arg)) { |
|
505 | + if (is_string($arg)) { |
|
506 | + $args[] = " '" . $arg . "'"; |
|
507 | + } elseif (is_array($arg)) { |
|
508 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
509 | + } elseif ($arg === null) { |
|
510 | + $args[] = ' NULL'; |
|
511 | + } elseif (is_bool($arg)) { |
|
512 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
513 | + } elseif (is_object($arg)) { |
|
514 | + $args[] = ' OBJECT ' . get_class($arg); |
|
515 | + } elseif (is_resource($arg)) { |
|
516 | + $args[] = get_resource_type($arg); |
|
517 | + } else { |
|
518 | + $args[] = $arg; |
|
519 | + } |
|
520 | + } |
|
521 | + } |
|
522 | + $arg_string = implode(', ', $args); |
|
523 | + } |
|
524 | + if ($array) { |
|
525 | + $arg_string .= ' )'; |
|
526 | + } |
|
527 | + return $arg_string; |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * add error message |
|
534 | + * |
|
535 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
536 | + * separate messages for user || dev |
|
537 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
538 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
539 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
540 | + * @return void |
|
541 | + */ |
|
542 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
543 | + { |
|
544 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
545 | + self::$_error_count++; |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
552 | + * adds an error |
|
553 | + * |
|
554 | + * @param string $msg |
|
555 | + * @param string $file |
|
556 | + * @param string $func |
|
557 | + * @param string $line |
|
558 | + * @throws EE_Error |
|
559 | + */ |
|
560 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
561 | + { |
|
562 | + if (WP_DEBUG) { |
|
563 | + throw new EE_Error($msg); |
|
564 | + } |
|
565 | + EE_Error::add_error($msg, $file, $func, $line); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * add success message |
|
572 | + * |
|
573 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
574 | + * separate messages for user || dev |
|
575 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
576 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
577 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
578 | + * @return void |
|
579 | + */ |
|
580 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
581 | + { |
|
582 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * add attention message |
|
589 | + * |
|
590 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
591 | + * separate messages for user || dev |
|
592 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
593 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
594 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
595 | + * @return void |
|
596 | + */ |
|
597 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
598 | + { |
|
599 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
600 | + } |
|
601 | + |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * @param string $type whether the message is for a success or error notification |
|
606 | + * @param string $msg the message to display to users or developers |
|
607 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
608 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
609 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
610 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
611 | + * @return void |
|
612 | + */ |
|
613 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
614 | + { |
|
615 | + if (empty($msg)) { |
|
616 | + EE_Error::doing_it_wrong( |
|
617 | + 'EE_Error::add_' . $type . '()', |
|
618 | + sprintf( |
|
619 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
620 | + 'event_espresso'), |
|
621 | + $type, |
|
622 | + $file, |
|
623 | + $line |
|
624 | + ), |
|
625 | + EVENT_ESPRESSO_VERSION |
|
626 | + ); |
|
627 | + } |
|
628 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
629 | + EE_Error::doing_it_wrong( |
|
630 | + 'EE_Error::add_error()', |
|
631 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
632 | + 'event_espresso'), |
|
633 | + EVENT_ESPRESSO_VERSION |
|
634 | + ); |
|
635 | + } |
|
636 | + // get separate user and developer messages if they exist |
|
637 | + $msg = explode('||', $msg); |
|
638 | + $user_msg = $msg[0]; |
|
639 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
640 | + /** |
|
641 | + * Do an action so other code can be triggered when a notice is created |
|
642 | + * |
|
643 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
644 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
645 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
646 | + * @param string $file file where error was generated |
|
647 | + * @param string $func function where error was generated |
|
648 | + * @param string $line line where error was generated |
|
649 | + */ |
|
650 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
651 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
652 | + // add notice if message exists |
|
653 | + if (! empty($msg)) { |
|
654 | + // get error code |
|
655 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
656 | + if (WP_DEBUG && $type === 'errors') { |
|
657 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
658 | + } |
|
659 | + // add notice. Index by code if it's not blank |
|
660 | + if ($notice_code) { |
|
661 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
662 | + } else { |
|
663 | + self::$_espresso_notices[$type][] = $msg; |
|
664 | + } |
|
665 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
666 | + } |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * in some case it may be necessary to overwrite the existing success messages |
|
672 | + * |
|
673 | + * @return void |
|
674 | + */ |
|
675 | + public static function overwrite_success() |
|
676 | + { |
|
677 | + self::$_espresso_notices['success'] = false; |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * in some case it may be necessary to overwrite the existing attention messages |
|
684 | + * |
|
685 | + * @return void |
|
686 | + */ |
|
687 | + public static function overwrite_attention() |
|
688 | + { |
|
689 | + self::$_espresso_notices['attention'] = false; |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * in some case it may be necessary to overwrite the existing error messages |
|
696 | + * |
|
697 | + * @return void |
|
698 | + */ |
|
699 | + public static function overwrite_errors() |
|
700 | + { |
|
701 | + self::$_espresso_notices['errors'] = false; |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * @return void |
|
708 | + */ |
|
709 | + public static function reset_notices() |
|
710 | + { |
|
711 | + self::$_espresso_notices['success'] = false; |
|
712 | + self::$_espresso_notices['attention'] = false; |
|
713 | + self::$_espresso_notices['errors'] = false; |
|
714 | + } |
|
715 | + |
|
716 | + |
|
717 | + |
|
718 | + /** |
|
719 | + * @return int |
|
720 | + */ |
|
721 | + public static function has_notices() |
|
722 | + { |
|
723 | + $has_notices = 0; |
|
724 | + // check for success messages |
|
725 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
726 | + ? 3 |
|
727 | + : $has_notices; |
|
728 | + // check for attention messages |
|
729 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
730 | + ? 2 |
|
731 | + : $has_notices; |
|
732 | + // check for error messages |
|
733 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
734 | + ? 1 |
|
735 | + : $has_notices; |
|
736 | + return $has_notices; |
|
737 | + } |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
742 | + * |
|
743 | + * @since 4.9.0 |
|
744 | + * @return array |
|
745 | + */ |
|
746 | + public static function get_vanilla_notices() |
|
747 | + { |
|
748 | + return array( |
|
749 | + 'success' => isset(self::$_espresso_notices['success']) |
|
750 | + ? self::$_espresso_notices['success'] |
|
751 | + : array(), |
|
752 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
753 | + ? self::$_espresso_notices['attention'] |
|
754 | + : array(), |
|
755 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
756 | + ? self::$_espresso_notices['errors'] |
|
757 | + : array(), |
|
758 | + ); |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * @return array |
|
764 | + * @throws InvalidArgumentException |
|
765 | + * @throws InvalidDataTypeException |
|
766 | + * @throws InvalidInterfaceException |
|
767 | + */ |
|
768 | + public static function getStoredNotices() |
|
769 | + { |
|
770 | + if ($user_id = get_current_user_id()) { |
|
771 | + // get notices for logged in user |
|
772 | + $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
773 | + return is_array($notices) ? $notices : array(); |
|
774 | + } |
|
775 | + if (EE_Session::isLoadedAndActive()) { |
|
776 | + // get notices for user currently engaged in a session |
|
777 | + $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
778 | + return is_array($session_data) ? $session_data : array(); |
|
779 | + } |
|
780 | + // get global notices and hope they apply to the current site visitor |
|
781 | + $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | + return is_array($notices) ? $notices : array(); |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * @param array $notices |
|
788 | + * @return bool |
|
789 | + * @throws InvalidArgumentException |
|
790 | + * @throws InvalidDataTypeException |
|
791 | + * @throws InvalidInterfaceException |
|
792 | + */ |
|
793 | + public static function storeNotices(array $notices) |
|
794 | + { |
|
795 | + if ($user_id = get_current_user_id()) { |
|
796 | + // store notices for logged in user |
|
797 | + return (bool) update_user_option( |
|
798 | + $user_id, |
|
799 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
800 | + $notices |
|
801 | + ); |
|
802 | + } |
|
803 | + if (EE_Session::isLoadedAndActive()) { |
|
804 | + // store notices for user currently engaged in a session |
|
805 | + return EE_Session::instance()->set_session_data( |
|
806 | + array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
807 | + ); |
|
808 | + } |
|
809 | + // store global notices and hope they apply to the same site visitor on the next request |
|
810 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * @return bool|TRUE |
|
816 | + * @throws InvalidArgumentException |
|
817 | + * @throws InvalidDataTypeException |
|
818 | + * @throws InvalidInterfaceException |
|
819 | + */ |
|
820 | + public static function clearNotices() |
|
821 | + { |
|
822 | + if ($user_id = get_current_user_id()) { |
|
823 | + // clear notices for logged in user |
|
824 | + return (bool) update_user_option( |
|
825 | + $user_id, |
|
826 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
827 | + array() |
|
828 | + ); |
|
829 | + } |
|
830 | + if (EE_Session::isLoadedAndActive()) { |
|
831 | + // clear notices for user currently engaged in a session |
|
832 | + return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
833 | + } |
|
834 | + // clear global notices and hope none belonged to some for some other site visitor |
|
835 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
836 | + } |
|
837 | + |
|
838 | + |
|
839 | + /** |
|
840 | + * saves notices to the db for retrieval on next request |
|
841 | + * |
|
842 | + * @return void |
|
843 | + * @throws InvalidArgumentException |
|
844 | + * @throws InvalidDataTypeException |
|
845 | + * @throws InvalidInterfaceException |
|
846 | + */ |
|
847 | + public static function stashNoticesBeforeRedirect() |
|
848 | + { |
|
849 | + EE_Error::get_notices(false, true); |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * compile all error or success messages into one string |
|
855 | + * |
|
856 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
857 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
858 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
859 | + * - ONLY do this just before redirecting |
|
860 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
861 | + * @return array |
|
862 | + * @throws InvalidArgumentException |
|
863 | + * @throws InvalidDataTypeException |
|
864 | + * @throws InvalidInterfaceException |
|
865 | + */ |
|
866 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
867 | + { |
|
868 | + $success_messages = ''; |
|
869 | + $attention_messages = ''; |
|
870 | + $error_messages = ''; |
|
871 | + // either save notices to the db |
|
872 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
873 | + self::$_espresso_notices = array_merge( |
|
874 | + EE_Error::getStoredNotices(), |
|
875 | + self::$_espresso_notices |
|
876 | + ); |
|
877 | + EE_Error::storeNotices(self::$_espresso_notices); |
|
878 | + return array(); |
|
879 | + } |
|
880 | + $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
881 | + // check for success messages |
|
882 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
883 | + // combine messages |
|
884 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
885 | + $print_scripts = true; |
|
886 | + } |
|
887 | + // check for attention messages |
|
888 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
889 | + // combine messages |
|
890 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
891 | + $print_scripts = true; |
|
892 | + } |
|
893 | + // check for error messages |
|
894 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
895 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
896 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
897 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
898 | + // combine messages |
|
899 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
900 | + $print_scripts = true; |
|
901 | + } |
|
902 | + if ($format_output) { |
|
903 | + $notices = EE_Error::formatNoticesOutput( |
|
904 | + $success_messages, |
|
905 | + $attention_messages, |
|
906 | + $error_messages |
|
907 | + ); |
|
908 | + } else { |
|
909 | + $notices = array( |
|
910 | + 'success' => $success_messages, |
|
911 | + 'attention' => $attention_messages, |
|
912 | + 'errors' => $error_messages, |
|
913 | + ); |
|
914 | + if ($remove_empty) { |
|
915 | + // remove empty notices |
|
916 | + foreach ($notices as $type => $notice) { |
|
917 | + if (empty($notice)) { |
|
918 | + unset($notices[$type]); |
|
919 | + } |
|
920 | + } |
|
921 | + } |
|
922 | + } |
|
923 | + if ($print_scripts) { |
|
924 | + self::_print_scripts(); |
|
925 | + } |
|
926 | + return $notices; |
|
927 | + } |
|
928 | + |
|
929 | + |
|
930 | + /** |
|
931 | + * @return bool |
|
932 | + * @throws InvalidArgumentException |
|
933 | + * @throws InvalidDataTypeException |
|
934 | + * @throws InvalidInterfaceException |
|
935 | + */ |
|
936 | + private static function combineExistingAndNewNotices() |
|
937 | + { |
|
938 | + $print_scripts = false; |
|
939 | + // grab any notices that have been previously saved |
|
940 | + $notices = EE_Error::getStoredNotices(); |
|
941 | + if (! empty($notices)) { |
|
942 | + foreach ($notices as $type => $notice) { |
|
943 | + if (is_array($notice) && ! empty($notice)) { |
|
944 | + // make sure that existing notice type is an array |
|
945 | + self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
946 | + && ! empty(self::$_espresso_notices[ $type ]) |
|
947 | + ? self::$_espresso_notices[ $type ] |
|
948 | + : array(); |
|
949 | + // add newly created notices to existing ones |
|
950 | + self::$_espresso_notices[ $type ] += $notice; |
|
951 | + $print_scripts = true; |
|
952 | + } |
|
953 | + } |
|
954 | + // now clear any stored notices |
|
955 | + EE_Error::clearNotices(); |
|
956 | + } |
|
957 | + return $print_scripts; |
|
958 | + } |
|
959 | + |
|
960 | + |
|
961 | + /** |
|
962 | + * @param string $success_messages |
|
963 | + * @param string $attention_messages |
|
964 | + * @param string $error_messages |
|
965 | + * @return string |
|
966 | + */ |
|
967 | + private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
968 | + { |
|
969 | + $notices = '<div id="espresso-notices">'; |
|
970 | + $close = is_admin() |
|
971 | + ? '' |
|
972 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
973 | + if ($success_messages !== '') { |
|
974 | + $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
975 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
976 | + //showMessage( $success_messages ); |
|
977 | + $notices .= '<div id="' . $css_id . '" ' |
|
978 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
979 | + . 'style="display:none;">' |
|
980 | + . '<p>' . $success_messages . '</p>' |
|
981 | + . $close |
|
982 | + . '</div>'; |
|
983 | + } |
|
984 | + if ($attention_messages !== '') { |
|
985 | + $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
986 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
987 | + //showMessage( $error_messages, TRUE ); |
|
988 | + $notices .= '<div id="' . $css_id . '" ' |
|
989 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
990 | + . 'style="display:none;">' |
|
991 | + . '<p>' . $attention_messages . '</p>' |
|
992 | + . $close |
|
993 | + . '</div>'; |
|
994 | + } |
|
995 | + if ($error_messages !== '') { |
|
996 | + $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
997 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
998 | + //showMessage( $error_messages, TRUE ); |
|
999 | + $notices .= '<div id="' . $css_id . '" ' |
|
1000 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
1001 | + . 'style="display:none;">' |
|
1002 | + . '<p>' . $error_messages . '</p>' |
|
1003 | + . $close |
|
1004 | + . '</div>'; |
|
1005 | + } |
|
1006 | + $notices .= '</div>'; |
|
1007 | + return $notices; |
|
1008 | + } |
|
1009 | + |
|
1010 | + |
|
1011 | + |
|
1012 | + /** |
|
1013 | + * _print_scripts |
|
1014 | + * |
|
1015 | + * @param bool $force_print |
|
1016 | + * @return string |
|
1017 | + */ |
|
1018 | + private static function _print_scripts($force_print = false) |
|
1019 | + { |
|
1020 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1021 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
1022 | + return ''; |
|
1023 | + } |
|
1024 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
1025 | + wp_enqueue_style('espresso_default'); |
|
1026 | + wp_enqueue_style('espresso_custom_css'); |
|
1027 | + wp_enqueue_script('ee_error_js'); |
|
1028 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
1029 | + } |
|
1030 | + } else { |
|
1031 | + return ' |
|
1032 | 1032 | <script> |
1033 | 1033 | /* <![CDATA[ */ |
1034 | 1034 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -1038,223 +1038,223 @@ discard block |
||
1038 | 1038 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
1039 | 1039 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
1040 | 1040 | '; |
1041 | - } |
|
1042 | - return ''; |
|
1043 | - } |
|
1044 | - |
|
1045 | - |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * @return void |
|
1049 | - */ |
|
1050 | - public static function enqueue_error_scripts() |
|
1051 | - { |
|
1052 | - self::_print_scripts(); |
|
1053 | - } |
|
1054 | - |
|
1055 | - |
|
1056 | - |
|
1057 | - /** |
|
1058 | - * create error code from filepath, function name, |
|
1059 | - * and line number where exception or error was thrown |
|
1060 | - * |
|
1061 | - * @param string $file |
|
1062 | - * @param string $func |
|
1063 | - * @param string $line |
|
1064 | - * @return string |
|
1065 | - */ |
|
1066 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
1067 | - { |
|
1068 | - $file = explode('.', basename($file)); |
|
1069 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
1070 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
1071 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
1072 | - return $error_code; |
|
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - |
|
1077 | - /** |
|
1078 | - * write exception details to log file |
|
1079 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
1080 | - * |
|
1081 | - * @param int $time |
|
1082 | - * @param array $ex |
|
1083 | - * @param bool $clear |
|
1084 | - * @return void |
|
1085 | - */ |
|
1086 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
1087 | - { |
|
1088 | - if (empty($ex)) { |
|
1089 | - return; |
|
1090 | - } |
|
1091 | - if (! $time) { |
|
1092 | - $time = time(); |
|
1093 | - } |
|
1094 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
1095 | - . PHP_EOL; |
|
1096 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
1097 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1098 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
1099 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
1100 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1101 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1102 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
1103 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
1104 | - . PHP_EOL; |
|
1105 | - try { |
|
1106 | - error_log($exception_log); |
|
1107 | - } catch (EE_Error $e) { |
|
1108 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
1109 | - 'event_espresso'), $e->getMessage())); |
|
1110 | - } |
|
1111 | - } |
|
1112 | - |
|
1113 | - |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1117 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1118 | - * but the code execution is done in a manner that could lead to unexpected results |
|
1119 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
1120 | - * A good test for knowing whether to use this method is: |
|
1121 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1122 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1123 | - * 2. If this is loaded before something else, it won't break anything, |
|
1124 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1125 | - * |
|
1126 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1127 | - * @param string $function The function that was called |
|
1128 | - * @param string $message A message explaining what has been done incorrectly |
|
1129 | - * @param string $version The version of Event Espresso where the error was added |
|
1130 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1131 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
1132 | - * but not have any notices appear until a later version. This allows developers |
|
1133 | - * extra time to update their code before notices appear. |
|
1134 | - * @param int $error_type |
|
1135 | - */ |
|
1136 | - public static function doing_it_wrong( |
|
1137 | - $function, |
|
1138 | - $message, |
|
1139 | - $version, |
|
1140 | - $applies_when = '', |
|
1141 | - $error_type = null |
|
1142 | - ) { |
|
1143 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1144 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1145 | - } |
|
1146 | - } |
|
1147 | - |
|
1148 | - |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
1152 | - * |
|
1153 | - * @return array { |
|
1154 | - * @type array $success all the success messages |
|
1155 | - * @type array $errors all the error messages |
|
1156 | - * @type array $attention all the attention messages |
|
1157 | - * } |
|
1158 | - */ |
|
1159 | - public static function get_raw_notices() |
|
1160 | - { |
|
1161 | - return self::$_espresso_notices; |
|
1162 | - } |
|
1163 | - |
|
1164 | - |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * @deprecated 4.9.27 |
|
1168 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1169 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1170 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1171 | - * @return void |
|
1172 | - * @throws InvalidDataTypeException |
|
1173 | - */ |
|
1174 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1175 | - { |
|
1176 | - new PersistentAdminNotice( |
|
1177 | - $pan_name, |
|
1178 | - $pan_message, |
|
1179 | - $force_update |
|
1180 | - ); |
|
1181 | - EE_Error::doing_it_wrong( |
|
1182 | - __METHOD__, |
|
1183 | - sprintf( |
|
1184 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1185 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1186 | - ), |
|
1187 | - '4.9.27' |
|
1188 | - ); |
|
1189 | - } |
|
1190 | - |
|
1191 | - |
|
1192 | - |
|
1193 | - /** |
|
1194 | - * @deprecated 4.9.27 |
|
1195 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1196 | - * @param bool $purge |
|
1197 | - * @param bool $return |
|
1198 | - * @throws DomainException |
|
1199 | - * @throws InvalidInterfaceException |
|
1200 | - * @throws InvalidDataTypeException |
|
1201 | - * @throws ServiceNotFoundException |
|
1202 | - * @throws InvalidArgumentException |
|
1203 | - */ |
|
1204 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1205 | - { |
|
1206 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1207 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1208 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1209 | - ); |
|
1210 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1211 | - EE_Error::doing_it_wrong( |
|
1212 | - __METHOD__, |
|
1213 | - sprintf( |
|
1214 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1215 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1216 | - ), |
|
1217 | - '4.9.27' |
|
1218 | - ); |
|
1219 | - } |
|
1220 | - |
|
1221 | - |
|
1222 | - |
|
1223 | - /** |
|
1224 | - * @deprecated 4.9.27 |
|
1225 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1226 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1227 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
1228 | - */ |
|
1229 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1230 | - { |
|
1231 | - EE_Error::doing_it_wrong( |
|
1232 | - __METHOD__, |
|
1233 | - sprintf( |
|
1234 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1235 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1236 | - ), |
|
1237 | - '4.9.27' |
|
1238 | - ); |
|
1239 | - } |
|
1240 | - |
|
1241 | - |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * @deprecated 4.9.27 |
|
1245 | - * @param string $return_url |
|
1246 | - */ |
|
1247 | - public static function get_persistent_admin_notices($return_url = '') |
|
1248 | - { |
|
1249 | - EE_Error::doing_it_wrong( |
|
1250 | - __METHOD__, |
|
1251 | - sprintf( |
|
1252 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1253 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1254 | - ), |
|
1255 | - '4.9.27' |
|
1256 | - ); |
|
1257 | - } |
|
1041 | + } |
|
1042 | + return ''; |
|
1043 | + } |
|
1044 | + |
|
1045 | + |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * @return void |
|
1049 | + */ |
|
1050 | + public static function enqueue_error_scripts() |
|
1051 | + { |
|
1052 | + self::_print_scripts(); |
|
1053 | + } |
|
1054 | + |
|
1055 | + |
|
1056 | + |
|
1057 | + /** |
|
1058 | + * create error code from filepath, function name, |
|
1059 | + * and line number where exception or error was thrown |
|
1060 | + * |
|
1061 | + * @param string $file |
|
1062 | + * @param string $func |
|
1063 | + * @param string $line |
|
1064 | + * @return string |
|
1065 | + */ |
|
1066 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
1067 | + { |
|
1068 | + $file = explode('.', basename($file)); |
|
1069 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
1070 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
1071 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
1072 | + return $error_code; |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + |
|
1077 | + /** |
|
1078 | + * write exception details to log file |
|
1079 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
1080 | + * |
|
1081 | + * @param int $time |
|
1082 | + * @param array $ex |
|
1083 | + * @param bool $clear |
|
1084 | + * @return void |
|
1085 | + */ |
|
1086 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
1087 | + { |
|
1088 | + if (empty($ex)) { |
|
1089 | + return; |
|
1090 | + } |
|
1091 | + if (! $time) { |
|
1092 | + $time = time(); |
|
1093 | + } |
|
1094 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
1095 | + . PHP_EOL; |
|
1096 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
1097 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1098 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
1099 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
1100 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1101 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1102 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
1103 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
1104 | + . PHP_EOL; |
|
1105 | + try { |
|
1106 | + error_log($exception_log); |
|
1107 | + } catch (EE_Error $e) { |
|
1108 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
1109 | + 'event_espresso'), $e->getMessage())); |
|
1110 | + } |
|
1111 | + } |
|
1112 | + |
|
1113 | + |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1117 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1118 | + * but the code execution is done in a manner that could lead to unexpected results |
|
1119 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
1120 | + * A good test for knowing whether to use this method is: |
|
1121 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1122 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1123 | + * 2. If this is loaded before something else, it won't break anything, |
|
1124 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1125 | + * |
|
1126 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1127 | + * @param string $function The function that was called |
|
1128 | + * @param string $message A message explaining what has been done incorrectly |
|
1129 | + * @param string $version The version of Event Espresso where the error was added |
|
1130 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1131 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
1132 | + * but not have any notices appear until a later version. This allows developers |
|
1133 | + * extra time to update their code before notices appear. |
|
1134 | + * @param int $error_type |
|
1135 | + */ |
|
1136 | + public static function doing_it_wrong( |
|
1137 | + $function, |
|
1138 | + $message, |
|
1139 | + $version, |
|
1140 | + $applies_when = '', |
|
1141 | + $error_type = null |
|
1142 | + ) { |
|
1143 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1144 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1145 | + } |
|
1146 | + } |
|
1147 | + |
|
1148 | + |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
1152 | + * |
|
1153 | + * @return array { |
|
1154 | + * @type array $success all the success messages |
|
1155 | + * @type array $errors all the error messages |
|
1156 | + * @type array $attention all the attention messages |
|
1157 | + * } |
|
1158 | + */ |
|
1159 | + public static function get_raw_notices() |
|
1160 | + { |
|
1161 | + return self::$_espresso_notices; |
|
1162 | + } |
|
1163 | + |
|
1164 | + |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * @deprecated 4.9.27 |
|
1168 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1169 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1170 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1171 | + * @return void |
|
1172 | + * @throws InvalidDataTypeException |
|
1173 | + */ |
|
1174 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1175 | + { |
|
1176 | + new PersistentAdminNotice( |
|
1177 | + $pan_name, |
|
1178 | + $pan_message, |
|
1179 | + $force_update |
|
1180 | + ); |
|
1181 | + EE_Error::doing_it_wrong( |
|
1182 | + __METHOD__, |
|
1183 | + sprintf( |
|
1184 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1185 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1186 | + ), |
|
1187 | + '4.9.27' |
|
1188 | + ); |
|
1189 | + } |
|
1190 | + |
|
1191 | + |
|
1192 | + |
|
1193 | + /** |
|
1194 | + * @deprecated 4.9.27 |
|
1195 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1196 | + * @param bool $purge |
|
1197 | + * @param bool $return |
|
1198 | + * @throws DomainException |
|
1199 | + * @throws InvalidInterfaceException |
|
1200 | + * @throws InvalidDataTypeException |
|
1201 | + * @throws ServiceNotFoundException |
|
1202 | + * @throws InvalidArgumentException |
|
1203 | + */ |
|
1204 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1205 | + { |
|
1206 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1207 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1208 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1209 | + ); |
|
1210 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1211 | + EE_Error::doing_it_wrong( |
|
1212 | + __METHOD__, |
|
1213 | + sprintf( |
|
1214 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1215 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1216 | + ), |
|
1217 | + '4.9.27' |
|
1218 | + ); |
|
1219 | + } |
|
1220 | + |
|
1221 | + |
|
1222 | + |
|
1223 | + /** |
|
1224 | + * @deprecated 4.9.27 |
|
1225 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1226 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1227 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
1228 | + */ |
|
1229 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1230 | + { |
|
1231 | + EE_Error::doing_it_wrong( |
|
1232 | + __METHOD__, |
|
1233 | + sprintf( |
|
1234 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1235 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1236 | + ), |
|
1237 | + '4.9.27' |
|
1238 | + ); |
|
1239 | + } |
|
1240 | + |
|
1241 | + |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * @deprecated 4.9.27 |
|
1245 | + * @param string $return_url |
|
1246 | + */ |
|
1247 | + public static function get_persistent_admin_notices($return_url = '') |
|
1248 | + { |
|
1249 | + EE_Error::doing_it_wrong( |
|
1250 | + __METHOD__, |
|
1251 | + sprintf( |
|
1252 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1253 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1254 | + ), |
|
1255 | + '4.9.27' |
|
1256 | + ); |
|
1257 | + } |
|
1258 | 1258 | |
1259 | 1259 | |
1260 | 1260 | |
@@ -1269,27 +1269,27 @@ discard block |
||
1269 | 1269 | */ |
1270 | 1270 | function espresso_error_enqueue_scripts() |
1271 | 1271 | { |
1272 | - // js for error handling |
|
1273 | - wp_register_script( |
|
1274 | - 'espresso_core', |
|
1275 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1276 | - array('jquery'), |
|
1277 | - EVENT_ESPRESSO_VERSION, |
|
1278 | - false |
|
1279 | - ); |
|
1280 | - wp_register_script( |
|
1281 | - 'ee_error_js', |
|
1282 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1283 | - array('espresso_core'), |
|
1284 | - EVENT_ESPRESSO_VERSION, |
|
1285 | - false |
|
1286 | - ); |
|
1272 | + // js for error handling |
|
1273 | + wp_register_script( |
|
1274 | + 'espresso_core', |
|
1275 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1276 | + array('jquery'), |
|
1277 | + EVENT_ESPRESSO_VERSION, |
|
1278 | + false |
|
1279 | + ); |
|
1280 | + wp_register_script( |
|
1281 | + 'ee_error_js', |
|
1282 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1283 | + array('espresso_core'), |
|
1284 | + EVENT_ESPRESSO_VERSION, |
|
1285 | + false |
|
1286 | + ); |
|
1287 | 1287 | } |
1288 | 1288 | |
1289 | 1289 | if (is_admin()) { |
1290 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1290 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1291 | 1291 | } else { |
1292 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1292 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 |
@@ -102,14 +102,14 @@ discard block |
||
102 | 102 | default : |
103 | 103 | $to = get_option('admin_email'); |
104 | 104 | } |
105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
105 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
106 | 106 | $msg = EE_Error::_format_error($type, $message, $file, $line); |
107 | 107 | if (function_exists('wp_mail')) { |
108 | 108 | add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
109 | 109 | wp_mail($to, $subject, $msg); |
110 | 110 | } |
111 | 111 | echo '<div id="message" class="espresso-notices error"><p>'; |
112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
112 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
113 | 113 | echo '<br /></p></div>'; |
114 | 114 | } |
115 | 115 | |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | } |
335 | 335 | </style> |
336 | 336 | <div id="ee-error-message" class="error">'; |
337 | - if (! WP_DEBUG) { |
|
337 | + if ( ! WP_DEBUG) { |
|
338 | 338 | $output .= ' |
339 | 339 | <p>'; |
340 | 340 | } |
@@ -393,14 +393,14 @@ discard block |
||
393 | 393 | $class_dsply = ! empty($class) ? $class : ' '; |
394 | 394 | $type_dsply = ! empty($type) ? $type : ' '; |
395 | 395 | $function_dsply = ! empty($function) ? $function : ' '; |
396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
396 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
397 | 397 | $trace_details .= ' |
398 | 398 | <tr> |
399 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
400 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
401 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
402 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
403 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
399 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
400 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
401 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
402 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
403 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
404 | 404 | </tr>'; |
405 | 405 | } |
406 | 406 | $trace_details .= ' |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | } |
410 | 410 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
411 | 411 | // add generic non-identifying messages for non-privileged users |
412 | - if (! WP_DEBUG) { |
|
412 | + if ( ! WP_DEBUG) { |
|
413 | 413 | $output .= '<span class="ee-error-user-msg-spn">' |
414 | 414 | . trim($ex['msg']) |
415 | 415 | . '</span> <sup>' |
@@ -451,14 +451,14 @@ discard block |
||
451 | 451 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
452 | 452 | ' |
453 | 453 | . $trace_details; |
454 | - if (! empty($class)) { |
|
454 | + if ( ! empty($class)) { |
|
455 | 455 | $output .= ' |
456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
458 | 458 | <h3>Class Details</h3>'; |
459 | 459 | $a = new ReflectionClass($class); |
460 | 460 | $output .= ' |
461 | - <pre>' . $a . '</pre> |
|
461 | + <pre>' . $a.'</pre> |
|
462 | 462 | </div> |
463 | 463 | </div>'; |
464 | 464 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | } |
472 | 472 | // remove last linebreak |
473 | 473 | $output = substr($output, 0, -6); |
474 | - if (! WP_DEBUG) { |
|
474 | + if ( ! WP_DEBUG) { |
|
475 | 475 | $output .= ' |
476 | 476 | </p>'; |
477 | 477 | } |
@@ -498,20 +498,20 @@ discard block |
||
498 | 498 | private function _convert_args_to_string($arguments = array(), $array = false) |
499 | 499 | { |
500 | 500 | $arg_string = ''; |
501 | - if (! empty($arguments)) { |
|
501 | + if ( ! empty($arguments)) { |
|
502 | 502 | $args = array(); |
503 | 503 | foreach ($arguments as $arg) { |
504 | - if (! empty($arg)) { |
|
504 | + if ( ! empty($arg)) { |
|
505 | 505 | if (is_string($arg)) { |
506 | - $args[] = " '" . $arg . "'"; |
|
506 | + $args[] = " '".$arg."'"; |
|
507 | 507 | } elseif (is_array($arg)) { |
508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
508 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true); |
|
509 | 509 | } elseif ($arg === null) { |
510 | 510 | $args[] = ' NULL'; |
511 | 511 | } elseif (is_bool($arg)) { |
512 | 512 | $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
513 | 513 | } elseif (is_object($arg)) { |
514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
514 | + $args[] = ' OBJECT '.get_class($arg); |
|
515 | 515 | } elseif (is_resource($arg)) { |
516 | 516 | $args[] = get_resource_type($arg); |
517 | 517 | } else { |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | { |
615 | 615 | if (empty($msg)) { |
616 | 616 | EE_Error::doing_it_wrong( |
617 | - 'EE_Error::add_' . $type . '()', |
|
617 | + 'EE_Error::add_'.$type.'()', |
|
618 | 618 | sprintf( |
619 | 619 | __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
620 | 620 | 'event_espresso'), |
@@ -650,11 +650,11 @@ discard block |
||
650 | 650 | do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
651 | 651 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
652 | 652 | // add notice if message exists |
653 | - if (! empty($msg)) { |
|
653 | + if ( ! empty($msg)) { |
|
654 | 654 | // get error code |
655 | 655 | $notice_code = EE_Error::generate_error_code($file, $func, $line); |
656 | 656 | if (WP_DEBUG && $type === 'errors') { |
657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
657 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
658 | 658 | } |
659 | 659 | // add notice. Index by code if it's not blank |
660 | 660 | if ($notice_code) { |
@@ -882,13 +882,13 @@ discard block |
||
882 | 882 | if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
883 | 883 | // combine messages |
884 | 884 | $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
885 | - $print_scripts = true; |
|
885 | + $print_scripts = true; |
|
886 | 886 | } |
887 | 887 | // check for attention messages |
888 | 888 | if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
889 | 889 | // combine messages |
890 | 890 | $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
891 | - $print_scripts = true; |
|
891 | + $print_scripts = true; |
|
892 | 892 | } |
893 | 893 | // check for error messages |
894 | 894 | if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | : __('An error has occurred:<br />', 'event_espresso'); |
898 | 898 | // combine messages |
899 | 899 | $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
900 | - $print_scripts = true; |
|
900 | + $print_scripts = true; |
|
901 | 901 | } |
902 | 902 | if ($format_output) { |
903 | 903 | $notices = EE_Error::formatNoticesOutput( |
@@ -938,16 +938,16 @@ discard block |
||
938 | 938 | $print_scripts = false; |
939 | 939 | // grab any notices that have been previously saved |
940 | 940 | $notices = EE_Error::getStoredNotices(); |
941 | - if (! empty($notices)) { |
|
941 | + if ( ! empty($notices)) { |
|
942 | 942 | foreach ($notices as $type => $notice) { |
943 | 943 | if (is_array($notice) && ! empty($notice)) { |
944 | 944 | // make sure that existing notice type is an array |
945 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
946 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
947 | - ? self::$_espresso_notices[ $type ] |
|
945 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
946 | + && ! empty(self::$_espresso_notices[$type]) |
|
947 | + ? self::$_espresso_notices[$type] |
|
948 | 948 | : array(); |
949 | 949 | // add newly created notices to existing ones |
950 | - self::$_espresso_notices[ $type ] += $notice; |
|
950 | + self::$_espresso_notices[$type] += $notice; |
|
951 | 951 | $print_scripts = true; |
952 | 952 | } |
953 | 953 | } |
@@ -974,10 +974,10 @@ discard block |
||
974 | 974 | $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
975 | 975 | $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
976 | 976 | //showMessage( $success_messages ); |
977 | - $notices .= '<div id="' . $css_id . '" ' |
|
978 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
977 | + $notices .= '<div id="'.$css_id.'" ' |
|
978 | + . 'class="espresso-notices '.$css_class.'" ' |
|
979 | 979 | . 'style="display:none;">' |
980 | - . '<p>' . $success_messages . '</p>' |
|
980 | + . '<p>'.$success_messages.'</p>' |
|
981 | 981 | . $close |
982 | 982 | . '</div>'; |
983 | 983 | } |
@@ -985,10 +985,10 @@ discard block |
||
985 | 985 | $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
986 | 986 | $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
987 | 987 | //showMessage( $error_messages, TRUE ); |
988 | - $notices .= '<div id="' . $css_id . '" ' |
|
989 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
988 | + $notices .= '<div id="'.$css_id.'" ' |
|
989 | + . 'class="espresso-notices '.$css_class.'" ' |
|
990 | 990 | . 'style="display:none;">' |
991 | - . '<p>' . $attention_messages . '</p>' |
|
991 | + . '<p>'.$attention_messages.'</p>' |
|
992 | 992 | . $close |
993 | 993 | . '</div>'; |
994 | 994 | } |
@@ -996,10 +996,10 @@ discard block |
||
996 | 996 | $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
997 | 997 | $css_class = is_admin() ? 'error' : 'error fade-away'; |
998 | 998 | //showMessage( $error_messages, TRUE ); |
999 | - $notices .= '<div id="' . $css_id . '" ' |
|
1000 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
999 | + $notices .= '<div id="'.$css_id.'" ' |
|
1000 | + . 'class="espresso-notices '.$css_class.'" ' |
|
1001 | 1001 | . 'style="display:none;">' |
1002 | - . '<p>' . $error_messages . '</p>' |
|
1002 | + . '<p>'.$error_messages.'</p>' |
|
1003 | 1003 | . $close |
1004 | 1004 | . '</div>'; |
1005 | 1005 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | */ |
1018 | 1018 | private static function _print_scripts($force_print = false) |
1019 | 1019 | { |
1020 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1020 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1021 | 1021 | if (wp_script_is('ee_error_js', 'enqueued')) { |
1022 | 1022 | return ''; |
1023 | 1023 | } |
@@ -1031,12 +1031,12 @@ discard block |
||
1031 | 1031 | return ' |
1032 | 1032 | <script> |
1033 | 1033 | /* <![CDATA[ */ |
1034 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
1034 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
1035 | 1035 | /* ]]> */ |
1036 | 1036 | </script> |
1037 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
1038 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
1039 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
1037 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
1038 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
1039 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
1040 | 1040 | '; |
1041 | 1041 | } |
1042 | 1042 | return ''; |
@@ -1067,8 +1067,8 @@ discard block |
||
1067 | 1067 | { |
1068 | 1068 | $file = explode('.', basename($file)); |
1069 | 1069 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
1070 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
1071 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
1070 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
1071 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
1072 | 1072 | return $error_code; |
1073 | 1073 | } |
1074 | 1074 | |
@@ -1088,18 +1088,18 @@ discard block |
||
1088 | 1088 | if (empty($ex)) { |
1089 | 1089 | return; |
1090 | 1090 | } |
1091 | - if (! $time) { |
|
1091 | + if ( ! $time) { |
|
1092 | 1092 | $time = time(); |
1093 | 1093 | } |
1094 | 1094 | $exception_log = '----------------------------------------------------------------------------------------' |
1095 | 1095 | . PHP_EOL; |
1096 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
1097 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1098 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
1099 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
1100 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1101 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1102 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
1096 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
1097 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
1098 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
1099 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
1100 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
1101 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
1102 | + $exception_log .= $ex['string'].PHP_EOL; |
|
1103 | 1103 | $exception_log .= '----------------------------------------------------------------------------------------' |
1104 | 1104 | . PHP_EOL; |
1105 | 1105 | try { |
@@ -1272,14 +1272,14 @@ discard block |
||
1272 | 1272 | // js for error handling |
1273 | 1273 | wp_register_script( |
1274 | 1274 | 'espresso_core', |
1275 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1275 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
1276 | 1276 | array('jquery'), |
1277 | 1277 | EVENT_ESPRESSO_VERSION, |
1278 | 1278 | false |
1279 | 1279 | ); |
1280 | 1280 | wp_register_script( |
1281 | 1281 | 'ee_error_js', |
1282 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1282 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
1283 | 1283 | array('espresso_core'), |
1284 | 1284 | EVENT_ESPRESSO_VERSION, |
1285 | 1285 | false |
@@ -22,199 +22,199 @@ |
||
22 | 22 | class CachingLoader extends CachingLoaderDecorator |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $identifier |
|
32 | - */ |
|
33 | - protected $identifier; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var ClassInterfaceCache $class_cache |
|
37 | - */ |
|
38 | - private $class_cache; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * CachingLoader constructor. |
|
43 | - * |
|
44 | - * @param LoaderDecoratorInterface $loader |
|
45 | - * @param CollectionInterface $cache |
|
46 | - * @param ClassInterfaceCache $class_cache |
|
47 | - * @param string $identifier |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - */ |
|
50 | - public function __construct( |
|
51 | - LoaderDecoratorInterface $loader, |
|
52 | - CollectionInterface $cache, |
|
53 | - ClassInterfaceCache $class_cache, |
|
54 | - $identifier = '' |
|
55 | - ) { |
|
56 | - parent::__construct($loader); |
|
57 | - $this->cache = $cache; |
|
58 | - $this->class_cache = $class_cache; |
|
59 | - $this->setIdentifier($identifier); |
|
60 | - if ($this->identifier !== '') { |
|
61 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
62 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
63 | - // where "IDENTIFIER" = the string that was set during construction |
|
64 | - add_action( |
|
65 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
66 | - array($this, 'reset') |
|
67 | - ); |
|
68 | - } |
|
69 | - // to clear ALL caches, simply do the following: |
|
70 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
71 | - add_action( |
|
72 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
73 | - array($this, 'reset') |
|
74 | - ); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function identifier() |
|
82 | - { |
|
83 | - return $this->identifier; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $identifier |
|
89 | - * @throws InvalidDataTypeException |
|
90 | - */ |
|
91 | - private function setIdentifier($identifier) |
|
92 | - { |
|
93 | - if (! is_string($identifier)) { |
|
94 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
95 | - } |
|
96 | - $this->identifier = $identifier; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @param FullyQualifiedName|string $fqcn |
|
102 | - * @param mixed $object |
|
103 | - * @return bool |
|
104 | - * @throws InvalidArgumentException |
|
105 | - */ |
|
106 | - public function share($fqcn, $object) |
|
107 | - { |
|
108 | - if ($object instanceof $fqcn) { |
|
109 | - return $this->cache->add($object, md5($fqcn)); |
|
110 | - } |
|
111 | - throw new InvalidArgumentException( |
|
112 | - sprintf( |
|
113 | - esc_html__( |
|
114 | - 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - $fqcn |
|
118 | - ) |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @param FullyQualifiedName|string $fqcn |
|
125 | - * @param array $arguments |
|
126 | - * @param bool $shared |
|
127 | - * @param array $interfaces |
|
128 | - * @return mixed |
|
129 | - */ |
|
130 | - public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
131 | - { |
|
132 | - $fqcn = ltrim($fqcn, '\\'); |
|
133 | - // caching can be turned off via the following code: |
|
134 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
135 | - if ( |
|
136 | - apply_filters( |
|
137 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
138 | - false, |
|
139 | - $this |
|
140 | - ) |
|
141 | - ) { |
|
142 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
143 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
144 | - return $this->loader->load($fqcn, $arguments, false); |
|
145 | - } |
|
146 | - $identifier = $this->getClassIdentifier($fqcn, $arguments); |
|
147 | - if ($this->cache->has($identifier)) { |
|
148 | - return $this->cache->get($identifier); |
|
149 | - } |
|
150 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
151 | - if ($object instanceof $fqcn) { |
|
152 | - $this->cache->add($object, $identifier); |
|
153 | - } |
|
154 | - return $object; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * empties cache and calls reset() on loader if method exists |
|
160 | - */ |
|
161 | - public function reset() |
|
162 | - { |
|
163 | - $this->cache->trashAndDetachAll(); |
|
164 | - $this->loader->reset(); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * build a string representation of a class' name and arguments |
|
170 | - * |
|
171 | - * @param string $fqcn |
|
172 | - * @param array $arguments |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - private function getClassIdentifier($fqcn, array $arguments = array()) |
|
176 | - { |
|
177 | - // only build identifier from arguments if class is not ReservedInstanceInterface |
|
178 | - $identifier = ! $this->class_cache->hasInterface($fqcn, |
|
179 | - 'EventEspresso\core\interfaces\ReservedInstanceInterface') |
|
180 | - ? $this->getIdentifierForArguments($arguments) |
|
181 | - : ''; |
|
182 | - if (! empty($identifier)) { |
|
183 | - $fqcn .= '____' . md5($identifier); |
|
184 | - } |
|
185 | - return $fqcn; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * build a string representation of a class' arguments |
|
191 | - * (mostly because Closures can't be serialized) |
|
192 | - * |
|
193 | - * @param array $arguments |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - protected function getIdentifierForArguments(array $arguments) |
|
197 | - { |
|
198 | - if (empty($arguments)) { |
|
199 | - return ''; |
|
200 | - } |
|
201 | - $identifier = ''; |
|
202 | - foreach ($arguments as $argument) { |
|
203 | - switch (true) { |
|
204 | - case is_object($argument) : |
|
205 | - case $argument instanceof Closure : |
|
206 | - $identifier .= spl_object_hash($argument); |
|
207 | - break; |
|
208 | - case is_array($argument) : |
|
209 | - $identifier .= $this->getIdentifierForArguments($argument); |
|
210 | - break; |
|
211 | - default : |
|
212 | - $identifier .= $argument; |
|
213 | - break; |
|
214 | - } |
|
215 | - } |
|
216 | - return $identifier; |
|
217 | - } |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $identifier |
|
32 | + */ |
|
33 | + protected $identifier; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var ClassInterfaceCache $class_cache |
|
37 | + */ |
|
38 | + private $class_cache; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * CachingLoader constructor. |
|
43 | + * |
|
44 | + * @param LoaderDecoratorInterface $loader |
|
45 | + * @param CollectionInterface $cache |
|
46 | + * @param ClassInterfaceCache $class_cache |
|
47 | + * @param string $identifier |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + */ |
|
50 | + public function __construct( |
|
51 | + LoaderDecoratorInterface $loader, |
|
52 | + CollectionInterface $cache, |
|
53 | + ClassInterfaceCache $class_cache, |
|
54 | + $identifier = '' |
|
55 | + ) { |
|
56 | + parent::__construct($loader); |
|
57 | + $this->cache = $cache; |
|
58 | + $this->class_cache = $class_cache; |
|
59 | + $this->setIdentifier($identifier); |
|
60 | + if ($this->identifier !== '') { |
|
61 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
62 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
63 | + // where "IDENTIFIER" = the string that was set during construction |
|
64 | + add_action( |
|
65 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
66 | + array($this, 'reset') |
|
67 | + ); |
|
68 | + } |
|
69 | + // to clear ALL caches, simply do the following: |
|
70 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
71 | + add_action( |
|
72 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
73 | + array($this, 'reset') |
|
74 | + ); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function identifier() |
|
82 | + { |
|
83 | + return $this->identifier; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $identifier |
|
89 | + * @throws InvalidDataTypeException |
|
90 | + */ |
|
91 | + private function setIdentifier($identifier) |
|
92 | + { |
|
93 | + if (! is_string($identifier)) { |
|
94 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
95 | + } |
|
96 | + $this->identifier = $identifier; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @param FullyQualifiedName|string $fqcn |
|
102 | + * @param mixed $object |
|
103 | + * @return bool |
|
104 | + * @throws InvalidArgumentException |
|
105 | + */ |
|
106 | + public function share($fqcn, $object) |
|
107 | + { |
|
108 | + if ($object instanceof $fqcn) { |
|
109 | + return $this->cache->add($object, md5($fqcn)); |
|
110 | + } |
|
111 | + throw new InvalidArgumentException( |
|
112 | + sprintf( |
|
113 | + esc_html__( |
|
114 | + 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + $fqcn |
|
118 | + ) |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @param FullyQualifiedName|string $fqcn |
|
125 | + * @param array $arguments |
|
126 | + * @param bool $shared |
|
127 | + * @param array $interfaces |
|
128 | + * @return mixed |
|
129 | + */ |
|
130 | + public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
131 | + { |
|
132 | + $fqcn = ltrim($fqcn, '\\'); |
|
133 | + // caching can be turned off via the following code: |
|
134 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
135 | + if ( |
|
136 | + apply_filters( |
|
137 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
138 | + false, |
|
139 | + $this |
|
140 | + ) |
|
141 | + ) { |
|
142 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
143 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
144 | + return $this->loader->load($fqcn, $arguments, false); |
|
145 | + } |
|
146 | + $identifier = $this->getClassIdentifier($fqcn, $arguments); |
|
147 | + if ($this->cache->has($identifier)) { |
|
148 | + return $this->cache->get($identifier); |
|
149 | + } |
|
150 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
151 | + if ($object instanceof $fqcn) { |
|
152 | + $this->cache->add($object, $identifier); |
|
153 | + } |
|
154 | + return $object; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * empties cache and calls reset() on loader if method exists |
|
160 | + */ |
|
161 | + public function reset() |
|
162 | + { |
|
163 | + $this->cache->trashAndDetachAll(); |
|
164 | + $this->loader->reset(); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * build a string representation of a class' name and arguments |
|
170 | + * |
|
171 | + * @param string $fqcn |
|
172 | + * @param array $arguments |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + private function getClassIdentifier($fqcn, array $arguments = array()) |
|
176 | + { |
|
177 | + // only build identifier from arguments if class is not ReservedInstanceInterface |
|
178 | + $identifier = ! $this->class_cache->hasInterface($fqcn, |
|
179 | + 'EventEspresso\core\interfaces\ReservedInstanceInterface') |
|
180 | + ? $this->getIdentifierForArguments($arguments) |
|
181 | + : ''; |
|
182 | + if (! empty($identifier)) { |
|
183 | + $fqcn .= '____' . md5($identifier); |
|
184 | + } |
|
185 | + return $fqcn; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * build a string representation of a class' arguments |
|
191 | + * (mostly because Closures can't be serialized) |
|
192 | + * |
|
193 | + * @param array $arguments |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + protected function getIdentifierForArguments(array $arguments) |
|
197 | + { |
|
198 | + if (empty($arguments)) { |
|
199 | + return ''; |
|
200 | + } |
|
201 | + $identifier = ''; |
|
202 | + foreach ($arguments as $argument) { |
|
203 | + switch (true) { |
|
204 | + case is_object($argument) : |
|
205 | + case $argument instanceof Closure : |
|
206 | + $identifier .= spl_object_hash($argument); |
|
207 | + break; |
|
208 | + case is_array($argument) : |
|
209 | + $identifier .= $this->getIdentifierForArguments($argument); |
|
210 | + break; |
|
211 | + default : |
|
212 | + $identifier .= $argument; |
|
213 | + break; |
|
214 | + } |
|
215 | + } |
|
216 | + return $identifier; |
|
217 | + } |
|
218 | 218 | } |
219 | 219 | // End of file CachingLoader.php |
220 | 220 | // Location: EventEspresso\core\services\loaders/CachingLoader.php |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | private function setIdentifier($identifier) |
92 | 92 | { |
93 | - if (! is_string($identifier)) { |
|
93 | + if ( ! is_string($identifier)) { |
|
94 | 94 | throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
95 | 95 | } |
96 | 96 | $this->identifier = $identifier; |
@@ -179,8 +179,8 @@ discard block |
||
179 | 179 | 'EventEspresso\core\interfaces\ReservedInstanceInterface') |
180 | 180 | ? $this->getIdentifierForArguments($arguments) |
181 | 181 | : ''; |
182 | - if (! empty($identifier)) { |
|
183 | - $fqcn .= '____' . md5($identifier); |
|
182 | + if ( ! empty($identifier)) { |
|
183 | + $fqcn .= '____'.md5($identifier); |
|
184 | 184 | } |
185 | 185 | return $fqcn; |
186 | 186 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use EventEspresso\core\services\request\ResponseInterface; |
9 | 9 | |
10 | 10 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
11 | - exit('No direct script access allowed'); |
|
11 | + exit('No direct script access allowed'); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
@@ -25,839 +25,839 @@ discard block |
||
25 | 25 | class EE_Dependency_Map |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * This means that the requested class dependency is not present in the dependency map |
|
30 | - */ |
|
31 | - const not_registered = 0; |
|
32 | - |
|
33 | - /** |
|
34 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
35 | - */ |
|
36 | - const load_new_object = 1; |
|
37 | - |
|
38 | - /** |
|
39 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
40 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
41 | - */ |
|
42 | - const load_from_cache = 2; |
|
43 | - |
|
44 | - /** |
|
45 | - * When registering a dependency, |
|
46 | - * this indicates to keep any existing dependencies that already exist, |
|
47 | - * and simply discard any new dependencies declared in the incoming data |
|
48 | - */ |
|
49 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
50 | - |
|
51 | - /** |
|
52 | - * When registering a dependency, |
|
53 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
54 | - */ |
|
55 | - const OVERWRITE_DEPENDENCIES = 1; |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @type EE_Dependency_Map $_instance |
|
61 | - */ |
|
62 | - protected static $_instance; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var ClassInterfaceCache $class_cache |
|
66 | - */ |
|
67 | - private $class_cache; |
|
68 | - |
|
69 | - /** |
|
70 | - * @type RequestInterface $request |
|
71 | - */ |
|
72 | - protected $request; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type LegacyRequestInterface $legacy_request |
|
76 | - */ |
|
77 | - protected $legacy_request; |
|
78 | - |
|
79 | - /** |
|
80 | - * @type ResponseInterface $response |
|
81 | - */ |
|
82 | - protected $response; |
|
83 | - |
|
84 | - /** |
|
85 | - * @type LoaderInterface $loader |
|
86 | - */ |
|
87 | - protected $loader; |
|
88 | - |
|
89 | - /** |
|
90 | - * @type array $_dependency_map |
|
91 | - */ |
|
92 | - protected $_dependency_map = array(); |
|
93 | - |
|
94 | - /** |
|
95 | - * @type array $_class_loaders |
|
96 | - */ |
|
97 | - protected $_class_loaders = array(); |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * EE_Dependency_Map constructor. |
|
102 | - * |
|
103 | - * @param ClassInterfaceCache $class_cache |
|
104 | - */ |
|
105 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
106 | - { |
|
107 | - $this->class_cache = $class_cache; |
|
108 | - do_action('EE_Dependency_Map____construct', $this); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - public function initialize() |
|
116 | - { |
|
117 | - $this->_register_core_dependencies(); |
|
118 | - $this->_register_core_class_loaders(); |
|
119 | - $this->_register_core_aliases(); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @singleton method used to instantiate class object |
|
125 | - * @param ClassInterfaceCache|null $class_cache |
|
126 | - * @return EE_Dependency_Map |
|
127 | - */ |
|
128 | - public static function instance(ClassInterfaceCache $class_cache = null) { |
|
129 | - // check if class object is instantiated, and instantiated properly |
|
130 | - if ( |
|
131 | - ! self::$_instance instanceof EE_Dependency_Map |
|
132 | - && $class_cache instanceof ClassInterfaceCache |
|
133 | - ) { |
|
134 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
135 | - } |
|
136 | - return self::$_instance; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param RequestInterface $request |
|
142 | - */ |
|
143 | - public function setRequest(RequestInterface $request) |
|
144 | - { |
|
145 | - $this->request = $request; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @param LegacyRequestInterface $legacy_request |
|
151 | - */ |
|
152 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
153 | - { |
|
154 | - $this->legacy_request = $legacy_request; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @param ResponseInterface $response |
|
160 | - */ |
|
161 | - public function setResponse(ResponseInterface $response) |
|
162 | - { |
|
163 | - $this->response = $response; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @param LoaderInterface $loader |
|
170 | - */ |
|
171 | - public function setLoader(LoaderInterface $loader) |
|
172 | - { |
|
173 | - $this->loader = $loader; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param string $class |
|
180 | - * @param array $dependencies |
|
181 | - * @param int $overwrite |
|
182 | - * @return bool |
|
183 | - */ |
|
184 | - public static function register_dependencies( |
|
185 | - $class, |
|
186 | - array $dependencies, |
|
187 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
188 | - ) { |
|
189 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
196 | - * to the class specified by the first parameter. |
|
197 | - * IMPORTANT !!! |
|
198 | - * The order of elements in the incoming $dependencies array MUST match |
|
199 | - * the order of the constructor parameters for the class in question. |
|
200 | - * This is especially important when overriding any existing dependencies that are registered. |
|
201 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
202 | - * |
|
203 | - * @param string $class |
|
204 | - * @param array $dependencies |
|
205 | - * @param int $overwrite |
|
206 | - * @return bool |
|
207 | - */ |
|
208 | - public function registerDependencies( |
|
209 | - $class, |
|
210 | - array $dependencies, |
|
211 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
212 | - ) { |
|
213 | - $class = trim($class, '\\'); |
|
214 | - $registered = false; |
|
215 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
216 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
217 | - } |
|
218 | - // we need to make sure that any aliases used when registering a dependency |
|
219 | - // get resolved to the correct class name |
|
220 | - foreach ($dependencies as $dependency => $load_source) { |
|
221 | - $alias = self::$_instance->get_alias($dependency); |
|
222 | - if ( |
|
223 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
224 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
225 | - ) { |
|
226 | - unset($dependencies[$dependency]); |
|
227 | - $dependencies[$alias] = $load_source; |
|
228 | - $registered = true; |
|
229 | - } |
|
230 | - } |
|
231 | - // now add our two lists of dependencies together. |
|
232 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
233 | - // so $dependencies is NOT overwritten because it is listed first |
|
234 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
235 | - // Union is way faster than array_merge() but should be used with caution... |
|
236 | - // especially with numerically indexed arrays |
|
237 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
238 | - // now we need to ensure that the resulting dependencies |
|
239 | - // array only has the entries that are required for the class |
|
240 | - // so first count how many dependencies were originally registered for the class |
|
241 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
242 | - // if that count is non-zero (meaning dependencies were already registered) |
|
243 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
244 | - // then truncate the final array to match that count |
|
245 | - ? array_slice($dependencies, 0, $dependency_count) |
|
246 | - // otherwise just take the incoming array because nothing previously existed |
|
247 | - : $dependencies; |
|
248 | - return $registered; |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * @param string $class_name |
|
255 | - * @param string $loader |
|
256 | - * @return bool |
|
257 | - * @throws DomainException |
|
258 | - */ |
|
259 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
260 | - { |
|
261 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
262 | - throw new DomainException( |
|
263 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
264 | - ); |
|
265 | - } |
|
266 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
267 | - if ( |
|
268 | - ! is_callable($loader) |
|
269 | - && ( |
|
270 | - strpos($loader, 'load_') !== 0 |
|
271 | - || ! method_exists('EE_Registry', $loader) |
|
272 | - ) |
|
273 | - ) { |
|
274 | - throw new DomainException( |
|
275 | - sprintf( |
|
276 | - esc_html__( |
|
277 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
278 | - 'event_espresso' |
|
279 | - ), |
|
280 | - $loader |
|
281 | - ) |
|
282 | - ); |
|
283 | - } |
|
284 | - $class_name = self::$_instance->get_alias($class_name); |
|
285 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
286 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
287 | - return true; |
|
288 | - } |
|
289 | - return false; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @return array |
|
296 | - */ |
|
297 | - public function dependency_map() |
|
298 | - { |
|
299 | - return $this->_dependency_map; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
306 | - * |
|
307 | - * @param string $class_name |
|
308 | - * @return boolean |
|
309 | - */ |
|
310 | - public function has($class_name = '') |
|
311 | - { |
|
312 | - // all legacy models have the same dependencies |
|
313 | - if (strpos($class_name, 'EEM_') === 0) { |
|
314 | - $class_name = 'LEGACY_MODELS'; |
|
315 | - } |
|
316 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
323 | - * |
|
324 | - * @param string $class_name |
|
325 | - * @param string $dependency |
|
326 | - * @return bool |
|
327 | - */ |
|
328 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
329 | - { |
|
330 | - // all legacy models have the same dependencies |
|
331 | - if (strpos($class_name, 'EEM_') === 0) { |
|
332 | - $class_name = 'LEGACY_MODELS'; |
|
333 | - } |
|
334 | - $dependency = $this->get_alias($dependency); |
|
335 | - return isset($this->_dependency_map[$class_name][$dependency]) |
|
336 | - ? true |
|
337 | - : false; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
344 | - * |
|
345 | - * @param string $class_name |
|
346 | - * @param string $dependency |
|
347 | - * @return int |
|
348 | - */ |
|
349 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
350 | - { |
|
351 | - // all legacy models have the same dependencies |
|
352 | - if (strpos($class_name, 'EEM_') === 0) { |
|
353 | - $class_name = 'LEGACY_MODELS'; |
|
354 | - } |
|
355 | - $dependency = $this->get_alias($dependency); |
|
356 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
357 | - ? $this->_dependency_map[$class_name][$dependency] |
|
358 | - : EE_Dependency_Map::not_registered; |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * @param string $class_name |
|
365 | - * @return string | Closure |
|
366 | - */ |
|
367 | - public function class_loader($class_name) |
|
368 | - { |
|
369 | - // all legacy models use load_model() |
|
370 | - if(strpos($class_name, 'EEM_') === 0){ |
|
371 | - return 'load_model'; |
|
372 | - } |
|
373 | - $class_name = $this->get_alias($class_name); |
|
374 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return array |
|
381 | - */ |
|
382 | - public function class_loaders() |
|
383 | - { |
|
384 | - return $this->_class_loaders; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * adds an alias for a classname |
|
391 | - * |
|
392 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
393 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
394 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
395 | - */ |
|
396 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
397 | - { |
|
398 | - $this->class_cache->addAlias($alias, $fqcn, $for_class); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
405 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
406 | - * |
|
407 | - * @param string $fqn |
|
408 | - * @param string $for_class |
|
409 | - * @return bool |
|
410 | - */ |
|
411 | - public function has_alias($fqn = '', $for_class = '') |
|
412 | - { |
|
413 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
420 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
421 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
422 | - * for example: |
|
423 | - * if the following two entries were added to the _aliases array: |
|
424 | - * array( |
|
425 | - * 'interface_alias' => 'some\namespace\interface' |
|
426 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
427 | - * ) |
|
428 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
429 | - * to load an instance of 'some\namespace\classname' |
|
430 | - * |
|
431 | - * @param string $alias |
|
432 | - * @param string $for_class |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - public function get_alias($alias = '', $for_class = '') |
|
436 | - { |
|
437 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
444 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
445 | - * This is done by using the following class constants: |
|
446 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
447 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
448 | - */ |
|
449 | - protected function _register_core_dependencies() |
|
450 | - { |
|
451 | - $this->_dependency_map = array( |
|
452 | - 'EE_Request_Handler' => array( |
|
453 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EE_System' => array( |
|
456 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
457 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_Session' => array( |
|
462 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
463 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
464 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
465 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
466 | - ), |
|
467 | - 'EE_Cart' => array( |
|
468 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Front_Controller' => array( |
|
471 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
472 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
473 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
474 | - ), |
|
475 | - 'EE_Messenger_Collection_Loader' => array( |
|
476 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
477 | - ), |
|
478 | - 'EE_Message_Type_Collection_Loader' => array( |
|
479 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
480 | - ), |
|
481 | - 'EE_Message_Resource_Manager' => array( |
|
482 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
483 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
484 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
485 | - ), |
|
486 | - 'EE_Message_Factory' => array( |
|
487 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
488 | - ), |
|
489 | - 'EE_messages' => array( |
|
490 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
491 | - ), |
|
492 | - 'EE_Messages_Generator' => array( |
|
493 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
494 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
495 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
496 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
497 | - ), |
|
498 | - 'EE_Messages_Processor' => array( |
|
499 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EE_Messages_Queue' => array( |
|
502 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
503 | - ), |
|
504 | - 'EE_Messages_Template_Defaults' => array( |
|
505 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
506 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EE_Message_To_Generate_From_Request' => array( |
|
509 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
511 | - ), |
|
512 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
513 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
514 | - ), |
|
515 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
516 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
517 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
518 | - ), |
|
519 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
520 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
523 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
524 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
525 | - ), |
|
526 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
527 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
528 | - ), |
|
529 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
530 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
531 | - ), |
|
532 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
533 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
534 | - ), |
|
535 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
536 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
537 | - ), |
|
538 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
539 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
540 | - ), |
|
541 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
542 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
543 | - ), |
|
544 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
545 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
546 | - ), |
|
547 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
548 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
549 | - ), |
|
550 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
551 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
552 | - ), |
|
553 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
554 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
555 | - ), |
|
556 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
557 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
558 | - ), |
|
559 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
560 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
561 | - ), |
|
562 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
563 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
564 | - ), |
|
565 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
566 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | - ), |
|
568 | - 'EE_Data_Migration_Class_Base' => array( |
|
569 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
570 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
571 | - ), |
|
572 | - 'EE_DMS_Core_4_1_0' => array( |
|
573 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
574 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
575 | - ), |
|
576 | - 'EE_DMS_Core_4_2_0' => array( |
|
577 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
578 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
579 | - ), |
|
580 | - 'EE_DMS_Core_4_3_0' => array( |
|
581 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
582 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
583 | - ), |
|
584 | - 'EE_DMS_Core_4_4_0' => array( |
|
585 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
586 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
587 | - ), |
|
588 | - 'EE_DMS_Core_4_5_0' => array( |
|
589 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
590 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
591 | - ), |
|
592 | - 'EE_DMS_Core_4_6_0' => array( |
|
593 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
594 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
595 | - ), |
|
596 | - 'EE_DMS_Core_4_7_0' => array( |
|
597 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
598 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
599 | - ), |
|
600 | - 'EE_DMS_Core_4_8_0' => array( |
|
601 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
602 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
603 | - ), |
|
604 | - 'EE_DMS_Core_4_9_0' => array( |
|
605 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
606 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
607 | - ), |
|
608 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
609 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
610 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
611 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
612 | - ), |
|
613 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
614 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
615 | - ), |
|
616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | - ), |
|
619 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
620 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | - ), |
|
622 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | - ), |
|
625 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
626 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | - ), |
|
628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
632 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
635 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
638 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | - ), |
|
640 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
641 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
642 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
643 | - ), |
|
644 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
645 | - null, |
|
646 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
647 | - ), |
|
648 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
649 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
650 | - ), |
|
651 | - 'LEGACY_MODELS' => array( |
|
652 | - null, |
|
653 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
654 | - ), |
|
655 | - 'EE_Module_Request_Router' => array( |
|
656 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
657 | - ), |
|
658 | - 'EE_Registration_Processor' => array( |
|
659 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
660 | - ), |
|
661 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
662 | - null, |
|
663 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
664 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
665 | - ), |
|
666 | - 'EE_Admin_Transactions_List_Table' => array( |
|
667 | - null, |
|
668 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
669 | - ), |
|
670 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
671 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
672 | - ), |
|
673 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
674 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
675 | - ), |
|
676 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
677 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
678 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
679 | - ), |
|
680 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
681 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
682 | - ), |
|
683 | - ); |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - /** |
|
688 | - * Registers how core classes are loaded. |
|
689 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
690 | - * 'EE_Request_Handler' => 'load_core' |
|
691 | - * 'EE_Messages_Queue' => 'load_lib' |
|
692 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
693 | - * or, if greater control is required, by providing a custom closure. For example: |
|
694 | - * 'Some_Class' => function () { |
|
695 | - * return new Some_Class(); |
|
696 | - * }, |
|
697 | - * This is required for instantiating dependencies |
|
698 | - * where an interface has been type hinted in a class constructor. For example: |
|
699 | - * 'Required_Interface' => function () { |
|
700 | - * return new A_Class_That_Implements_Required_Interface(); |
|
701 | - * }, |
|
702 | - * |
|
703 | - */ |
|
704 | - protected function _register_core_class_loaders() |
|
705 | - { |
|
706 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
707 | - //be used in a closure. |
|
708 | - $request = &$this->request; |
|
709 | - $response = &$this->response; |
|
710 | - $legacy_request = &$this->legacy_request; |
|
711 | - // $loader = &$this->loader; |
|
712 | - $this->_class_loaders = array( |
|
713 | - //load_core |
|
714 | - 'EE_Capabilities' => 'load_core', |
|
715 | - 'EE_Encryption' => 'load_core', |
|
716 | - 'EE_Front_Controller' => 'load_core', |
|
717 | - 'EE_Module_Request_Router' => 'load_core', |
|
718 | - 'EE_Registry' => 'load_core', |
|
719 | - 'EE_Request' => function () use (&$legacy_request) { |
|
720 | - return $legacy_request; |
|
721 | - }, |
|
722 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
723 | - return $request; |
|
724 | - }, |
|
725 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
726 | - return $response; |
|
727 | - }, |
|
728 | - 'EE_Request_Handler' => 'load_core', |
|
729 | - 'EE_Session' => 'load_core', |
|
730 | - 'EE_Cron_Tasks' => 'load_core', |
|
731 | - 'EE_System' => 'load_core', |
|
732 | - 'EE_Maintenance_Mode' => 'load_core', |
|
733 | - 'EE_Register_CPTs' => 'load_core', |
|
734 | - 'EE_Admin' => 'load_core', |
|
735 | - //load_lib |
|
736 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
737 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
738 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
739 | - 'EE_Messenger_Collection' => 'load_lib', |
|
740 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
741 | - 'EE_Messages_Processor' => 'load_lib', |
|
742 | - 'EE_Message_Repository' => 'load_lib', |
|
743 | - 'EE_Messages_Queue' => 'load_lib', |
|
744 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
745 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
746 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
747 | - 'EE_Messages_Generator' => function () { |
|
748 | - return EE_Registry::instance()->load_lib( |
|
749 | - 'Messages_Generator', |
|
750 | - array(), |
|
751 | - false, |
|
752 | - false |
|
753 | - ); |
|
754 | - }, |
|
755 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
756 | - return EE_Registry::instance()->load_lib( |
|
757 | - 'Messages_Template_Defaults', |
|
758 | - $arguments, |
|
759 | - false, |
|
760 | - false |
|
761 | - ); |
|
762 | - }, |
|
763 | - //load_model |
|
764 | - // 'EEM_Attendee' => 'load_model', |
|
765 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
766 | - // 'EEM_Message_Template' => 'load_model', |
|
767 | - //load_helper |
|
768 | - 'EEH_Parse_Shortcodes' => function () { |
|
769 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
770 | - return new EEH_Parse_Shortcodes(); |
|
771 | - } |
|
772 | - return null; |
|
773 | - }, |
|
774 | - 'EE_Template_Config' => function () { |
|
775 | - return EE_Config::instance()->template_settings; |
|
776 | - }, |
|
777 | - 'EE_Currency_Config' => function () { |
|
778 | - return EE_Config::instance()->currency; |
|
779 | - }, |
|
780 | - 'EE_Registration_Config' => function () { |
|
781 | - return EE_Config::instance()->registration; |
|
782 | - }, |
|
783 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
784 | - return LoaderFactory::getLoader(); |
|
785 | - }, |
|
786 | - 'EE_Base' => 'load_core', |
|
787 | - ); |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * can be used for supplying alternate names for classes, |
|
795 | - * or for connecting interface names to instantiable classes |
|
796 | - */ |
|
797 | - protected function _register_core_aliases() |
|
798 | - { |
|
799 | - $aliases = array( |
|
800 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
801 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
802 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
803 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
804 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
805 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
806 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
807 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
808 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
809 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
810 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
811 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
812 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
813 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
814 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
815 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
816 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
817 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
818 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
819 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
820 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
821 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
822 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
823 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
824 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
825 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
826 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
827 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
828 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
829 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
830 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
831 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
832 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
833 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
834 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
835 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
836 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
837 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
838 | - ); |
|
839 | - foreach ($aliases as $alias => $fqn) { |
|
840 | - $this->class_cache->addAlias($fqn, $alias); |
|
841 | - } |
|
842 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
843 | - $this->class_cache->addAlias( |
|
844 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
845 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
846 | - ); |
|
847 | - } |
|
848 | - } |
|
849 | - |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
854 | - * request Primarily used by unit tests. |
|
855 | - */ |
|
856 | - public function reset() |
|
857 | - { |
|
858 | - $this->_register_core_class_loaders(); |
|
859 | - $this->_register_core_dependencies(); |
|
860 | - } |
|
28 | + /** |
|
29 | + * This means that the requested class dependency is not present in the dependency map |
|
30 | + */ |
|
31 | + const not_registered = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
35 | + */ |
|
36 | + const load_new_object = 1; |
|
37 | + |
|
38 | + /** |
|
39 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
40 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
41 | + */ |
|
42 | + const load_from_cache = 2; |
|
43 | + |
|
44 | + /** |
|
45 | + * When registering a dependency, |
|
46 | + * this indicates to keep any existing dependencies that already exist, |
|
47 | + * and simply discard any new dependencies declared in the incoming data |
|
48 | + */ |
|
49 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
50 | + |
|
51 | + /** |
|
52 | + * When registering a dependency, |
|
53 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
54 | + */ |
|
55 | + const OVERWRITE_DEPENDENCIES = 1; |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @type EE_Dependency_Map $_instance |
|
61 | + */ |
|
62 | + protected static $_instance; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var ClassInterfaceCache $class_cache |
|
66 | + */ |
|
67 | + private $class_cache; |
|
68 | + |
|
69 | + /** |
|
70 | + * @type RequestInterface $request |
|
71 | + */ |
|
72 | + protected $request; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type LegacyRequestInterface $legacy_request |
|
76 | + */ |
|
77 | + protected $legacy_request; |
|
78 | + |
|
79 | + /** |
|
80 | + * @type ResponseInterface $response |
|
81 | + */ |
|
82 | + protected $response; |
|
83 | + |
|
84 | + /** |
|
85 | + * @type LoaderInterface $loader |
|
86 | + */ |
|
87 | + protected $loader; |
|
88 | + |
|
89 | + /** |
|
90 | + * @type array $_dependency_map |
|
91 | + */ |
|
92 | + protected $_dependency_map = array(); |
|
93 | + |
|
94 | + /** |
|
95 | + * @type array $_class_loaders |
|
96 | + */ |
|
97 | + protected $_class_loaders = array(); |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * EE_Dependency_Map constructor. |
|
102 | + * |
|
103 | + * @param ClassInterfaceCache $class_cache |
|
104 | + */ |
|
105 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
106 | + { |
|
107 | + $this->class_cache = $class_cache; |
|
108 | + do_action('EE_Dependency_Map____construct', $this); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + public function initialize() |
|
116 | + { |
|
117 | + $this->_register_core_dependencies(); |
|
118 | + $this->_register_core_class_loaders(); |
|
119 | + $this->_register_core_aliases(); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @singleton method used to instantiate class object |
|
125 | + * @param ClassInterfaceCache|null $class_cache |
|
126 | + * @return EE_Dependency_Map |
|
127 | + */ |
|
128 | + public static function instance(ClassInterfaceCache $class_cache = null) { |
|
129 | + // check if class object is instantiated, and instantiated properly |
|
130 | + if ( |
|
131 | + ! self::$_instance instanceof EE_Dependency_Map |
|
132 | + && $class_cache instanceof ClassInterfaceCache |
|
133 | + ) { |
|
134 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
135 | + } |
|
136 | + return self::$_instance; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param RequestInterface $request |
|
142 | + */ |
|
143 | + public function setRequest(RequestInterface $request) |
|
144 | + { |
|
145 | + $this->request = $request; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @param LegacyRequestInterface $legacy_request |
|
151 | + */ |
|
152 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
153 | + { |
|
154 | + $this->legacy_request = $legacy_request; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @param ResponseInterface $response |
|
160 | + */ |
|
161 | + public function setResponse(ResponseInterface $response) |
|
162 | + { |
|
163 | + $this->response = $response; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @param LoaderInterface $loader |
|
170 | + */ |
|
171 | + public function setLoader(LoaderInterface $loader) |
|
172 | + { |
|
173 | + $this->loader = $loader; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param string $class |
|
180 | + * @param array $dependencies |
|
181 | + * @param int $overwrite |
|
182 | + * @return bool |
|
183 | + */ |
|
184 | + public static function register_dependencies( |
|
185 | + $class, |
|
186 | + array $dependencies, |
|
187 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
188 | + ) { |
|
189 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
196 | + * to the class specified by the first parameter. |
|
197 | + * IMPORTANT !!! |
|
198 | + * The order of elements in the incoming $dependencies array MUST match |
|
199 | + * the order of the constructor parameters for the class in question. |
|
200 | + * This is especially important when overriding any existing dependencies that are registered. |
|
201 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
202 | + * |
|
203 | + * @param string $class |
|
204 | + * @param array $dependencies |
|
205 | + * @param int $overwrite |
|
206 | + * @return bool |
|
207 | + */ |
|
208 | + public function registerDependencies( |
|
209 | + $class, |
|
210 | + array $dependencies, |
|
211 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
212 | + ) { |
|
213 | + $class = trim($class, '\\'); |
|
214 | + $registered = false; |
|
215 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
216 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
217 | + } |
|
218 | + // we need to make sure that any aliases used when registering a dependency |
|
219 | + // get resolved to the correct class name |
|
220 | + foreach ($dependencies as $dependency => $load_source) { |
|
221 | + $alias = self::$_instance->get_alias($dependency); |
|
222 | + if ( |
|
223 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
224 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
225 | + ) { |
|
226 | + unset($dependencies[$dependency]); |
|
227 | + $dependencies[$alias] = $load_source; |
|
228 | + $registered = true; |
|
229 | + } |
|
230 | + } |
|
231 | + // now add our two lists of dependencies together. |
|
232 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
233 | + // so $dependencies is NOT overwritten because it is listed first |
|
234 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
235 | + // Union is way faster than array_merge() but should be used with caution... |
|
236 | + // especially with numerically indexed arrays |
|
237 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
238 | + // now we need to ensure that the resulting dependencies |
|
239 | + // array only has the entries that are required for the class |
|
240 | + // so first count how many dependencies were originally registered for the class |
|
241 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
242 | + // if that count is non-zero (meaning dependencies were already registered) |
|
243 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
244 | + // then truncate the final array to match that count |
|
245 | + ? array_slice($dependencies, 0, $dependency_count) |
|
246 | + // otherwise just take the incoming array because nothing previously existed |
|
247 | + : $dependencies; |
|
248 | + return $registered; |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * @param string $class_name |
|
255 | + * @param string $loader |
|
256 | + * @return bool |
|
257 | + * @throws DomainException |
|
258 | + */ |
|
259 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
260 | + { |
|
261 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
262 | + throw new DomainException( |
|
263 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
264 | + ); |
|
265 | + } |
|
266 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
267 | + if ( |
|
268 | + ! is_callable($loader) |
|
269 | + && ( |
|
270 | + strpos($loader, 'load_') !== 0 |
|
271 | + || ! method_exists('EE_Registry', $loader) |
|
272 | + ) |
|
273 | + ) { |
|
274 | + throw new DomainException( |
|
275 | + sprintf( |
|
276 | + esc_html__( |
|
277 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
278 | + 'event_espresso' |
|
279 | + ), |
|
280 | + $loader |
|
281 | + ) |
|
282 | + ); |
|
283 | + } |
|
284 | + $class_name = self::$_instance->get_alias($class_name); |
|
285 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
286 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
287 | + return true; |
|
288 | + } |
|
289 | + return false; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @return array |
|
296 | + */ |
|
297 | + public function dependency_map() |
|
298 | + { |
|
299 | + return $this->_dependency_map; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
306 | + * |
|
307 | + * @param string $class_name |
|
308 | + * @return boolean |
|
309 | + */ |
|
310 | + public function has($class_name = '') |
|
311 | + { |
|
312 | + // all legacy models have the same dependencies |
|
313 | + if (strpos($class_name, 'EEM_') === 0) { |
|
314 | + $class_name = 'LEGACY_MODELS'; |
|
315 | + } |
|
316 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
323 | + * |
|
324 | + * @param string $class_name |
|
325 | + * @param string $dependency |
|
326 | + * @return bool |
|
327 | + */ |
|
328 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
329 | + { |
|
330 | + // all legacy models have the same dependencies |
|
331 | + if (strpos($class_name, 'EEM_') === 0) { |
|
332 | + $class_name = 'LEGACY_MODELS'; |
|
333 | + } |
|
334 | + $dependency = $this->get_alias($dependency); |
|
335 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
336 | + ? true |
|
337 | + : false; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
344 | + * |
|
345 | + * @param string $class_name |
|
346 | + * @param string $dependency |
|
347 | + * @return int |
|
348 | + */ |
|
349 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
350 | + { |
|
351 | + // all legacy models have the same dependencies |
|
352 | + if (strpos($class_name, 'EEM_') === 0) { |
|
353 | + $class_name = 'LEGACY_MODELS'; |
|
354 | + } |
|
355 | + $dependency = $this->get_alias($dependency); |
|
356 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
357 | + ? $this->_dependency_map[$class_name][$dependency] |
|
358 | + : EE_Dependency_Map::not_registered; |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * @param string $class_name |
|
365 | + * @return string | Closure |
|
366 | + */ |
|
367 | + public function class_loader($class_name) |
|
368 | + { |
|
369 | + // all legacy models use load_model() |
|
370 | + if(strpos($class_name, 'EEM_') === 0){ |
|
371 | + return 'load_model'; |
|
372 | + } |
|
373 | + $class_name = $this->get_alias($class_name); |
|
374 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return array |
|
381 | + */ |
|
382 | + public function class_loaders() |
|
383 | + { |
|
384 | + return $this->_class_loaders; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * adds an alias for a classname |
|
391 | + * |
|
392 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
393 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
394 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
395 | + */ |
|
396 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
397 | + { |
|
398 | + $this->class_cache->addAlias($alias, $fqcn, $for_class); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
405 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
406 | + * |
|
407 | + * @param string $fqn |
|
408 | + * @param string $for_class |
|
409 | + * @return bool |
|
410 | + */ |
|
411 | + public function has_alias($fqn = '', $for_class = '') |
|
412 | + { |
|
413 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
420 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
421 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
422 | + * for example: |
|
423 | + * if the following two entries were added to the _aliases array: |
|
424 | + * array( |
|
425 | + * 'interface_alias' => 'some\namespace\interface' |
|
426 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
427 | + * ) |
|
428 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
429 | + * to load an instance of 'some\namespace\classname' |
|
430 | + * |
|
431 | + * @param string $alias |
|
432 | + * @param string $for_class |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + public function get_alias($alias = '', $for_class = '') |
|
436 | + { |
|
437 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
444 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
445 | + * This is done by using the following class constants: |
|
446 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
447 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
448 | + */ |
|
449 | + protected function _register_core_dependencies() |
|
450 | + { |
|
451 | + $this->_dependency_map = array( |
|
452 | + 'EE_Request_Handler' => array( |
|
453 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EE_System' => array( |
|
456 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
457 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_Session' => array( |
|
462 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
463 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
464 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
465 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
466 | + ), |
|
467 | + 'EE_Cart' => array( |
|
468 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Front_Controller' => array( |
|
471 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
472 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
473 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
474 | + ), |
|
475 | + 'EE_Messenger_Collection_Loader' => array( |
|
476 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
477 | + ), |
|
478 | + 'EE_Message_Type_Collection_Loader' => array( |
|
479 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
480 | + ), |
|
481 | + 'EE_Message_Resource_Manager' => array( |
|
482 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
483 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
484 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
485 | + ), |
|
486 | + 'EE_Message_Factory' => array( |
|
487 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
488 | + ), |
|
489 | + 'EE_messages' => array( |
|
490 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
491 | + ), |
|
492 | + 'EE_Messages_Generator' => array( |
|
493 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
494 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
495 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
496 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
497 | + ), |
|
498 | + 'EE_Messages_Processor' => array( |
|
499 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EE_Messages_Queue' => array( |
|
502 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
503 | + ), |
|
504 | + 'EE_Messages_Template_Defaults' => array( |
|
505 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
506 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EE_Message_To_Generate_From_Request' => array( |
|
509 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
510 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
511 | + ), |
|
512 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
513 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
514 | + ), |
|
515 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
516 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
517 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
518 | + ), |
|
519 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
520 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
523 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
524 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
525 | + ), |
|
526 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
527 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
528 | + ), |
|
529 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
530 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
531 | + ), |
|
532 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
533 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
534 | + ), |
|
535 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
536 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
537 | + ), |
|
538 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
539 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
540 | + ), |
|
541 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
542 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
543 | + ), |
|
544 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
545 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
546 | + ), |
|
547 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
548 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
549 | + ), |
|
550 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
551 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
552 | + ), |
|
553 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
554 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
555 | + ), |
|
556 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
557 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
558 | + ), |
|
559 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
560 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
561 | + ), |
|
562 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
563 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
564 | + ), |
|
565 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
566 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
567 | + ), |
|
568 | + 'EE_Data_Migration_Class_Base' => array( |
|
569 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
570 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
571 | + ), |
|
572 | + 'EE_DMS_Core_4_1_0' => array( |
|
573 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
574 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
575 | + ), |
|
576 | + 'EE_DMS_Core_4_2_0' => array( |
|
577 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
578 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
579 | + ), |
|
580 | + 'EE_DMS_Core_4_3_0' => array( |
|
581 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
582 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
583 | + ), |
|
584 | + 'EE_DMS_Core_4_4_0' => array( |
|
585 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
586 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
587 | + ), |
|
588 | + 'EE_DMS_Core_4_5_0' => array( |
|
589 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
590 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
591 | + ), |
|
592 | + 'EE_DMS_Core_4_6_0' => array( |
|
593 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
594 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
595 | + ), |
|
596 | + 'EE_DMS_Core_4_7_0' => array( |
|
597 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
598 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
599 | + ), |
|
600 | + 'EE_DMS_Core_4_8_0' => array( |
|
601 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
602 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
603 | + ), |
|
604 | + 'EE_DMS_Core_4_9_0' => array( |
|
605 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
606 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
607 | + ), |
|
608 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
609 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
610 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
611 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
612 | + ), |
|
613 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
614 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
615 | + ), |
|
616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | + ), |
|
619 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
620 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | + ), |
|
622 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | + ), |
|
625 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
626 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | + ), |
|
628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
632 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
635 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
638 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | + ), |
|
640 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
641 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
642 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
643 | + ), |
|
644 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
645 | + null, |
|
646 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
647 | + ), |
|
648 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
649 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
650 | + ), |
|
651 | + 'LEGACY_MODELS' => array( |
|
652 | + null, |
|
653 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
654 | + ), |
|
655 | + 'EE_Module_Request_Router' => array( |
|
656 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
657 | + ), |
|
658 | + 'EE_Registration_Processor' => array( |
|
659 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
660 | + ), |
|
661 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
662 | + null, |
|
663 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
664 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
665 | + ), |
|
666 | + 'EE_Admin_Transactions_List_Table' => array( |
|
667 | + null, |
|
668 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
669 | + ), |
|
670 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
671 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
672 | + ), |
|
673 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
674 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
675 | + ), |
|
676 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
677 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
678 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
679 | + ), |
|
680 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
681 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
682 | + ), |
|
683 | + ); |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + /** |
|
688 | + * Registers how core classes are loaded. |
|
689 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
690 | + * 'EE_Request_Handler' => 'load_core' |
|
691 | + * 'EE_Messages_Queue' => 'load_lib' |
|
692 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
693 | + * or, if greater control is required, by providing a custom closure. For example: |
|
694 | + * 'Some_Class' => function () { |
|
695 | + * return new Some_Class(); |
|
696 | + * }, |
|
697 | + * This is required for instantiating dependencies |
|
698 | + * where an interface has been type hinted in a class constructor. For example: |
|
699 | + * 'Required_Interface' => function () { |
|
700 | + * return new A_Class_That_Implements_Required_Interface(); |
|
701 | + * }, |
|
702 | + * |
|
703 | + */ |
|
704 | + protected function _register_core_class_loaders() |
|
705 | + { |
|
706 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
707 | + //be used in a closure. |
|
708 | + $request = &$this->request; |
|
709 | + $response = &$this->response; |
|
710 | + $legacy_request = &$this->legacy_request; |
|
711 | + // $loader = &$this->loader; |
|
712 | + $this->_class_loaders = array( |
|
713 | + //load_core |
|
714 | + 'EE_Capabilities' => 'load_core', |
|
715 | + 'EE_Encryption' => 'load_core', |
|
716 | + 'EE_Front_Controller' => 'load_core', |
|
717 | + 'EE_Module_Request_Router' => 'load_core', |
|
718 | + 'EE_Registry' => 'load_core', |
|
719 | + 'EE_Request' => function () use (&$legacy_request) { |
|
720 | + return $legacy_request; |
|
721 | + }, |
|
722 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
723 | + return $request; |
|
724 | + }, |
|
725 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
726 | + return $response; |
|
727 | + }, |
|
728 | + 'EE_Request_Handler' => 'load_core', |
|
729 | + 'EE_Session' => 'load_core', |
|
730 | + 'EE_Cron_Tasks' => 'load_core', |
|
731 | + 'EE_System' => 'load_core', |
|
732 | + 'EE_Maintenance_Mode' => 'load_core', |
|
733 | + 'EE_Register_CPTs' => 'load_core', |
|
734 | + 'EE_Admin' => 'load_core', |
|
735 | + //load_lib |
|
736 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
737 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
738 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
739 | + 'EE_Messenger_Collection' => 'load_lib', |
|
740 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
741 | + 'EE_Messages_Processor' => 'load_lib', |
|
742 | + 'EE_Message_Repository' => 'load_lib', |
|
743 | + 'EE_Messages_Queue' => 'load_lib', |
|
744 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
745 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
746 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
747 | + 'EE_Messages_Generator' => function () { |
|
748 | + return EE_Registry::instance()->load_lib( |
|
749 | + 'Messages_Generator', |
|
750 | + array(), |
|
751 | + false, |
|
752 | + false |
|
753 | + ); |
|
754 | + }, |
|
755 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
756 | + return EE_Registry::instance()->load_lib( |
|
757 | + 'Messages_Template_Defaults', |
|
758 | + $arguments, |
|
759 | + false, |
|
760 | + false |
|
761 | + ); |
|
762 | + }, |
|
763 | + //load_model |
|
764 | + // 'EEM_Attendee' => 'load_model', |
|
765 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
766 | + // 'EEM_Message_Template' => 'load_model', |
|
767 | + //load_helper |
|
768 | + 'EEH_Parse_Shortcodes' => function () { |
|
769 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
770 | + return new EEH_Parse_Shortcodes(); |
|
771 | + } |
|
772 | + return null; |
|
773 | + }, |
|
774 | + 'EE_Template_Config' => function () { |
|
775 | + return EE_Config::instance()->template_settings; |
|
776 | + }, |
|
777 | + 'EE_Currency_Config' => function () { |
|
778 | + return EE_Config::instance()->currency; |
|
779 | + }, |
|
780 | + 'EE_Registration_Config' => function () { |
|
781 | + return EE_Config::instance()->registration; |
|
782 | + }, |
|
783 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
784 | + return LoaderFactory::getLoader(); |
|
785 | + }, |
|
786 | + 'EE_Base' => 'load_core', |
|
787 | + ); |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * can be used for supplying alternate names for classes, |
|
795 | + * or for connecting interface names to instantiable classes |
|
796 | + */ |
|
797 | + protected function _register_core_aliases() |
|
798 | + { |
|
799 | + $aliases = array( |
|
800 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
801 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
802 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
803 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
804 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
805 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
806 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
807 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
808 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
809 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
810 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
811 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
812 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
813 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
814 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
815 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
816 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
817 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
818 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
819 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
820 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
821 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
822 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
823 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
824 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
825 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
826 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
827 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
828 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
829 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
830 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
831 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
832 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
833 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
834 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
835 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
836 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
837 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
838 | + ); |
|
839 | + foreach ($aliases as $alias => $fqn) { |
|
840 | + $this->class_cache->addAlias($fqn, $alias); |
|
841 | + } |
|
842 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
843 | + $this->class_cache->addAlias( |
|
844 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
845 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
846 | + ); |
|
847 | + } |
|
848 | + } |
|
849 | + |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
854 | + * request Primarily used by unit tests. |
|
855 | + */ |
|
856 | + public function reset() |
|
857 | + { |
|
858 | + $this->_register_core_class_loaders(); |
|
859 | + $this->_register_core_dependencies(); |
|
860 | + } |
|
861 | 861 | |
862 | 862 | |
863 | 863 | } |