@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php 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 | - ); ?> |
|
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 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
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 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.38.rc.034'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.38.rc.034'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
106 | 106 | { |
107 | 107 | // check if class object is instantiated, and instantiated properly |
108 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
108 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
109 | 109 | self::$_instance = new EE_Dependency_Map($request, $response); |
110 | 110 | } |
111 | 111 | return self::$_instance; |
@@ -120,15 +120,15 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public static function register_dependencies($class, $dependencies) |
122 | 122 | { |
123 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
123 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
124 | 124 | // we need to make sure that any aliases used when registering a dependency |
125 | 125 | // get resolved to the correct class name |
126 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
126 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
127 | 127 | $alias = self::$_instance->get_alias($dependency); |
128 | 128 | unset($dependencies[$dependency]); |
129 | 129 | $dependencies[$alias] = $load_source; |
130 | 130 | } |
131 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
131 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
132 | 132 | return true; |
133 | 133 | } |
134 | 134 | return false; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | ); |
158 | 158 | } |
159 | 159 | $class_name = self::$_instance->get_alias($class_name); |
160 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
160 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
161 | 161 | self::$_instance->_class_loaders[$class_name] = $loader; |
162 | 162 | return true; |
163 | 163 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | public function add_alias($class_name, $alias, $for_class = '') |
256 | 256 | { |
257 | 257 | if ($for_class !== '') { |
258 | - if (! isset($this->_aliases[$for_class])) { |
|
258 | + if ( ! isset($this->_aliases[$for_class])) { |
|
259 | 259 | $this->_aliases[$for_class] = array(); |
260 | 260 | } |
261 | 261 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | */ |
301 | 301 | public function get_alias($class_name = '', $for_class = '') |
302 | 302 | { |
303 | - if (! $this->has_alias($class_name, $for_class)) { |
|
303 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
304 | 304 | return $class_name; |
305 | 305 | } |
306 | 306 | if ($for_class !== '') { |
@@ -498,10 +498,10 @@ discard block |
||
498 | 498 | 'EE_Front_Controller' => 'load_core', |
499 | 499 | 'EE_Module_Request_Router' => 'load_core', |
500 | 500 | 'EE_Registry' => 'load_core', |
501 | - 'EE_Request' => function () use (&$request) { |
|
501 | + 'EE_Request' => function() use (&$request) { |
|
502 | 502 | return $request; |
503 | 503 | }, |
504 | - 'EE_Response' => function () use (&$response) { |
|
504 | + 'EE_Response' => function() use (&$response) { |
|
505 | 505 | return $response; |
506 | 506 | }, |
507 | 507 | 'EE_Request_Handler' => 'load_core', |
@@ -518,10 +518,10 @@ discard block |
||
518 | 518 | 'EE_Messages_Queue' => 'load_lib', |
519 | 519 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
520 | 520 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
521 | - 'EE_Messages_Generator' => function () { |
|
521 | + 'EE_Messages_Generator' => function() { |
|
522 | 522 | return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
523 | 523 | }, |
524 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
524 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
525 | 525 | return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
526 | 526 | }, |
527 | 527 | //load_model |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | 'EEM_Message_Template_Group' => 'load_model', |
530 | 530 | 'EEM_Message_Template' => 'load_model', |
531 | 531 | //load_helper |
532 | - 'EEH_Parse_Shortcodes' => function () { |
|
532 | + 'EEH_Parse_Shortcodes' => function() { |
|
533 | 533 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
534 | 534 | return new EEH_Parse_Shortcodes(); |
535 | 535 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -18,563 +18,563 @@ discard block |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * This means that the requested class dependency is not present in the dependency map |
|
23 | - */ |
|
24 | - const not_registered = 0; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
29 | - */ |
|
30 | - const load_new_object = 1; |
|
31 | - |
|
32 | - /** |
|
33 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
34 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
35 | - */ |
|
36 | - const load_from_cache = 2; |
|
37 | - |
|
38 | - /** |
|
39 | - * @type EE_Dependency_Map $_instance |
|
40 | - */ |
|
41 | - protected static $_instance; |
|
42 | - |
|
43 | - /** |
|
44 | - * @type EE_Request $request |
|
45 | - */ |
|
46 | - protected $_request; |
|
47 | - |
|
48 | - /** |
|
49 | - * @type EE_Response $response |
|
50 | - */ |
|
51 | - protected $_response; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @type array $_dependency_map |
|
56 | - */ |
|
57 | - protected $_dependency_map = array(); |
|
58 | - |
|
59 | - /** |
|
60 | - * @type array $_class_loaders |
|
61 | - */ |
|
62 | - protected $_class_loaders = array(); |
|
63 | - |
|
64 | - /** |
|
65 | - * @type array $_aliases |
|
66 | - */ |
|
67 | - protected $_aliases = array(); |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * EE_Dependency_Map constructor. |
|
73 | - * |
|
74 | - * @param EE_Request $request |
|
75 | - * @param EE_Response $response |
|
76 | - */ |
|
77 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
78 | - { |
|
79 | - $this->_request = $request; |
|
80 | - $this->_response = $response; |
|
81 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
82 | - do_action('EE_Dependency_Map____construct'); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - */ |
|
89 | - public function initialize() |
|
90 | - { |
|
91 | - $this->_register_core_dependencies(); |
|
92 | - $this->_register_core_class_loaders(); |
|
93 | - $this->_register_core_aliases(); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @singleton method used to instantiate class object |
|
100 | - * @access public |
|
101 | - * @param EE_Request $request |
|
102 | - * @param EE_Response $response |
|
103 | - * @return EE_Dependency_Map instance |
|
104 | - */ |
|
105 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
106 | - { |
|
107 | - // check if class object is instantiated, and instantiated properly |
|
108 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
109 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
110 | - } |
|
111 | - return self::$_instance; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @param string $class |
|
118 | - * @param array $dependencies |
|
119 | - * @return boolean |
|
120 | - */ |
|
121 | - public static function register_dependencies($class, $dependencies) |
|
122 | - { |
|
123 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
124 | - // we need to make sure that any aliases used when registering a dependency |
|
125 | - // get resolved to the correct class name |
|
126 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
127 | - $alias = self::$_instance->get_alias($dependency); |
|
128 | - unset($dependencies[$dependency]); |
|
129 | - $dependencies[$alias] = $load_source; |
|
130 | - } |
|
131 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
132 | - return true; |
|
133 | - } |
|
134 | - return false; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $class_name |
|
141 | - * @param string $loader |
|
142 | - * @return bool |
|
143 | - * @throws EE_Error |
|
144 | - */ |
|
145 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
146 | - { |
|
147 | - // check that loader method starts with "load_" and exists in EE_Registry |
|
148 | - if ( |
|
149 | - ! is_callable($loader) |
|
150 | - && (strpos($loader, 'load_') !== 0 || ! method_exists('EE_Registry', $loader)) |
|
151 | - ) { |
|
152 | - throw new EE_Error( |
|
153 | - sprintf( |
|
154 | - esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
155 | - $loader |
|
156 | - ) |
|
157 | - ); |
|
158 | - } |
|
159 | - $class_name = self::$_instance->get_alias($class_name); |
|
160 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
161 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
162 | - return true; |
|
163 | - } |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return array |
|
171 | - */ |
|
172 | - public function dependency_map() |
|
173 | - { |
|
174 | - return $this->_dependency_map; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
181 | - * |
|
182 | - * @param string $class_name |
|
183 | - * @return boolean |
|
184 | - */ |
|
185 | - public function has($class_name = '') |
|
186 | - { |
|
187 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
194 | - * |
|
195 | - * @param string $class_name |
|
196 | - * @param string $dependency |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
200 | - { |
|
201 | - $dependency = $this->get_alias($dependency); |
|
202 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
203 | - ? true |
|
204 | - : false; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
211 | - * |
|
212 | - * @param string $class_name |
|
213 | - * @param string $dependency |
|
214 | - * @return int |
|
215 | - */ |
|
216 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
217 | - { |
|
218 | - $dependency = $this->get_alias($dependency); |
|
219 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
220 | - ? $this->_dependency_map[$class_name][$dependency] |
|
221 | - : EE_Dependency_Map::not_registered; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * @param string $class_name |
|
228 | - * @return string | Closure |
|
229 | - */ |
|
230 | - public function class_loader($class_name) |
|
231 | - { |
|
232 | - $class_name = $this->get_alias($class_name); |
|
233 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return array |
|
240 | - */ |
|
241 | - public function class_loaders() |
|
242 | - { |
|
243 | - return $this->_class_loaders; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * adds an alias for a classname |
|
250 | - * |
|
251 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
252 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
253 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
254 | - */ |
|
255 | - public function add_alias($class_name, $alias, $for_class = '') |
|
256 | - { |
|
257 | - if ($for_class !== '') { |
|
258 | - if (! isset($this->_aliases[$for_class])) { |
|
259 | - $this->_aliases[$for_class] = array(); |
|
260 | - } |
|
261 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
262 | - } |
|
263 | - $this->_aliases[$class_name] = $alias; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * returns TRUE if the provided class name has an alias |
|
270 | - * |
|
271 | - * @param string $class_name |
|
272 | - * @param string $for_class |
|
273 | - * @return bool |
|
274 | - */ |
|
275 | - public function has_alias($class_name = '', $for_class = '') |
|
276 | - { |
|
277 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
278 | - || ( |
|
279 | - isset($this->_aliases[$class_name]) |
|
280 | - && ! is_array($this->_aliases[$class_name]) |
|
281 | - ); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
288 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
289 | - * for example: |
|
290 | - * if the following two entries were added to the _aliases array: |
|
291 | - * array( |
|
292 | - * 'interface_alias' => 'some\namespace\interface' |
|
293 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
294 | - * ) |
|
295 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
296 | - * to load an instance of 'some\namespace\classname' |
|
297 | - * |
|
298 | - * @param string $class_name |
|
299 | - * @param string $for_class |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function get_alias($class_name = '', $for_class = '') |
|
303 | - { |
|
304 | - if (! $this->has_alias($class_name, $for_class)) { |
|
305 | - return $class_name; |
|
306 | - } |
|
307 | - if ($for_class !== '') { |
|
308 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
309 | - } |
|
310 | - return $this->get_alias($this->_aliases[$class_name]); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
317 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
318 | - * This is done by using the following class constants: |
|
319 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
320 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
321 | - */ |
|
322 | - protected function _register_core_dependencies() |
|
323 | - { |
|
324 | - $this->_dependency_map = array( |
|
325 | - 'EE_Request_Handler' => array( |
|
326 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
327 | - ), |
|
328 | - 'EE_System' => array( |
|
329 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
330 | - ), |
|
331 | - 'EE_Session' => array( |
|
332 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
333 | - ), |
|
334 | - 'EE_Cart' => array( |
|
335 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
336 | - ), |
|
337 | - 'EE_Front_Controller' => array( |
|
338 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
339 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
340 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
341 | - ), |
|
342 | - 'EE_Messenger_Collection_Loader' => array( |
|
343 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
344 | - ), |
|
345 | - 'EE_Message_Type_Collection_Loader' => array( |
|
346 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
347 | - ), |
|
348 | - 'EE_Message_Resource_Manager' => array( |
|
349 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
350 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
351 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
352 | - ), |
|
353 | - 'EE_Message_Factory' => array( |
|
354 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
355 | - ), |
|
356 | - 'EE_messages' => array( |
|
357 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
358 | - ), |
|
359 | - 'EE_Messages_Generator' => array( |
|
360 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
361 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
362 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
363 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
364 | - ), |
|
365 | - 'EE_Messages_Processor' => array( |
|
366 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
367 | - ), |
|
368 | - 'EE_Messages_Queue' => array( |
|
369 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
370 | - ), |
|
371 | - 'EE_Messages_Template_Defaults' => array( |
|
372 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
373 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
374 | - ), |
|
375 | - 'EE_Message_To_Generate_From_Request' => array( |
|
376 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
377 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
378 | - ), |
|
379 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
380 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
381 | - ), |
|
382 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
383 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
384 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
385 | - ), |
|
386 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
387 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
388 | - ), |
|
389 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
390 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
391 | - ), |
|
392 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
393 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
394 | - ), |
|
395 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
396 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
397 | - ), |
|
398 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
399 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
400 | - ), |
|
401 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
402 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
403 | - ), |
|
404 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
405 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
406 | - ), |
|
407 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
408 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
409 | - ), |
|
410 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
411 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
412 | - ), |
|
413 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
414 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
415 | - ), |
|
416 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
417 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
418 | - ), |
|
419 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
420 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
421 | - ), |
|
422 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
423 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
424 | - ), |
|
425 | - 'EE_Data_Migration_Class_Base' => array( |
|
426 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
427 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
428 | - ), |
|
429 | - 'EE_DMS_Core_4_1_0' => array( |
|
430 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
431 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
432 | - ), |
|
433 | - 'EE_DMS_Core_4_2_0' => array( |
|
434 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
435 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
436 | - ), |
|
437 | - 'EE_DMS_Core_4_3_0' => array( |
|
438 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
439 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
440 | - ), |
|
441 | - 'EE_DMS_Core_4_4_0' => array( |
|
442 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
443 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
444 | - ), |
|
445 | - 'EE_DMS_Core_4_5_0' => array( |
|
446 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
447 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_DMS_Core_4_6_0' => array( |
|
450 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
452 | - ), |
|
453 | - 'EE_DMS_Core_4_7_0' => array( |
|
454 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
455 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
456 | - ), |
|
457 | - 'EE_DMS_Core_4_8_0' => array( |
|
458 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_DMS_Core_4_9_0' => array( |
|
462 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
463 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - ); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Registers how core classes are loaded. |
|
472 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
473 | - * 'EE_Request_Handler' => 'load_core' |
|
474 | - * 'EE_Messages_Queue' => 'load_lib' |
|
475 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
476 | - * or, if greater control is required, by providing a custom closure. For example: |
|
477 | - * 'Some_Class' => function () { |
|
478 | - * return new Some_Class(); |
|
479 | - * }, |
|
480 | - * This is required for instantiating dependencies |
|
481 | - * where an interface has been type hinted in a class constructor. For example: |
|
482 | - * 'Required_Interface' => function () { |
|
483 | - * return new A_Class_That_Implements_Required_Interface(); |
|
484 | - * }, |
|
485 | - */ |
|
486 | - protected function _register_core_class_loaders() |
|
487 | - { |
|
488 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
489 | - //be used in a closure. |
|
490 | - $request = &$this->_request; |
|
491 | - $response = &$this->_response; |
|
492 | - $this->_class_loaders = array( |
|
493 | - //load_core |
|
494 | - 'EE_Capabilities' => 'load_core', |
|
495 | - 'EE_Encryption' => 'load_core', |
|
496 | - 'EE_Front_Controller' => 'load_core', |
|
497 | - 'EE_Module_Request_Router' => 'load_core', |
|
498 | - 'EE_Registry' => 'load_core', |
|
499 | - 'EE_Request' => function () use (&$request) { |
|
500 | - return $request; |
|
501 | - }, |
|
502 | - 'EE_Response' => function () use (&$response) { |
|
503 | - return $response; |
|
504 | - }, |
|
505 | - 'EE_Request_Handler' => 'load_core', |
|
506 | - 'EE_Session' => 'load_core', |
|
507 | - 'EE_System' => 'load_core', |
|
508 | - //load_lib |
|
509 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
510 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
511 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
512 | - 'EE_Messenger_Collection' => 'load_lib', |
|
513 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
514 | - 'EE_Messages_Processor' => 'load_lib', |
|
515 | - 'EE_Message_Repository' => 'load_lib', |
|
516 | - 'EE_Messages_Queue' => 'load_lib', |
|
517 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
518 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
519 | - 'EE_Messages_Generator' => function () { |
|
520 | - return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
521 | - }, |
|
522 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
523 | - return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
524 | - }, |
|
525 | - //load_model |
|
526 | - 'EEM_Message_Template_Group' => 'load_model', |
|
527 | - 'EEM_Message_Template' => 'load_model', |
|
528 | - //load_helper |
|
529 | - 'EEH_Parse_Shortcodes' => function () { |
|
530 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
531 | - return new EEH_Parse_Shortcodes(); |
|
532 | - } |
|
533 | - return null; |
|
534 | - }, |
|
535 | - ); |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * can be used for supplying alternate names for classes, |
|
542 | - * or for connecting interface names to instantiable classes |
|
543 | - */ |
|
544 | - protected function _register_core_aliases() |
|
545 | - { |
|
546 | - $this->_aliases = array( |
|
547 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
548 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
549 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
550 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
551 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
552 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
553 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
554 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
555 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
556 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
557 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
558 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
559 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
560 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
561 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
562 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
563 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
564 | - ); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - |
|
569 | - /** |
|
570 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
571 | - * request Primarily used by unit tests. |
|
572 | - */ |
|
573 | - public function reset() |
|
574 | - { |
|
575 | - $this->_register_core_class_loaders(); |
|
576 | - $this->_register_core_dependencies(); |
|
577 | - } |
|
21 | + /** |
|
22 | + * This means that the requested class dependency is not present in the dependency map |
|
23 | + */ |
|
24 | + const not_registered = 0; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
29 | + */ |
|
30 | + const load_new_object = 1; |
|
31 | + |
|
32 | + /** |
|
33 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
34 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
35 | + */ |
|
36 | + const load_from_cache = 2; |
|
37 | + |
|
38 | + /** |
|
39 | + * @type EE_Dependency_Map $_instance |
|
40 | + */ |
|
41 | + protected static $_instance; |
|
42 | + |
|
43 | + /** |
|
44 | + * @type EE_Request $request |
|
45 | + */ |
|
46 | + protected $_request; |
|
47 | + |
|
48 | + /** |
|
49 | + * @type EE_Response $response |
|
50 | + */ |
|
51 | + protected $_response; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @type array $_dependency_map |
|
56 | + */ |
|
57 | + protected $_dependency_map = array(); |
|
58 | + |
|
59 | + /** |
|
60 | + * @type array $_class_loaders |
|
61 | + */ |
|
62 | + protected $_class_loaders = array(); |
|
63 | + |
|
64 | + /** |
|
65 | + * @type array $_aliases |
|
66 | + */ |
|
67 | + protected $_aliases = array(); |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * EE_Dependency_Map constructor. |
|
73 | + * |
|
74 | + * @param EE_Request $request |
|
75 | + * @param EE_Response $response |
|
76 | + */ |
|
77 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
78 | + { |
|
79 | + $this->_request = $request; |
|
80 | + $this->_response = $response; |
|
81 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
82 | + do_action('EE_Dependency_Map____construct'); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + */ |
|
89 | + public function initialize() |
|
90 | + { |
|
91 | + $this->_register_core_dependencies(); |
|
92 | + $this->_register_core_class_loaders(); |
|
93 | + $this->_register_core_aliases(); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @singleton method used to instantiate class object |
|
100 | + * @access public |
|
101 | + * @param EE_Request $request |
|
102 | + * @param EE_Response $response |
|
103 | + * @return EE_Dependency_Map instance |
|
104 | + */ |
|
105 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
106 | + { |
|
107 | + // check if class object is instantiated, and instantiated properly |
|
108 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
109 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
110 | + } |
|
111 | + return self::$_instance; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @param string $class |
|
118 | + * @param array $dependencies |
|
119 | + * @return boolean |
|
120 | + */ |
|
121 | + public static function register_dependencies($class, $dependencies) |
|
122 | + { |
|
123 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
124 | + // we need to make sure that any aliases used when registering a dependency |
|
125 | + // get resolved to the correct class name |
|
126 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
127 | + $alias = self::$_instance->get_alias($dependency); |
|
128 | + unset($dependencies[$dependency]); |
|
129 | + $dependencies[$alias] = $load_source; |
|
130 | + } |
|
131 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
132 | + return true; |
|
133 | + } |
|
134 | + return false; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $class_name |
|
141 | + * @param string $loader |
|
142 | + * @return bool |
|
143 | + * @throws EE_Error |
|
144 | + */ |
|
145 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
146 | + { |
|
147 | + // check that loader method starts with "load_" and exists in EE_Registry |
|
148 | + if ( |
|
149 | + ! is_callable($loader) |
|
150 | + && (strpos($loader, 'load_') !== 0 || ! method_exists('EE_Registry', $loader)) |
|
151 | + ) { |
|
152 | + throw new EE_Error( |
|
153 | + sprintf( |
|
154 | + esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
155 | + $loader |
|
156 | + ) |
|
157 | + ); |
|
158 | + } |
|
159 | + $class_name = self::$_instance->get_alias($class_name); |
|
160 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
161 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
162 | + return true; |
|
163 | + } |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return array |
|
171 | + */ |
|
172 | + public function dependency_map() |
|
173 | + { |
|
174 | + return $this->_dependency_map; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
181 | + * |
|
182 | + * @param string $class_name |
|
183 | + * @return boolean |
|
184 | + */ |
|
185 | + public function has($class_name = '') |
|
186 | + { |
|
187 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
194 | + * |
|
195 | + * @param string $class_name |
|
196 | + * @param string $dependency |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
200 | + { |
|
201 | + $dependency = $this->get_alias($dependency); |
|
202 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
203 | + ? true |
|
204 | + : false; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
211 | + * |
|
212 | + * @param string $class_name |
|
213 | + * @param string $dependency |
|
214 | + * @return int |
|
215 | + */ |
|
216 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
217 | + { |
|
218 | + $dependency = $this->get_alias($dependency); |
|
219 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
220 | + ? $this->_dependency_map[$class_name][$dependency] |
|
221 | + : EE_Dependency_Map::not_registered; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * @param string $class_name |
|
228 | + * @return string | Closure |
|
229 | + */ |
|
230 | + public function class_loader($class_name) |
|
231 | + { |
|
232 | + $class_name = $this->get_alias($class_name); |
|
233 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return array |
|
240 | + */ |
|
241 | + public function class_loaders() |
|
242 | + { |
|
243 | + return $this->_class_loaders; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * adds an alias for a classname |
|
250 | + * |
|
251 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
252 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
253 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
254 | + */ |
|
255 | + public function add_alias($class_name, $alias, $for_class = '') |
|
256 | + { |
|
257 | + if ($for_class !== '') { |
|
258 | + if (! isset($this->_aliases[$for_class])) { |
|
259 | + $this->_aliases[$for_class] = array(); |
|
260 | + } |
|
261 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
262 | + } |
|
263 | + $this->_aliases[$class_name] = $alias; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * returns TRUE if the provided class name has an alias |
|
270 | + * |
|
271 | + * @param string $class_name |
|
272 | + * @param string $for_class |
|
273 | + * @return bool |
|
274 | + */ |
|
275 | + public function has_alias($class_name = '', $for_class = '') |
|
276 | + { |
|
277 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
278 | + || ( |
|
279 | + isset($this->_aliases[$class_name]) |
|
280 | + && ! is_array($this->_aliases[$class_name]) |
|
281 | + ); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
288 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
289 | + * for example: |
|
290 | + * if the following two entries were added to the _aliases array: |
|
291 | + * array( |
|
292 | + * 'interface_alias' => 'some\namespace\interface' |
|
293 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
294 | + * ) |
|
295 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
296 | + * to load an instance of 'some\namespace\classname' |
|
297 | + * |
|
298 | + * @param string $class_name |
|
299 | + * @param string $for_class |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function get_alias($class_name = '', $for_class = '') |
|
303 | + { |
|
304 | + if (! $this->has_alias($class_name, $for_class)) { |
|
305 | + return $class_name; |
|
306 | + } |
|
307 | + if ($for_class !== '') { |
|
308 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
309 | + } |
|
310 | + return $this->get_alias($this->_aliases[$class_name]); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
317 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
318 | + * This is done by using the following class constants: |
|
319 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
320 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
321 | + */ |
|
322 | + protected function _register_core_dependencies() |
|
323 | + { |
|
324 | + $this->_dependency_map = array( |
|
325 | + 'EE_Request_Handler' => array( |
|
326 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
327 | + ), |
|
328 | + 'EE_System' => array( |
|
329 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
330 | + ), |
|
331 | + 'EE_Session' => array( |
|
332 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
333 | + ), |
|
334 | + 'EE_Cart' => array( |
|
335 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
336 | + ), |
|
337 | + 'EE_Front_Controller' => array( |
|
338 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
339 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
340 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
341 | + ), |
|
342 | + 'EE_Messenger_Collection_Loader' => array( |
|
343 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
344 | + ), |
|
345 | + 'EE_Message_Type_Collection_Loader' => array( |
|
346 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
347 | + ), |
|
348 | + 'EE_Message_Resource_Manager' => array( |
|
349 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
350 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
351 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
352 | + ), |
|
353 | + 'EE_Message_Factory' => array( |
|
354 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
355 | + ), |
|
356 | + 'EE_messages' => array( |
|
357 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
358 | + ), |
|
359 | + 'EE_Messages_Generator' => array( |
|
360 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
361 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
362 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
363 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
364 | + ), |
|
365 | + 'EE_Messages_Processor' => array( |
|
366 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
367 | + ), |
|
368 | + 'EE_Messages_Queue' => array( |
|
369 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
370 | + ), |
|
371 | + 'EE_Messages_Template_Defaults' => array( |
|
372 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
373 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
374 | + ), |
|
375 | + 'EE_Message_To_Generate_From_Request' => array( |
|
376 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
377 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
378 | + ), |
|
379 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
380 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
381 | + ), |
|
382 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
383 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
384 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
385 | + ), |
|
386 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
387 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
388 | + ), |
|
389 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
390 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
391 | + ), |
|
392 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
393 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
394 | + ), |
|
395 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
396 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
397 | + ), |
|
398 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
399 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
400 | + ), |
|
401 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
402 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
403 | + ), |
|
404 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
405 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
406 | + ), |
|
407 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
408 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
409 | + ), |
|
410 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
411 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
412 | + ), |
|
413 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
414 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
415 | + ), |
|
416 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
417 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
418 | + ), |
|
419 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
420 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
421 | + ), |
|
422 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
423 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
424 | + ), |
|
425 | + 'EE_Data_Migration_Class_Base' => array( |
|
426 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
427 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
428 | + ), |
|
429 | + 'EE_DMS_Core_4_1_0' => array( |
|
430 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
431 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
432 | + ), |
|
433 | + 'EE_DMS_Core_4_2_0' => array( |
|
434 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
435 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
436 | + ), |
|
437 | + 'EE_DMS_Core_4_3_0' => array( |
|
438 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
439 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
440 | + ), |
|
441 | + 'EE_DMS_Core_4_4_0' => array( |
|
442 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
443 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
444 | + ), |
|
445 | + 'EE_DMS_Core_4_5_0' => array( |
|
446 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
447 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_DMS_Core_4_6_0' => array( |
|
450 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
452 | + ), |
|
453 | + 'EE_DMS_Core_4_7_0' => array( |
|
454 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
455 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
456 | + ), |
|
457 | + 'EE_DMS_Core_4_8_0' => array( |
|
458 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_DMS_Core_4_9_0' => array( |
|
462 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
463 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + ); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Registers how core classes are loaded. |
|
472 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
473 | + * 'EE_Request_Handler' => 'load_core' |
|
474 | + * 'EE_Messages_Queue' => 'load_lib' |
|
475 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
476 | + * or, if greater control is required, by providing a custom closure. For example: |
|
477 | + * 'Some_Class' => function () { |
|
478 | + * return new Some_Class(); |
|
479 | + * }, |
|
480 | + * This is required for instantiating dependencies |
|
481 | + * where an interface has been type hinted in a class constructor. For example: |
|
482 | + * 'Required_Interface' => function () { |
|
483 | + * return new A_Class_That_Implements_Required_Interface(); |
|
484 | + * }, |
|
485 | + */ |
|
486 | + protected function _register_core_class_loaders() |
|
487 | + { |
|
488 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
489 | + //be used in a closure. |
|
490 | + $request = &$this->_request; |
|
491 | + $response = &$this->_response; |
|
492 | + $this->_class_loaders = array( |
|
493 | + //load_core |
|
494 | + 'EE_Capabilities' => 'load_core', |
|
495 | + 'EE_Encryption' => 'load_core', |
|
496 | + 'EE_Front_Controller' => 'load_core', |
|
497 | + 'EE_Module_Request_Router' => 'load_core', |
|
498 | + 'EE_Registry' => 'load_core', |
|
499 | + 'EE_Request' => function () use (&$request) { |
|
500 | + return $request; |
|
501 | + }, |
|
502 | + 'EE_Response' => function () use (&$response) { |
|
503 | + return $response; |
|
504 | + }, |
|
505 | + 'EE_Request_Handler' => 'load_core', |
|
506 | + 'EE_Session' => 'load_core', |
|
507 | + 'EE_System' => 'load_core', |
|
508 | + //load_lib |
|
509 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
510 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
511 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
512 | + 'EE_Messenger_Collection' => 'load_lib', |
|
513 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
514 | + 'EE_Messages_Processor' => 'load_lib', |
|
515 | + 'EE_Message_Repository' => 'load_lib', |
|
516 | + 'EE_Messages_Queue' => 'load_lib', |
|
517 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
518 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
519 | + 'EE_Messages_Generator' => function () { |
|
520 | + return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
521 | + }, |
|
522 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
523 | + return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
524 | + }, |
|
525 | + //load_model |
|
526 | + 'EEM_Message_Template_Group' => 'load_model', |
|
527 | + 'EEM_Message_Template' => 'load_model', |
|
528 | + //load_helper |
|
529 | + 'EEH_Parse_Shortcodes' => function () { |
|
530 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
531 | + return new EEH_Parse_Shortcodes(); |
|
532 | + } |
|
533 | + return null; |
|
534 | + }, |
|
535 | + ); |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * can be used for supplying alternate names for classes, |
|
542 | + * or for connecting interface names to instantiable classes |
|
543 | + */ |
|
544 | + protected function _register_core_aliases() |
|
545 | + { |
|
546 | + $this->_aliases = array( |
|
547 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
548 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
549 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
550 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
551 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
552 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
553 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
554 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
555 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
556 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
557 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
558 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
559 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
560 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
561 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
562 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
563 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
564 | + ); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + |
|
569 | + /** |
|
570 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
571 | + * request Primarily used by unit tests. |
|
572 | + */ |
|
573 | + public function reset() |
|
574 | + { |
|
575 | + $this->_register_core_class_loaders(); |
|
576 | + $this->_register_core_dependencies(); |
|
577 | + } |
|
578 | 578 | |
579 | 579 | |
580 | 580 | } |