Completed
Branch BUG-9871-email-validation (e62b1a)
by
unknown
350:41 queued 333:27
created
core/helpers/EEH_Template.helper.php 1 patch
Spacing   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 
17 17
 
18
-if ( ! function_exists( 'espresso_get_template_part' )) {
18
+if ( ! function_exists('espresso_get_template_part')) {
19 19
 	/**
20 20
 	 * espresso_get_template_part
21 21
 	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
@@ -25,14 +25,14 @@  discard block
 block discarded – undo
25 25
 	 * @param string $name The name of the specialised template.
26 26
 	 * @return string        the html output for the formatted money value
27 27
 	 */
28
-	function espresso_get_template_part( $slug = NULL, $name = NULL ) {
29
-		EEH_Template::get_template_part( $slug, $name );
28
+	function espresso_get_template_part($slug = NULL, $name = NULL) {
29
+		EEH_Template::get_template_part($slug, $name);
30 30
 	}
31 31
 }
32 32
 
33 33
 
34 34
 
35
-if ( ! function_exists( 'espresso_get_object_css_class' )) {
35
+if ( ! function_exists('espresso_get_object_css_class')) {
36 36
 	/**
37 37
 	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
38 38
 	 *
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @param  string $suffix added to the end of the generated class
43 43
 	 * @return string
44 44
 	 */
45
-	function espresso_get_object_css_class( $object = NULL, $prefix = '', $suffix = '' ) {
46
-		return EEH_Template::get_object_css_class( $object, $prefix, $suffix );
45
+	function espresso_get_object_css_class($object = NULL, $prefix = '', $suffix = '') {
46
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
47 47
 	}
48 48
 }
49 49
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 * 	@return boolean
71 71
 	 */
72 72
 	public static function is_espresso_theme() {
73
-		return wp_get_theme()->get( 'TextDomain' ) == 'event_espresso' ? TRUE : FALSE;
73
+		return wp_get_theme()->get('TextDomain') == 'event_espresso' ? TRUE : FALSE;
74 74
 	}
75 75
 
76 76
 	/**
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 	 * 	@return void
80 80
 	 */
81 81
 	public static function load_espresso_theme_functions() {
82
-		if ( ! defined( 'EE_THEME_FUNCTIONS_LOADED' )) {
83
-			if ( is_readable( EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php' )) {
84
-				require_once( EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php' );
82
+		if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
83
+			if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) {
84
+				require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php');
85 85
 			}
86 86
 		}
87 87
 	}
@@ -93,17 +93,17 @@  discard block
 block discarded – undo
93 93
 	 * 	@return array
94 94
 	 */
95 95
 	public static function get_espresso_themes() {
96
-		if ( empty( EEH_Template::$_espresso_themes )) {
97
-			$espresso_themes =  glob( EE_PUBLIC . '*', GLOB_ONLYDIR );
98
-			if ( empty( $espresso_themes ) ) {
96
+		if (empty(EEH_Template::$_espresso_themes)) {
97
+			$espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
98
+			if (empty($espresso_themes)) {
99 99
 				return array();
100 100
 			}
101
-			if (( $key = array_search( 'global_assets', $espresso_themes )) !== FALSE ) {
102
-			    unset( $espresso_themes[ $key ] );
101
+			if (($key = array_search('global_assets', $espresso_themes)) !== FALSE) {
102
+			    unset($espresso_themes[$key]);
103 103
 			}
104 104
 			EEH_Template::$_espresso_themes = array();
105
-			foreach ( $espresso_themes as $espresso_theme ) {
106
-				EEH_Template::$_espresso_themes[ basename( $espresso_theme ) ] = $espresso_theme;
105
+			foreach ($espresso_themes as $espresso_theme) {
106
+				EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
107 107
 			}
108 108
 		}
109 109
 		return EEH_Template::$_espresso_themes;
@@ -122,16 +122,16 @@  discard block
 block discarded – undo
122 122
 	 * @param bool   $return_string
123 123
 	 * @return string        the html output for the formatted money value
124 124
 	 */
125
-	public static function get_template_part( $slug = NULL, $name = NULL, $template_args = array(), $return_string = FALSE  ) {
126
-		do_action( "get_template_part_{$slug}-{$name}", $slug, $name );
125
+	public static function get_template_part($slug = NULL, $name = NULL, $template_args = array(), $return_string = FALSE) {
126
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
127 127
 		$templates = array();
128 128
 		$name = (string) $name;
129
-		if ( $name != '' ) {
129
+		if ($name != '') {
130 130
 			$templates[] = "{$slug}-{$name}.php";
131 131
 		}
132 132
 		// allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
133
-		if ( apply_filters( "FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", TRUE )) {
134
-			EEH_Template::locate_template( $templates, $template_args, TRUE, $return_string );
133
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", TRUE)) {
134
+			EEH_Template::locate_template($templates, $template_args, TRUE, $return_string);
135 135
 		}
136 136
 	}
137 137
 
@@ -182,26 +182,26 @@  discard block
 block discarded – undo
182 182
 	 * 				Used in places where you don't actually load the template, you just want to know if there's a custom version of it.
183 183
 	 * @return mixed
184 184
 	 */
185
-	public static function locate_template( $templates = array(), $template_args = array(), $load = TRUE, $return_string = TRUE, $check_if_custom = FALSE ) {
185
+	public static function locate_template($templates = array(), $template_args = array(), $load = TRUE, $return_string = TRUE, $check_if_custom = FALSE) {
186 186
 		// first use WP locate_template to check for template in the current theme folder
187
-		$template_path = locate_template( $templates );
187
+		$template_path = locate_template($templates);
188 188
 
189
-		if ( $check_if_custom && !empty( $template_path ) )
189
+		if ($check_if_custom && ! empty($template_path))
190 190
 			return TRUE;
191 191
 
192 192
 		// not in the theme
193
-		if ( empty( $template_path )) {
193
+		if (empty($template_path)) {
194 194
 			// not even a template to look for ?
195
-			if ( empty( $templates )) {
195
+			if (empty($templates)) {
196 196
 				// get post_type
197
-				$post_type = EE_Registry::instance()->REQ->get( 'post_type' );
197
+				$post_type = EE_Registry::instance()->REQ->get('post_type');
198 198
 				// get array of EE Custom Post Types
199 199
 				$EE_CPTs = EE_Register_CPTs::get_CPTs();
200 200
 				// build template name based on request
201
-				if ( isset( $EE_CPTs[ $post_type ] )) {
202
-					$archive_or_single =  is_archive() ? 'archive' : '';
203
-					$archive_or_single =  is_single() ? 'single' : $archive_or_single;
204
-					$templates = $archive_or_single . '-' . $post_type . '.php';
201
+				if (isset($EE_CPTs[$post_type])) {
202
+					$archive_or_single = is_archive() ? 'archive' : '';
203
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
204
+					$templates = $archive_or_single.'-'.$post_type.'.php';
205 205
 				}
206 206
 			}
207 207
 			// currently active EE template theme
@@ -210,81 +210,81 @@  discard block
 block discarded – undo
210 210
 			// array of paths to folders that may contain templates
211 211
 			$template_folder_paths = array(
212 212
 				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
213
-				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
213
+				EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
214 214
 				// then in the root of the /wp-content/uploads/espresso/templates/ folder
215 215
 				EVENT_ESPRESSO_TEMPLATE_DIR
216 216
 			);
217 217
 
218 218
 			//add core plugin folders for checking only if we're not $check_if_custom
219
-			if ( ! $check_if_custom ) {
219
+			if ( ! $check_if_custom) {
220 220
 				$core_paths = array(
221 221
 					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
222
-					EE_PUBLIC . $current_theme,
222
+					EE_PUBLIC.$current_theme,
223 223
 					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
224
-					EE_TEMPLATES . $current_theme,
224
+					EE_TEMPLATES.$current_theme,
225 225
 					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
226 226
 					EE_PLUGIN_DIR_PATH
227 227
 					);
228
-				$template_folder_paths = array_merge( $template_folder_paths, $core_paths );
228
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
229 229
 			}
230 230
 
231 231
 			// now filter that array
232
-			$template_folder_paths = apply_filters( 'FHEE__EEH_Template__locate_template__template_folder_paths', $template_folder_paths );
233
-			$templates = is_array( $templates ) ? $templates : array( $templates );
234
-			$template_folder_paths = is_array( $template_folder_paths ) ? $template_folder_paths : array( $template_folder_paths );
232
+			$template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', $template_folder_paths);
233
+			$templates = is_array($templates) ? $templates : array($templates);
234
+			$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
235 235
 			// array to hold all possible template paths
236 236
 			$full_template_paths = array();
237 237
 
238 238
 			// loop through $templates
239
-			foreach ( $templates as $template ) {
239
+			foreach ($templates as $template) {
240 240
 				// normalize directory separators
241
-				$template = EEH_File::standardise_directory_separators( $template );
242
-				$file_name = basename( $template );
243
-				$template_path_minus_file_name = substr( $template, 0, ( strlen( $file_name ) * -1 ) );
241
+				$template = EEH_File::standardise_directory_separators($template);
242
+				$file_name = basename($template);
243
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
244 244
 				// while looping through all template folder paths
245
-				foreach ( $template_folder_paths as $template_folder_path ) {
245
+				foreach ($template_folder_paths as $template_folder_path) {
246 246
 					// normalize directory separators
247
-					$template_folder_path = EEH_File::standardise_directory_separators( $template_folder_path );
247
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
248 248
 					// determine if any common base path exists between the two paths
249 249
 					$common_base_path = EEH_Template::_find_common_base_path(
250
-						array( $template_folder_path, $template_path_minus_file_name )
250
+						array($template_folder_path, $template_path_minus_file_name)
251 251
 					);
252
-					if ( $common_base_path !== '' ) {
252
+					if ($common_base_path !== '') {
253 253
 						// both paths have a common base, so just tack the filename onto our search path
254
-						$resolved_path = EEH_File::end_with_directory_separator( $template_folder_path ) . $file_name;
254
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
255 255
 					} else {
256 256
 						// no common base path, so let's just concatenate
257
-						$resolved_path = EEH_File::end_with_directory_separator( $template_folder_path ) . $template;
257
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
258 258
 					}
259 259
 					// build up our template locations array by adding our resolved paths
260 260
 					$full_template_paths[] = $resolved_path;
261 261
 				}
262 262
 				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
263
-				array_unshift( $full_template_paths, $template );
263
+				array_unshift($full_template_paths, $template);
264 264
 				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
265
-				array_unshift( $full_template_paths, get_stylesheet_directory() . DS . $file_name );
265
+				array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name);
266 266
 			}
267 267
 			// filter final array of full template paths
268
-			$full_template_paths = apply_filters( 'FHEE__EEH_Template__locate_template__full_template_paths', $full_template_paths, $file_name );
268
+			$full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', $full_template_paths, $file_name);
269 269
 			// now loop through our final array of template location paths and check each location
270
-			foreach ( (array)$full_template_paths as $full_template_path ) {
271
-				if ( is_readable( $full_template_path )) {
272
-					$template_path = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR, $full_template_path );
270
+			foreach ((array) $full_template_paths as $full_template_path) {
271
+				if (is_readable($full_template_path)) {
272
+					$template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
273 273
 					// hook that can be used to display the full template path that will be used
274
-					do_action( 'AHEE__EEH_Template__locate_template__full_template_path', $template_path );
274
+					do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
275 275
 					break;
276 276
 				}
277 277
 			}
278 278
 		}
279 279
 		// if we got it and you want to see it...
280
-		if ( $template_path && $load && ! $check_if_custom  ) {
281
-			if ( $return_string ) {
282
-				return EEH_Template::display_template( $template_path, $template_args, TRUE );
280
+		if ($template_path && $load && ! $check_if_custom) {
281
+			if ($return_string) {
282
+				return EEH_Template::display_template($template_path, $template_args, TRUE);
283 283
 			} else {
284
-				EEH_Template::display_template( $template_path, $template_args, FALSE );
284
+				EEH_Template::display_template($template_path, $template_args, FALSE);
285 285
 			}
286 286
 		}
287
-		return $check_if_custom && ! empty( $template_path ) ? TRUE : $template_path;
287
+		return $check_if_custom && ! empty($template_path) ? TRUE : $template_path;
288 288
 	}
289 289
 
290 290
 
@@ -297,21 +297,21 @@  discard block
 block discarded – undo
297 297
 	 * @param array $paths
298 298
 	 * @return string
299 299
 	 */
300
-	protected static function _find_common_base_path( $paths ) {
300
+	protected static function _find_common_base_path($paths) {
301 301
 		$last_offset = 0;
302 302
 		$common_base_path = '';
303
-		while ( ( $index = strpos( $paths[ 0 ], DS, $last_offset ) ) !== false ) {
303
+		while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
304 304
 			$dir_length = $index - $last_offset + 1;
305
-			$directory = substr( $paths[ 0 ], $last_offset, $dir_length );
306
-			foreach ( $paths as $path ) {
307
-				if ( substr( $path, $last_offset, $dir_length ) != $directory ) {
305
+			$directory = substr($paths[0], $last_offset, $dir_length);
306
+			foreach ($paths as $path) {
307
+				if (substr($path, $last_offset, $dir_length) != $directory) {
308 308
 					return $common_base_path;
309 309
 				}
310 310
 			}
311 311
 			$common_base_path .= $directory;
312 312
 			$last_offset = $index + 1;
313 313
 		}
314
-		return substr( $common_base_path, 0, -1 );
314
+		return substr($common_base_path, 0, -1);
315 315
 	}
316 316
 
317 317
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 	 * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
324 324
 	 * @return mixed string
325 325
 	 */
326
-	public static function display_template( $template_path = FALSE, $template_args = array(), $return_string = FALSE ) {
326
+	public static function display_template($template_path = FALSE, $template_args = array(), $return_string = FALSE) {
327 327
 
328 328
 		/**
329 329
 		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
@@ -334,26 +334,26 @@  discard block
 block discarded – undo
334 334
 		 *
335 335
 		 * @since 4.6.0
336 336
 		 */
337
-		$template_path = apply_filters( 'FHEE__EEH_Template__display_template__template_path', $template_path );
338
-		$template_args = apply_filters( 'FHEE__EEH_Template__display_template__template_args', $template_args );
337
+		$template_path = apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
338
+		$template_args = apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
339 339
 
340 340
 		// you gimme nuttin - YOU GET NUTTIN !!
341
-		if ( ! $template_path || ! is_readable( $template_path )) {
341
+		if ( ! $template_path || ! is_readable($template_path)) {
342 342
 			return '';
343 343
 		}
344 344
 		// if $template_args are not in an array, then make it so
345
-		if ( ! is_array( $template_args ) && ! is_object( $template_args )) {
346
-			$template_args = array( $template_args );
345
+		if ( ! is_array($template_args) && ! is_object($template_args)) {
346
+			$template_args = array($template_args);
347 347
 		}
348
-		extract( (array) $template_args);
348
+		extract((array) $template_args);
349 349
 
350
-		if ( $return_string ) {
350
+		if ($return_string) {
351 351
 			// because we want to return a string, we are going to capture the output
352 352
 			ob_start();
353
-			include( $template_path );
353
+			include($template_path);
354 354
 			return ob_get_clean();
355 355
 		} else {
356
-			include( $template_path );
356
+			include($template_path);
357 357
 		}
358 358
 		return '';
359 359
 	}
@@ -371,27 +371,27 @@  discard block
 block discarded – undo
371 371
 	 * @param  string $suffix added to the end of the generated class
372 372
 	 * @return string
373 373
 	 */
374
-	public static function get_object_css_class( $object = NULL, $prefix = '', $suffix = '' ) {
374
+	public static function get_object_css_class($object = NULL, $prefix = '', $suffix = '') {
375 375
 		// in the beginning...
376
-		$prefix = ! empty( $prefix ) ? rtrim( $prefix, '-' ) . '-' : '';
376
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
377 377
 		// da muddle
378 378
 		$class = '';
379 379
 		// the end
380
-		$suffix = ! empty( $suffix ) ? '-' . ltrim( $suffix, '-' ) : '';
380
+		$suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
381 381
 		// is the passed object an EE object ?
382
-		if ( $object instanceof EE_Base_Class ) {
382
+		if ($object instanceof EE_Base_Class) {
383 383
 			// grab the exact type of object
384
-			$obj_class = get_class( $object );
384
+			$obj_class = get_class($object);
385 385
 			// depending on the type of object...
386
-			switch ( $obj_class ) {
386
+			switch ($obj_class) {
387 387
 				// no specifics just yet...
388 388
 				default :
389
-					$class = strtolower( str_replace( '_', '-', $obj_class ));
390
-					$class .= method_exists( $obj_class, 'name' ) ? '-' . sanitize_title( $object->name() ) : '';
389
+					$class = strtolower(str_replace('_', '-', $obj_class));
390
+					$class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
391 391
 
392 392
 			}
393 393
 		}
394
-		return $prefix . $class . $suffix;
394
+		return $prefix.$class.$suffix;
395 395
 	}
396 396
 
397 397
 
@@ -407,54 +407,54 @@  discard block
 block discarded – undo
407 407
 	 * @param string      $cur_code_span_class
408 408
 	 * @return string        the html output for the formatted money value
409 409
 	 */
410
-	public static function format_currency( $amount = NULL, $return_raw = FALSE, $display_code = TRUE, $CNT_ISO = '', $cur_code_span_class = 'currency-code' ) {
410
+	public static function format_currency($amount = NULL, $return_raw = FALSE, $display_code = TRUE, $CNT_ISO = '', $cur_code_span_class = 'currency-code') {
411 411
 		// ensure amount was received
412
-		if ( is_null( $amount ) ) {
413
-			$msg = __( 'In order to format currency, an amount needs to be passed.', 'event_espresso' );
414
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
412
+		if (is_null($amount)) {
413
+			$msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
414
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
415 415
 			return '';
416 416
 		}
417 417
 		//ensure amount is float
418
-		$amount = apply_filters( 'FHEE__EEH_Template__format_currency__raw_amount', (float) $amount );
419
-		$CNT_ISO = apply_filters( 'FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount );
418
+		$amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
419
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
420 420
 		// filter raw amount (allows 0.00 to be changed to "free" for example)
421
-		$amount_formatted = apply_filters( 'FHEE__EEH_Template__format_currency__amount', $amount, $return_raw );
421
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
422 422
 		// still a number or was amount converted to a string like "free" ?
423
-		if ( is_float( $amount_formatted )) {
423
+		if (is_float($amount_formatted)) {
424 424
 			// was a country ISO code passed ? if so generate currency config object for that country
425
-			$mny = $CNT_ISO !== '' ? new EE_Currency_Config( $CNT_ISO ) : NULL;
425
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : NULL;
426 426
 			// verify results
427
-			if ( ! $mny instanceof EE_Currency_Config ) {
427
+			if ( ! $mny instanceof EE_Currency_Config) {
428 428
 				// set default config country currency settings
429 429
 				$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config ? EE_Registry::instance()->CFG->currency : new EE_Currency_Config();
430 430
 			}
431 431
 			// format float
432
-			$amount_formatted = number_format( $amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds );
432
+			$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
433 433
 			// add formatting ?
434
-			if ( ! $return_raw ) {
434
+			if ( ! $return_raw) {
435 435
 				// add currency sign
436
-				if( $mny->sign_b4 ){
437
-					if( $amount >= 0 ){
438
-						$amount_formatted = $mny->sign . $amount_formatted;
439
-					}else{
440
-						$amount_formatted = '-' . $mny->sign . str_replace( '-', '', $amount_formatted );
436
+				if ($mny->sign_b4) {
437
+					if ($amount >= 0) {
438
+						$amount_formatted = $mny->sign.$amount_formatted;
439
+					} else {
440
+						$amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
441 441
 					}
442 442
 
443
-				}else{
444
-					$amount_formatted =  $amount_formatted . $mny->sign;
443
+				} else {
444
+					$amount_formatted = $amount_formatted.$mny->sign;
445 445
 				}
446 446
 
447 447
 				// filter to allow global setting of display_code
448
-				$display_code = apply_filters( 'FHEE__EEH_Template__format_currency__display_code', $display_code );
448
+				$display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
449 449
 
450 450
 				// add currency code ?
451
-				$amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
451
+				$amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted;
452 452
 			}
453 453
 			// filter results
454
-			$amount_formatted = apply_filters( 'FHEE__EEH_Template__format_currency__amount_formatted', $amount_formatted, $mny, $return_raw );
454
+			$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', $amount_formatted, $mny, $return_raw);
455 455
 		}
456 456
 		// clean up vars
457
-		unset( $mny );
457
+		unset($mny);
458 458
 		// return formatted currency amount
459 459
 		return $amount_formatted;
460 460
 	}
@@ -469,11 +469,11 @@  discard block
 block discarded – undo
469 469
 	 * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
470 470
 	 * @return string             The localized label for the status id.
471 471
 	 */
472
-	public static function pretty_status( $status_id, $plural = FALSE, $schema = 'upper' ) {
472
+	public static function pretty_status($status_id, $plural = FALSE, $schema = 'upper') {
473 473
 		/** @type EEM_Status $EEM_Status */
474
-		$EEM_Status = EE_Registry::instance()->load_model( 'Status' );
475
-		$status = $EEM_Status->localized_status( array( $status_id => __( 'unknown', 'event_espresso' )), $plural, $schema );
476
-		return $status[ $status_id ];
474
+		$EEM_Status = EE_Registry::instance()->load_model('Status');
475
+		$status = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural, $schema);
476
+		return $status[$status_id];
477 477
 	}
478 478
 
479 479
 
@@ -488,21 +488,21 @@  discard block
 block discarded – undo
488 488
 	 * @param string  $title
489 489
 	 * @return string the html output for the button
490 490
 	 */
491
-	public static function get_button_or_link( $url, $label, $class = 'button-primary', $icon = '', $title = '' ) {
491
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') {
492 492
 		$icon_html = '';
493
-		if ( ! empty( $icon ) ) {
494
-			$dashicons = preg_split( "(ee-icon |dashicons )", $icon );
495
-			$dashicons = array_filter( $dashicons );
496
-			$count = count( $dashicons );
493
+		if ( ! empty($icon)) {
494
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
495
+			$dashicons = array_filter($dashicons);
496
+			$count = count($dashicons);
497 497
 			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
498
-			foreach ( $dashicons as $dashicon ) {
499
-				$type = strpos( $dashicon, 'ee-icon' ) !== false ? 'ee-icon ' : 'dashicons ';
500
-				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
498
+			foreach ($dashicons as $dashicon) {
499
+				$type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
500
+				$icon_html .= '<span class="'.$type.$dashicon.'"></span>';
501 501
 			}
502 502
 			$icon_html .= $count > 1 ? '</span>' : '';
503 503
 		}
504
-		$label = ! empty( $icon ) ? $icon_html . $label : $label;
505
-		$button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
504
+		$label = ! empty($icon) ? $icon_html.$label : $label;
505
+		$button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.$url.'" class="'.$class.'" title="'.$title.'">'.$label.'</a>';
506 506
 		return $button;
507 507
 	}
508 508
 
@@ -519,21 +519,21 @@  discard block
 block discarded – undo
519 519
 	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
520 520
 	 * @return string              generated link
521 521
 	 */
522
-	public static function get_help_tab_link( $help_tab_id, $page = FALSE, $action = FALSE, $icon_style = FALSE, $help_text = FALSE ) {
522
+	public static function get_help_tab_link($help_tab_id, $page = FALSE, $action = FALSE, $icon_style = FALSE, $help_text = FALSE) {
523 523
 
524
-		if ( ! $page )
525
-			$page = isset( $_REQUEST['page'] ) && ! empty( $_REQUEST['page'] ) ? sanitize_key( $_REQUEST['page'] ) : $page;
524
+		if ( ! $page)
525
+			$page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
526 526
 
527
-		if ( ! $action )
528
-			$action = isset( $_REQUEST['action'] ) && ! empty( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : $action;
527
+		if ( ! $action)
528
+			$action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
529 529
 
530 530
 		$action = empty($action) ? 'default' : $action;
531 531
 
532 532
 
533
-		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
534
-		$icon = !$icon_style ? ' dashicons-editor-help' : $icon_style;
535
-		$help_text = !$help_text ? '' : $help_text;
536
-		return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', 'event_espresso') . '" > ' . $help_text . ' </a>';
533
+		$help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
534
+		$icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
535
+		$help_text = ! $help_text ? '' : $help_text;
536
+		return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__('Click to open the \'Help\' tab for more information about this feature.', 'event_espresso').'" > '.$help_text.' </a>';
537 537
 	}
538 538
 
539 539
 
@@ -545,31 +545,31 @@  discard block
 block discarded – undo
545 545
 	 * @param EE_Help_Tour
546 546
 	 * @return string         html
547 547
 	 */
548
-	public static function help_tour_stops_generator( EE_Help_Tour $tour ) {
548
+	public static function help_tour_stops_generator(EE_Help_Tour $tour) {
549 549
 		$id = $tour->get_slug();
550 550
 		$stops = $tour->get_stops();
551 551
 
552
-		$content = '<ol style="display:none" id="' . $id . '">';
552
+		$content = '<ol style="display:none" id="'.$id.'">';
553 553
 
554
-		foreach ( $stops as $stop ) {
555
-			$data_id = !empty( $stop['id'] ) ? ' data-id="' . $stop['id'] . '"' : '';
556
-			$data_class = empty( $data_id ) && !empty( $stop['class'] ) ? ' data-class="' . $stop['class'] . '"' : '';
554
+		foreach ($stops as $stop) {
555
+			$data_id = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : '';
556
+			$data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : '';
557 557
 
558 558
 			//if container is set to modal then let's make sure we set the options accordingly
559
-			if ( empty( $data_id ) && empty( $data_class ) ) {
559
+			if (empty($data_id) && empty($data_class)) {
560 560
 				$stop['options']['modal'] = true;
561 561
 				$stop['options']['expose'] = true;
562 562
 			}
563 563
 
564
-			$custom_class = !empty( $stop['custom_class'] ) ? ' class="' . $stop['custom_class'] . '"' : '';
565
-			$button_text = !empty( $stop['button_text'] ) ? ' data-button="' . $stop['button_text'] . '"' : '';
564
+			$custom_class = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : '';
565
+			$button_text = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : '';
566 566
 			$inner_content = isset($stop['content']) ? $stop['content'] : '';
567 567
 
568 568
 			//options
569
-			if ( isset( $stop['options'] ) && is_array( $stop['options'] ) ) {
569
+			if (isset($stop['options']) && is_array($stop['options'])) {
570 570
 				$options = ' data-options="';
571
-				foreach ( $stop['options'] as $option => $value ) {
572
-					$options .= $option . ':' . $value . ';';
571
+				foreach ($stop['options'] as $option => $value) {
572
+					$options .= $option.':'.$value.';';
573 573
 				}
574 574
 				$options .= '"';
575 575
 			} else {
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 			}
578 578
 
579 579
 			//let's put all together
580
-			$content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
580
+			$content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>';
581 581
 		}
582 582
 
583 583
 		$content .= '</ol>';
@@ -598,31 +598,31 @@  discard block
 block discarded – undo
598 598
 	 * @throws EE_Error
599 599
 	 * @return string               html structure for status.
600 600
 	 */
601
-	public static function status_legend( $status_array, $active_status = '' ) {
602
-		if ( !is_array( $status_array ) )
603
-			throw new EE_Error( __('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', 'event_espresso') );
601
+	public static function status_legend($status_array, $active_status = '') {
602
+		if ( ! is_array($status_array))
603
+			throw new EE_Error(__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', 'event_espresso'));
604 604
 
605 605
 		$setup_array = array();
606
-		foreach ( $status_array as $item => $status ) {
606
+		foreach ($status_array as $item => $status) {
607 607
 			$setup_array[$item] = array(
608
-					'class' => 'ee-status-legend ee-status-legend-' . $status,
609
-					'desc' => EEH_Template::pretty_status( $status, FALSE, 'sentence' ),
608
+					'class' => 'ee-status-legend ee-status-legend-'.$status,
609
+					'desc' => EEH_Template::pretty_status($status, FALSE, 'sentence'),
610 610
 					'status' => $status
611 611
 				);
612 612
 		}
613 613
 
614
-		$content = '<div class="ee-list-table-legend-container">' . "\n";
615
-		$content .= '<h3>' . __('Status Legend', 'event_espresso') . '</h3>' . "\n";
616
-		$content .= '<dl class="ee-list-table-legend">' . "\n\t";
617
-		foreach ( $setup_array as $item => $details ) {
614
+		$content = '<div class="ee-list-table-legend-container">'."\n";
615
+		$content .= '<h3>'.__('Status Legend', 'event_espresso').'</h3>'."\n";
616
+		$content .= '<dl class="ee-list-table-legend">'."\n\t";
617
+		foreach ($setup_array as $item => $details) {
618 618
 			$active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
619
-			$content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
620
-			$content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
621
-			$content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
622
-			$content .= '</dt>' . "\n";
619
+			$content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t";
620
+			$content .= '<span class="'.$details['class'].'"></span>'."\n\t\t";
621
+			$content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t";
622
+			$content .= '</dt>'."\n";
623 623
 		}
624
-		$content .= '</dl>' . "\n";
625
-		$content .= '</div>' . "\n";
624
+		$content .= '</dl>'."\n";
625
+		$content .= '</div>'."\n";
626 626
 		return $content;
627 627
 	}
628 628
 
@@ -635,8 +635,8 @@  discard block
 block discarded – undo
635 635
 	 * @return string
636 636
 	 */
637 637
 	public static function layout_array_as_table($data) {
638
-	if (is_object($data) || $data instanceof __PHP_Incomplete_Class ) {
639
-		$data = (array)$data;
638
+	if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
639
+		$data = (array) $data;
640 640
 	}
641 641
 	ob_start();
642 642
 	if (is_array($data)) {
@@ -649,10 +649,10 @@  discard block
 block discarded – undo
649 649
 						?>
650 650
 						<tr>
651 651
 							<td>
652
-								<?php echo $data_key;?>
652
+								<?php echo $data_key; ?>
653 653
 							</td>
654 654
 							<td>
655
-								<?php echo self::layout_array_as_table($data_values);?>
655
+								<?php echo self::layout_array_as_table($data_values); ?>
656 656
 							</td>
657 657
 						</tr>
658 658
 						<?php
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 			<ul>
667 667
 				<?php
668 668
 				foreach ($data as $datum) {
669
-					echo "<li>"; echo self::layout_array_as_table($datum);echo "</li>";
669
+					echo "<li>"; echo self::layout_array_as_table($datum); echo "</li>";
670 670
 				}?>
671 671
 			</ul>
672 672
 			<?php
@@ -696,8 +696,8 @@  discard block
 block discarded – undo
696 696
 	 *
697 697
 	 * @return string
698 698
 	 */
699
-	public static function paging_html( $total_items, $current, $per_page, $url, $show_num_field = TRUE, $paged_arg_name = 'paged', $items_label = array() ) {
700
-		echo self::get_paging_html( $total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, $items_label );
699
+	public static function paging_html($total_items, $current, $per_page, $url, $show_num_field = TRUE, $paged_arg_name = 'paged', $items_label = array()) {
700
+		echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, $items_label);
701 701
 	}
702 702
 
703 703
 
@@ -721,13 +721,13 @@  discard block
 block discarded – undo
721 721
 	 *                                 )
722 722
 	 * @return  string
723 723
 	 */
724
-	public static function get_paging_html( $total_items, $current, $per_page, $url, $show_num_field = TRUE, $paged_arg_name = 'paged', $items_label = array() ) {
724
+	public static function get_paging_html($total_items, $current, $per_page, $url, $show_num_field = TRUE, $paged_arg_name = 'paged', $items_label = array()) {
725 725
 		$page_links = array();
726 726
 		$disable_first = $disable_last = '';
727 727
 		$total_items = (int) $total_items;
728 728
 		$per_page = (int) $per_page;
729 729
 		$current = (int) $current;
730
-		$paged_arg_name = empty( $paged_arg_name ) ? 'paged' : sanitize_key( $paged_arg_name );
730
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
731 731
 
732 732
 		//filter items_label
733 733
 		$items_label = apply_filters(
@@ -735,68 +735,68 @@  discard block
 block discarded – undo
735 735
 			$items_label
736 736
 		);
737 737
 
738
-		if ( empty( $items_label )
739
-		     || ! is_array( $items_label )
740
-		     || ! isset( $items_label['single'] )
741
-		     || ! isset( $items_label['plural'] ) ) {
738
+		if (empty($items_label)
739
+		     || ! is_array($items_label)
740
+		     || ! isset($items_label['single'])
741
+		     || ! isset($items_label['plural'])) {
742 742
 			$items_label = array(
743
-				'single' => __( '1 item', 'event_espresso' ),
744
-				'plural' => __( '%s items', 'event_espresso' )
743
+				'single' => __('1 item', 'event_espresso'),
744
+				'plural' => __('%s items', 'event_espresso')
745 745
 			);
746 746
 		} else {
747 747
 			$items_label = array(
748
-				'single' => '1 ' . esc_html( $items_label['single'] ),
749
-				'plural' => '%s ' . esc_html( $items_label['plural'] )
748
+				'single' => '1 '.esc_html($items_label['single']),
749
+				'plural' => '%s '.esc_html($items_label['plural'])
750 750
 			);
751 751
 		}
752 752
 
753
-		$total_pages = ceil( $total_items / $per_page );
753
+		$total_pages = ceil($total_items / $per_page);
754 754
 
755
-		if ( $total_pages <= 1 )
755
+		if ($total_pages <= 1)
756 756
 			return '';
757 757
 
758
-		$item_label = $total_items > 1 ? sprintf( $items_label['plural'], $total_items ) : $items_label['single'];
758
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
759 759
 
760
-		$output = '<span class="displaying-num">' . $item_label . '</span>';
760
+		$output = '<span class="displaying-num">'.$item_label.'</span>';
761 761
 
762
-		if ( $current === 1 ) {
762
+		if ($current === 1) {
763 763
 			$disable_first = ' disabled';
764 764
 		}
765
-		if ( $current == $total_pages ) {
765
+		if ($current == $total_pages) {
766 766
 			$disable_last = ' disabled';
767 767
 		}
768 768
 
769
-		$page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
770
-			'first-page' . $disable_first,
771
-			esc_attr__( 'Go to the first page' ),
772
-			esc_url( remove_query_arg( $paged_arg_name, $url ) ),
769
+		$page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
770
+			'first-page'.$disable_first,
771
+			esc_attr__('Go to the first page'),
772
+			esc_url(remove_query_arg($paged_arg_name, $url)),
773 773
 			'&laquo;'
774 774
 		);
775 775
 
776 776
 		$page_links[] = sprintf(
777 777
 			'<a class="%s" title="%s" href="%s">%s</a>',
778
-			'prev-page' . $disable_first,
779
-			esc_attr__( 'Go to the previous page' ),
780
-			esc_url( add_query_arg( $paged_arg_name, max( 1, $current-1 ), $url ) ),
778
+			'prev-page'.$disable_first,
779
+			esc_attr__('Go to the previous page'),
780
+			esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
781 781
 			'&lsaquo;'
782 782
 		);
783 783
 
784
-		if ( ! $show_num_field ) {
784
+		if ( ! $show_num_field) {
785 785
 			$html_current_page = $current;
786 786
 		} else {
787
-			$html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
788
-				esc_attr__( 'Current page' ),
787
+			$html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
788
+				esc_attr__('Current page'),
789 789
 				$current,
790
-				strlen( $total_pages )
790
+				strlen($total_pages)
791 791
 			);
792 792
 		}
793 793
 
794 794
 		$html_total_pages = sprintf(
795 795
 			'<span class="total-pages">%s</span>',
796
-			number_format_i18n( $total_pages )
796
+			number_format_i18n($total_pages)
797 797
 		);
798 798
 		$page_links[] = sprintf(
799
-			_x( '%3$s%1$s of %2$s%4$s', 'paging' ),
799
+			_x('%3$s%1$s of %2$s%4$s', 'paging'),
800 800
 			$html_current_page,
801 801
 			$html_total_pages,
802 802
 			'<span class="paging-input">',
@@ -805,29 +805,29 @@  discard block
 block discarded – undo
805 805
 
806 806
 		$page_links[] = sprintf(
807 807
 			'<a class="%s" title="%s" href="%s">%s</a>',
808
-			'next-page' . $disable_last,
809
-			esc_attr__( 'Go to the next page' ),
810
-			esc_url( add_query_arg( $paged_arg_name, min( $total_pages, $current+1 ), $url ) ),
808
+			'next-page'.$disable_last,
809
+			esc_attr__('Go to the next page'),
810
+			esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
811 811
 			'&rsaquo;'
812 812
 		);
813 813
 
814 814
 		$page_links[] = sprintf(
815 815
 			'<a class="%s" title="%s" href="%s">%s</a>',
816
-			'last-page' . $disable_last,
817
-			esc_attr__( 'Go to the last page' ),
818
-			esc_url( add_query_arg( $paged_arg_name, $total_pages, $url ) ),
816
+			'last-page'.$disable_last,
817
+			esc_attr__('Go to the last page'),
818
+			esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
819 819
 			'&raquo;'
820 820
 		);
821 821
 
822
-		$output .= "\n" . '<span class="pagination-links">' . join( "\n", $page_links ) . '</span>';
822
+		$output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
823 823
 		// set page class
824
-		if ( $total_pages ) {
824
+		if ($total_pages) {
825 825
 			$page_class = $total_pages < 2 ? ' one-page' : '';
826 826
 		} else {
827 827
 			$page_class = ' no-pages';
828 828
 		}
829 829
 
830
-		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
830
+		return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
831 831
 	}
832 832
 
833 833
 
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
 //add_filter( 'FHEE__EEH_Template__format_currency__amount', 'convert_zero_to_free', 10, 2 );
844 844
 
845 845
 
846
-if ( ! function_exists( 'espresso_pagination' ) ) {
846
+if ( ! function_exists('espresso_pagination')) {
847 847
 	/**
848 848
 	 *    espresso_pagination
849 849
 	 *
@@ -855,21 +855,21 @@  discard block
 block discarded – undo
855 855
 		$big = 999999999; // need an unlikely integer
856 856
 		$pagination = paginate_links(
857 857
 		array(
858
-		'base'         => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
858
+		'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
859 859
 		'format'       => '?paged=%#%',
860
-		'current'      => max( 1, get_query_var( 'paged' ) ),
860
+		'current'      => max(1, get_query_var('paged')),
861 861
 		'total'        => $wp_query->max_num_pages,
862 862
 		'show_all'     => true,
863 863
 		'end_size'     => 10,
864 864
 		'mid_size'     => 6,
865 865
 		'prev_next'    => true,
866
-		'prev_text'    => __( '&lsaquo; PREV', 'event_espresso' ),
867
-		'next_text'    => __( 'NEXT &rsaquo;', 'event_espresso' ),
866
+		'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
867
+		'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
868 868
 		'type'         => 'plain',
869 869
 		'add_args'     => false,
870 870
 		'add_fragment' => ''
871 871
 		)
872 872
 		);
873
-		echo ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
873
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : '';
874 874
 	}
875 875
 }
876 876
\ No newline at end of file
Please login to merge, or discard this patch.
payment_methods/Paypal_Standard/EE_Paypal_Standard_Form.form.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -21,35 +21,35 @@  discard block
 block discarded – undo
21 21
 	/**
22 22
 	 * @param EE_PMT_Paypal_Standard $payment_method_type
23 23
 	 */
24
-	public function __construct( $payment_method_type ){
24
+	public function __construct($payment_method_type) {
25 25
 		parent::__construct(
26 26
 			array(
27 27
 				'payment_method_type'          => $payment_method_type,
28 28
 				'extra_meta_inputs'            => array(
29
-					'paypal_id'        => new EE_Text_Input( array(
30
-						'html_label_text' => sprintf( __( "Paypal Email %s", 'event_espresso' ), $payment_method_type->get_help_tab_link() ),
31
-						'html_help_text'  => __( "Typically [email protected]", 'event_espresso' ),
29
+					'paypal_id'        => new EE_Text_Input(array(
30
+						'html_label_text' => sprintf(__("Paypal Email %s", 'event_espresso'), $payment_method_type->get_help_tab_link()),
31
+						'html_help_text'  => __("Typically [email protected]", 'event_espresso'),
32 32
 						'required'        => true
33
-					) ),
34
-					'image_url'        => new EE_Admin_File_Uploader_Input( array(
35
-						'html_help_text'  => __( "Used for your business/personal logo on the PayPal page", 'event_espresso' ),
36
-						'html_label_text' => __( 'Image URL', 'event_espresso' )
37
-					) ),
38
-					'paypal_taxes'     => new EE_Yes_No_Input( array(
39
-						'html_label_text' => sprintf( __( 'Paypal Calculates Taxes %s', 'event_espresso' ), $payment_method_type->get_help_tab_link() ),
40
-						'html_help_text'  => __( 'Whether Paypal should add taxes to the order', 'event_espresso' ),
33
+					)),
34
+					'image_url'        => new EE_Admin_File_Uploader_Input(array(
35
+						'html_help_text'  => __("Used for your business/personal logo on the PayPal page", 'event_espresso'),
36
+						'html_label_text' => __('Image URL', 'event_espresso')
37
+					)),
38
+					'paypal_taxes'     => new EE_Yes_No_Input(array(
39
+						'html_label_text' => sprintf(__('Paypal Calculates Taxes %s', 'event_espresso'), $payment_method_type->get_help_tab_link()),
40
+						'html_help_text'  => __('Whether Paypal should add taxes to the order', 'event_espresso'),
41 41
 						'default'         => false
42
-					) ),
43
-					'paypal_shipping'  => new EE_Yes_No_Input( array(
44
-						'html_label_text' => sprintf( __( 'Paypal Calculates Shipping %s', 'event_espresso' ), $payment_method_type->get_help_tab_link() ),
45
-						'html_help_text'  => __( 'Whether Paypal should add shipping surcharges', 'event_espresso' ),
42
+					)),
43
+					'paypal_shipping'  => new EE_Yes_No_Input(array(
44
+						'html_label_text' => sprintf(__('Paypal Calculates Shipping %s', 'event_espresso'), $payment_method_type->get_help_tab_link()),
45
+						'html_help_text'  => __('Whether Paypal should add shipping surcharges', 'event_espresso'),
46 46
 						'default'         => false
47
-					) ),
48
-					'shipping_details' => new EE_Select_Input( array(
49
-						EE_PMT_Paypal_Standard::shipping_info_none     => __( "Do not prompt for an address", 'event_espresso' ),
50
-						EE_PMT_Paypal_Standard::shipping_info_optional => __( "Prompt for an address, but do not require it", 'event_espresso' ),
51
-						EE_PMT_Paypal_Standard::shipping_info_required => __( "Prompt for an address, and require it", 'event_espresso' )
52
-					) )
47
+					)),
48
+					'shipping_details' => new EE_Select_Input(array(
49
+						EE_PMT_Paypal_Standard::shipping_info_none     => __("Do not prompt for an address", 'event_espresso'),
50
+						EE_PMT_Paypal_Standard::shipping_info_optional => __("Prompt for an address, but do not require it", 'event_espresso'),
51
+						EE_PMT_Paypal_Standard::shipping_info_required => __("Prompt for an address, and require it", 'event_espresso')
52
+					))
53 53
 				)
54 54
 			)
55 55
 		);
@@ -60,28 +60,28 @@  discard block
 block discarded – undo
60 60
 	/**
61 61
 	 * @param array $req_data
62 62
 	 */
63
-	protected function _normalize( $req_data ) {
64
-		parent::_normalize( $req_data );
65
-		$paypal_calculates_shipping = $this->get_input_value( 'paypal_shipping' );
66
-		$paypal_calculates_taxes = $this->get_input_value( 'paypal_taxes' );
67
-		$paypal_requests_address_info = $this->get_input_value( 'shipping_details' );
63
+	protected function _normalize($req_data) {
64
+		parent::_normalize($req_data);
65
+		$paypal_calculates_shipping = $this->get_input_value('paypal_shipping');
66
+		$paypal_calculates_taxes = $this->get_input_value('paypal_taxes');
67
+		$paypal_requests_address_info = $this->get_input_value('shipping_details');
68 68
 		if (
69
-			( $paypal_calculates_shipping || $paypal_calculates_taxes ) &&
69
+			($paypal_calculates_shipping || $paypal_calculates_taxes) &&
70 70
 			$paypal_requests_address_info == EE_PMT_Paypal_Standard::shipping_info_none
71 71
 		) {
72 72
 			//they want paypal to calculate taxes or shipping. They need to ask for
73 73
 			//address info, otherwise paypal can't calculate taxes or shipping
74 74
 			/** @type EE_Select_Input $shipping_details_input */
75
-			$shipping_details_input = $this->get_input( 'shipping_details' );
76
-			$shipping_details_input->set_default( EE_PMT_Paypal_Standard::shipping_info_optional );
75
+			$shipping_details_input = $this->get_input('shipping_details');
76
+			$shipping_details_input->set_default(EE_PMT_Paypal_Standard::shipping_info_optional);
77 77
 			$shipping_details_input_options = $shipping_details_input->options();
78 78
 			EE_Error::add_attention(
79 79
 				sprintf(
80
-					__( 'Automatically set "%s" to "%s" because Paypal requires address info in order to calculate shipping or taxes.', 'event_espresso' ),
81
-					strip_tags( $shipping_details_input->html_label_text() ),
82
-					isset( $shipping_details_input_options[ EE_PMT_Paypal_Standard::shipping_info_optional ] )
83
-						? $shipping_details_input_options[ EE_PMT_Paypal_Standard::shipping_info_optional ]
84
-						: __( 'Unknown', 'event_espresso' )
80
+					__('Automatically set "%s" to "%s" because Paypal requires address info in order to calculate shipping or taxes.', 'event_espresso'),
81
+					strip_tags($shipping_details_input->html_label_text()),
82
+					isset($shipping_details_input_options[EE_PMT_Paypal_Standard::shipping_info_optional])
83
+						? $shipping_details_input_options[EE_PMT_Paypal_Standard::shipping_info_optional]
84
+						: __('Unknown', 'event_espresso')
85 85
 				),
86 86
 				__FILE__, __FUNCTION__, __LINE__
87 87
 			);
Please login to merge, or discard this patch.
admin_pages/maintenance/Maintenance_Admin_Page.core.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
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
 /**
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 class Maintenance_Admin_Page extends EE_Admin_Page {
31 31
 
32 32
 
33
-	public function __construct( $routing = TRUE ) {
34
-		parent::__construct( $routing );
33
+	public function __construct($routing = TRUE) {
34
+		parent::__construct($routing);
35 35
 	}
36 36
 
37 37
 
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
 
47 47
 
48 48
 	protected function _ajax_hooks() {
49
-		add_action('wp_ajax_migration_step',array($this,'migration_step'));
50
-		add_action('wp_ajax_add_error_to_migrations_ran',array($this,'add_error_to_migrations_ran'));
49
+		add_action('wp_ajax_migration_step', array($this, 'migration_step'));
50
+		add_action('wp_ajax_add_error_to_migrations_ran', array($this, 'add_error_to_migrations_ran'));
51 51
 	}
52 52
 
53 53
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		$this->_admin_page_title = EE_MAINTENANCE_LABEL;
57 57
 		$this->_labels = array(
58 58
 			'buttons' => array(
59
-				'reset_capabilities' => __( 'Reset Event Espresso Capabilities', 'event_espresso' )
59
+				'reset_capabilities' => __('Reset Event Espresso Capabilities', 'event_espresso')
60 60
 				)
61 61
 			);
62 62
 	}
@@ -155,23 +155,23 @@  discard block
 block discarded – undo
155 155
 	 * default maintenance page. If we're in maintenance mode level 2, then we need to show
156 156
 	 * the migration scripts and all that UI.
157 157
 	 */
158
-	public function _maintenance(){
158
+	public function _maintenance() {
159 159
 		//it all depends if we're in maintenance model level 1 (frontend-only) or
160 160
 		//level 2 (everything except maintenance page)
161
-		try{
161
+		try {
162 162
 			//get the current maintenance level and check if
163 163
 			//we are removed
164 164
 			$mm = EE_Maintenance_Mode::instance()->level();
165 165
 			$placed_in_mm = EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
166
-			if( $mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm){
166
+			if ($mm == EE_Maintenance_Mode::level_2_complete_maintenance && ! $placed_in_mm) {
167 167
 				//we just took the site out of maintenance mode, so notify the user.
168 168
 				//unfortunately this message appears to be echoed on the NEXT page load...
169 169
 				//oh well, we should really be checking for this on addon deactivation anyways
170
-				EE_Error::add_attention( __( 'Site taken out of maintenance mode because no data migration scripts are required', 'event_espresso' ) );
171
-				$this->_process_notices( array( 'page' => 'espresso_maintenance_settings'), false );
170
+				EE_Error::add_attention(__('Site taken out of maintenance mode because no data migration scripts are required', 'event_espresso'));
171
+				$this->_process_notices(array('page' => 'espresso_maintenance_settings'), false);
172 172
 			}
173 173
 			//in case an exception is thrown while trying to handle migrations
174
-			switch(EE_Maintenance_Mode::instance()->level()){
174
+			switch (EE_Maintenance_Mode::instance()->level()) {
175 175
 				case EE_Maintenance_Mode::level_0_not_in_maintenance:
176 176
 				case EE_Maintenance_Mode::level_1_frontend_only_maintenance:
177 177
 					$show_maintenance_switch = true;
@@ -183,18 +183,18 @@  discard block
 block discarded – undo
183 183
 				case EE_Maintenance_Mode::level_2_complete_maintenance:
184 184
 					$show_maintenance_switch = false;
185 185
 					$show_migration_progress = true;
186
-					if(isset($this->_req_data['continue_migration'])){
186
+					if (isset($this->_req_data['continue_migration'])) {
187 187
 						$show_backup_db_text = false;
188
-					}else{
188
+					} else {
189 189
 						$show_backup_db_text = true;
190 190
 					}
191 191
 					$scripts_needing_to_run = EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts();
192 192
 					$addons_should_be_upgraded_first = EE_Data_Migration_Manager::instance()->addons_need_updating();
193 193
 					$script_names = array();
194 194
 					$current_script = NULL;
195
-					foreach($scripts_needing_to_run as $script){
196
-						if($script instanceof EE_Data_Migration_Script_Base){
197
-							if( ! $current_script){
195
+					foreach ($scripts_needing_to_run as $script) {
196
+						if ($script instanceof EE_Data_Migration_Script_Base) {
197
+							if ( ! $current_script) {
198 198
 								$current_script = $script;
199 199
 								$current_script->migration_page_hooks();
200 200
 							}
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 			}
206 206
 			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
207 207
 			$exception_thrown = false;
208
-		}catch(EE_Error $e){
208
+		} catch (EE_Error $e) {
209 209
 
210 210
 			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
211 211
 			//now, just so we can display the page correctly, make a error migration script stage object
@@ -215,54 +215,54 @@  discard block
 block discarded – undo
215 215
 			$exception_thrown = true;
216 216
 		}
217 217
 		$current_db_state = EE_Data_Migration_Manager::instance()->ensure_current_database_state_is_set();
218
-		$current_db_state = str_replace( '.decaf', '', $current_db_state );
219
-		if($exception_thrown ||
220
-				(	$most_recent_migration &&
218
+		$current_db_state = str_replace('.decaf', '', $current_db_state);
219
+		if ($exception_thrown ||
220
+				($most_recent_migration &&
221 221
 					$most_recent_migration instanceof EE_Data_Migration_Script_Base &&
222 222
 					$most_recent_migration->is_broken()
223
-				)){
224
-			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_was_borked_page.template.php';
225
-			$this->_template_args[ 'support_url' ] = 'http://eventespresso.com/support/forums/';
226
-			$this->_template_args[ 'next_url' ] = EEH_URL::add_query_args_and_nonce(array( 'action' => 'confirm_migration_crash_report_sent', 'success' => '0' ), EE_MAINTENANCE_ADMIN_URL );
227
-		}elseif($addons_should_be_upgraded_first){
228
-			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_upgrade_addons_before_migrating.template.php';
229
-		}else{
230
-			if($most_recent_migration &&
231
-					$most_recent_migration instanceof EE_Data_Migration_Script_Base  &&
232
-					$most_recent_migration->can_continue()){
223
+				)) {
224
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_was_borked_page.template.php';
225
+			$this->_template_args['support_url'] = 'http://eventespresso.com/support/forums/';
226
+			$this->_template_args['next_url'] = EEH_URL::add_query_args_and_nonce(array('action' => 'confirm_migration_crash_report_sent', 'success' => '0'), EE_MAINTENANCE_ADMIN_URL);
227
+		}elseif ($addons_should_be_upgraded_first) {
228
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_upgrade_addons_before_migrating.template.php';
229
+		} else {
230
+			if ($most_recent_migration &&
231
+					$most_recent_migration instanceof EE_Data_Migration_Script_Base &&
232
+					$most_recent_migration->can_continue()) {
233 233
 				$show_backup_db_text = false;
234 234
 				$show_continue_current_migration_script = true;
235 235
 				$show_most_recent_migration = true;
236
-			}elseif(isset($this->_req_data['continue_migration'])){
236
+			}elseif (isset($this->_req_data['continue_migration'])) {
237 237
 				$show_most_recent_migration = true;
238 238
 				$show_continue_current_migration_script = false;
239
-			}else{
239
+			} else {
240 240
 				$show_most_recent_migration = false;
241 241
 				$show_continue_current_migration_script = false;
242 242
 			}
243 243
 
244
-			if(isset($current_script)){
244
+			if (isset($current_script)) {
245 245
 				$migrates_to = $current_script->migrates_to_version();
246
-				$plugin_slug = $migrates_to[ 'slug' ];
247
-				$new_version = $migrates_to[ 'version' ];
248
-				$this->_template_args = array_merge($this->_template_args,array(
249
-					'current_db_state'=>  sprintf(__("EE%s (%s)", "event_espresso"), isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3,$plugin_slug),
250
-					'next_db_state'=>isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'),$new_version,$plugin_slug) : NULL));
246
+				$plugin_slug = $migrates_to['slug'];
247
+				$new_version = $migrates_to['version'];
248
+				$this->_template_args = array_merge($this->_template_args, array(
249
+					'current_db_state'=>  sprintf(__("EE%s (%s)", "event_espresso"), isset($current_db_state[$plugin_slug]) ? $current_db_state[$plugin_slug] : 3, $plugin_slug),
250
+					'next_db_state'=>isset($current_script) ? sprintf(__("EE%s (%s)", 'event_espresso'), $new_version, $plugin_slug) : NULL));
251 251
 			}
252 252
 
253
-			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_migration_page.template.php';
253
+			$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_migration_page.template.php';
254 254
 			$this->_template_args = array_merge(
255 255
 				$this->_template_args,
256 256
 				array(
257
-					'show_most_recent_migration' => $show_most_recent_migration,//flag for showing the most recent migration's status and/or errors
258
-					'show_migration_progress' => $show_migration_progress,//flag for showing the option to run migrations and see their progress
259
-					'show_backup_db_text' => $show_backup_db_text,//flag for showing text telling the user to backup their DB
260
-					'show_maintenance_switch'=> $show_maintenance_switch,//flag for showing the option to change maintenance mode between levels 0 and 1
261
-					'script_names'=>$script_names,//array of names of scripts that have run
262
-					'show_continue_current_migration_script'=>$show_continue_current_migration_script,//flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
257
+					'show_most_recent_migration' => $show_most_recent_migration, //flag for showing the most recent migration's status and/or errors
258
+					'show_migration_progress' => $show_migration_progress, //flag for showing the option to run migrations and see their progress
259
+					'show_backup_db_text' => $show_backup_db_text, //flag for showing text telling the user to backup their DB
260
+					'show_maintenance_switch'=> $show_maintenance_switch, //flag for showing the option to change maintenance mode between levels 0 and 1
261
+					'script_names'=>$script_names, //array of names of scripts that have run
262
+					'show_continue_current_migration_script'=>$show_continue_current_migration_script, //flag to change wording to indicating that we're only CONTINUING a migration script (somehow it got interrupted0
263 263
 					'reset_db_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action'=>'reset_db'), EE_MAINTENANCE_ADMIN_URL),
264
-					'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action'=>'change_maintenance_level'),EE_MAINTENANCE_ADMIN_URL),
265
-					'ultimate_db_state'=>  sprintf(__("EE%s", 'event_espresso'),espresso_version()),
264
+					'update_migration_script_page_link' => EE_Admin_Page::add_query_args_and_nonce(array('action'=>'change_maintenance_level'), EE_MAINTENANCE_ADMIN_URL),
265
+					'ultimate_db_state'=>  sprintf(__("EE%s", 'event_espresso'), espresso_version()),
266 266
 				)
267 267
 			);
268 268
 		//make sure we have the form fields helper available. It usually is, but sometimes it isn't
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 			'status_fatal_error'=>  EE_Data_Migration_Manager::status_fatal_error,
277 277
 			'status_completed'=>  EE_Data_Migration_Manager::status_completed));
278 278
 		}
279
-		$this->_template_args['most_recent_migration'] = $most_recent_migration;//the actual most recently ran migration
279
+		$this->_template_args['most_recent_migration'] = $most_recent_migration; //the actual most recently ran migration
280 280
 		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, $this->_template_args, TRUE);
281 281
 		$this->display_admin_page_with_sidebar();
282 282
 	}
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	/**
287 287
 	 * returns JSON and executes another step of the currently-executing data migration (called via ajax)
288 288
 	 */
289
-	public function migration_step(){
289
+	public function migration_step() {
290 290
 		$this->_template_args['data'] = EE_Data_Migration_Manager::instance()->response_to_migration_ajax_request();
291 291
 		$this->_return_json();
292 292
 	}
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 	 * Can be used by js when it notices a response with HTML in it in order
298 298
 	 * to log the malformed response
299 299
 	 */
300
-	public function add_error_to_migrations_ran(){
300
+	public function add_error_to_migrations_ran() {
301 301
 		EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($this->_req_data['message']);
302 302
 		$this->_template_args['data'] = array('ok'=>true);
303 303
 		$this->_return_json();
@@ -308,14 +308,14 @@  discard block
 block discarded – undo
308 308
 	/**
309 309
 	 * changes the maintenance level, provided there are still no migration scripts that shoudl run
310 310
 	 */
311
-	public function _change_maintenance_level(){
311
+	public function _change_maintenance_level() {
312 312
 		$new_level = intval($this->_req_data['maintenance_mode_level']);
313
-		if( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()){
313
+		if ( ! EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) {
314 314
 			EE_Maintenance_Mode::instance()->set_maintenance_level($new_level);
315 315
 			$success = true;
316
-		}else{
316
+		} else {
317 317
 			EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
318
-			$success= false;
318
+			$success = false;
319 319
 		}
320 320
 		$this->_redirect_after_action($success, 'Maintenance Mode', __("Updated", "event_espresso"));
321 321
 	}
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
 	/**
326 326
 	 * a tab with options for reseting and/or deleting EE data
327 327
 	 */
328
-	public function _data_reset_and_delete(){
329
-		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_data_reset_and_delete.template.php';
330
-		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button( 'reset_capabilities', 'reset_capabilities', array(),  'button button-primary' );
328
+	public function _data_reset_and_delete() {
329
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_data_reset_and_delete.template.php';
330
+		$this->_template_args['reset_capabilities_button'] = $this->get_action_link_or_button('reset_capabilities', 'reset_capabilities', array(), 'button button-primary');
331 331
 		$this->_template_args['delete_db_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'delete_db'), EE_MAINTENANCE_ADMIN_URL);
332 332
 		$this->_template_args['reset_db_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'reset_db'), EE_MAINTENANCE_ADMIN_URL);
333 333
 		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, $this->_template_args, TRUE);
@@ -337,9 +337,9 @@  discard block
 block discarded – undo
337 337
 
338 338
 
339 339
 	protected function _reset_capabilities() {
340
-		EE_Registry::instance()->CAP->init_caps( true );
341
-		EE_Error::add_success( __('Default Event Espresso capabilities have been restored for all current roles.', 'event_espresso' ) );
342
-		$this->_redirect_after_action( FALSE, '', '', array( 'action' => 'data_reset' ), TRUE );
340
+		EE_Registry::instance()->CAP->init_caps(true);
341
+		EE_Error::add_success(__('Default Event Espresso capabilities have been restored for all current roles.', 'event_espresso'));
342
+		$this->_redirect_after_action(FALSE, '', '', array('action' => 'data_reset'), TRUE);
343 343
 	}
344 344
 
345 345
 	/**
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 	 */
350 350
 	protected function _reattempt_migration() {
351 351
 		EE_Data_Migration_Manager::instance()->reattempt();
352
-		$this->_redirect_after_action( FALSE, '', '', array( 'action' => 'default' ), TRUE );
352
+		$this->_redirect_after_action(FALSE, '', '', array('action' => 'default'), TRUE);
353 353
 	}
354 354
 
355 355
 
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	/**
359 359
 	 * shows the big ol' System Information page
360 360
 	 */
361
-	public function _system_status(){
362
-		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_system_stati_page.template.php';
361
+	public function _system_status() {
362
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_system_stati_page.template.php';
363 363
 		$this->_template_args['system_stati'] = EEM_System_Status::instance()->get_system_stati();
364 364
 		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, $this->_template_args, TRUE);
365 365
 		$this->display_admin_page_with_sidebar();
@@ -367,30 +367,30 @@  discard block
 block discarded – undo
367 367
 
368 368
 
369 369
 
370
-	public function _send_migration_crash_report(){
370
+	public function _send_migration_crash_report() {
371 371
 		$from = $this->_req_data['from'];
372 372
 		$from_name = $this->_req_data['from_name'];
373 373
 		$body = $this->_req_data['body'];
374
-		try{
374
+		try {
375 375
 		$success = wp_mail(EE_SUPPORT_EMAIL,
376 376
 				'Migration Crash Report',
377
-				$body."/r/n<br>".  print_r(EEM_System_Status::instance()->get_system_stati(),true),
377
+				$body."/r/n<br>".print_r(EEM_System_Status::instance()->get_system_stati(), true),
378 378
 				array(
379 379
 					"from:$from_name<$from>",
380 380
 //					'content-type:text/html charset=UTF-8'
381 381
 					));
382
-		}catch( Exception $e ){
382
+		} catch (Exception $e) {
383 383
 			$success = FALSE;
384 384
 		}
385
-		$this->_redirect_after_action($success, __("Migration Crash Report", "event_espresso"), __("sent", "event_espresso"),array('success'=>$success,'action'=>'confirm_migration_crash_report_sent'));
385
+		$this->_redirect_after_action($success, __("Migration Crash Report", "event_espresso"), __("sent", "event_espresso"), array('success'=>$success, 'action'=>'confirm_migration_crash_report_sent'));
386 386
 	}
387 387
 
388 388
 
389 389
 
390
-	public function _confirm_migration_crash_report_sent(){
391
-		try{
390
+	public function _confirm_migration_crash_report_sent() {
391
+		try {
392 392
 			$most_recent_migration = EE_Data_Migration_Manager::instance()->get_last_ran_script(true);
393
-		}catch(EE_Error $e){
393
+		} catch (EE_Error $e) {
394 394
 
395 395
 			EE_Data_Migration_Manager::instance()->add_error_to_migrations_ran($e->getMessage());
396 396
 			//now, just so we can display the page correctly, make a error migration script stage object
@@ -398,14 +398,14 @@  discard block
 block discarded – undo
398 398
 			$most_recent_migration = new EE_DMS_Unknown_1_0_0();
399 399
 			$most_recent_migration->add_error($e->getMessage());
400 400
 		}
401
-		$success = $this->_req_data['success']=='1' ? true : false;
401
+		$success = $this->_req_data['success'] == '1' ? true : false;
402 402
 		$this->_template_args['success'] = $success;
403
-		$this->_template_args[ 'most_recent_migration' ] = $most_recent_migration;
403
+		$this->_template_args['most_recent_migration'] = $most_recent_migration;
404 404
 		$this->_template_args['reset_db_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'reset_db'), EE_MAINTENANCE_ADMIN_URL);
405
-		$this->_template_args[ 'reset_db_page_url' ] = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'data_reset'), EE_MAINTENANCE_ADMIN_URL);
406
-		$this->_template_args[ 'reattempt_action_url' ] = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'reattempt_migration'), EE_MAINTENANCE_ADMIN_URL );
407
-		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH . 'ee_confirm_migration_crash_report_sent.template.php';
408
-		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,$this->_template_args,TRUE);
405
+		$this->_template_args['reset_db_page_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action'=>'data_reset'), EE_MAINTENANCE_ADMIN_URL);
406
+		$this->_template_args['reattempt_action_url'] = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'reattempt_migration'), EE_MAINTENANCE_ADMIN_URL);
407
+		$this->_template_path = EE_MAINTENANCE_TEMPLATE_PATH.'ee_confirm_migration_crash_report_sent.template.php';
408
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path, $this->_template_args, TRUE);
409 409
 		$this->display_admin_page_with_sidebar();
410 410
 	}
411 411
 
@@ -418,18 +418,18 @@  discard block
 block discarded – undo
418 418
 	 * @param boolean $nuke_old_ee4_data controls whether or not we
419 419
 	 * destroy the old ee4 data, or just try initializing ee4 default data
420 420
 	 */
421
-	public function _reset_db( $nuke_old_ee4_data = TRUE ){
421
+	public function _reset_db($nuke_old_ee4_data = TRUE) {
422 422
 		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
423 423
 
424
-		if( $nuke_old_ee4_data ){
424
+		if ($nuke_old_ee4_data) {
425 425
 			EEH_Activation::delete_all_espresso_cpt_data();
426
-			EEH_Activation::delete_all_espresso_tables_and_data( FALSE );
426
+			EEH_Activation::delete_all_espresso_tables_and_data(FALSE);
427 427
 			EEH_Activation::remove_cron_tasks();
428 428
 		}
429 429
 		//make sure when we reset the registry's config that it
430 430
 		//switches to using the new singleton
431
-		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset( TRUE );
432
-		EE_System::instance()->initialize_db_if_no_migrations_required( TRUE );
431
+		EE_Registry::instance()->CFG = EE_Registry::instance()->CFG->reset(TRUE);
432
+		EE_System::instance()->initialize_db_if_no_migrations_required(TRUE);
433 433
 		EE_System::instance()->redirect_to_about_ee();
434 434
 	}
435 435
 
@@ -438,20 +438,20 @@  discard block
 block discarded – undo
438 438
 	/**
439 439
 	 * Deletes ALL EE tables, Records, and Options from the database.
440 440
 	 */
441
-	public function _delete_db(){
441
+	public function _delete_db() {
442 442
 		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
443 443
 		EEH_Activation::delete_all_espresso_cpt_data();
444 444
 		EEH_Activation::delete_all_espresso_tables_and_data();
445 445
 		EEH_Activation::remove_cron_tasks();
446 446
 		EEH_Activation::deactivate_event_espresso();
447
-		wp_safe_redirect( admin_url( 'plugins.php' ));
447
+		wp_safe_redirect(admin_url('plugins.php'));
448 448
 		exit;
449 449
 	}
450 450
 
451 451
 	/**
452 452
 	 * sets up EE4 to rerun the migrations from ee3 to ee4
453 453
 	 */
454
-	public function _rerun_migration_from_ee3(){
454
+	public function _rerun_migration_from_ee3() {
455 455
 		EE_Maintenance_Mode::instance()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance);
456 456
 		EEH_Activation::delete_all_espresso_cpt_data();
457 457
 		EEH_Activation::delete_all_espresso_tables_and_data(false);
@@ -478,9 +478,9 @@  discard block
 block discarded – undo
478 478
 		wp_enqueue_script('ee_admin_js');
479 479
 //		wp_enqueue_media();
480 480
 //		wp_enqueue_script('media-upload');
481
-		wp_enqueue_script('ee-maintenance',EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js',array('jquery'),EVENT_ESPRESSO_VERSION,true);
481
+		wp_enqueue_script('ee-maintenance', EE_MAINTENANCE_ASSETS_URL.'/ee-maintenance.js', array('jquery'), EVENT_ESPRESSO_VERSION, true);
482 482
 
483
-		wp_register_style( 'espresso_maintenance', EE_MAINTENANCE_ASSETS_URL . 'ee-maintenance.css', array(), EVENT_ESPRESSO_VERSION );
483
+		wp_register_style('espresso_maintenance', EE_MAINTENANCE_ASSETS_URL.'ee-maintenance.css', array(), EVENT_ESPRESSO_VERSION);
484 484
 		wp_enqueue_style('espresso_maintenance');
485 485
 	}
486 486
 
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 3 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 
188 188
 	/**
189 189
 	 * 	start_timer
190
-	 * @param null $timer_name
190
+	 * @param string $timer_name
191 191
 	 */
192 192
 	public function start_timer( $timer_name = NULL ){
193 193
 		$this->_start_times[$timer_name] = microtime( TRUE );
@@ -468,12 +468,13 @@  discard block
 block discarded – undo
468 468
 
469 469
 
470 470
 	/**
471
-	 * @param mixed  $var
471
+	 * @param string  $var
472 472
 	 * @param string $var_name
473 473
 	 * @param string $file
474 474
 	 * @param int    $line
475 475
 	 * @param int $heading_tag
476 476
 	 * @param bool   $die
477
+	 * @param string $margin
477 478
 	 */
478 479
 	public static function printv( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $heading_tag = 5, $die = false, $margin ) {
479 480
 		$var_name = ! $var_name ? 'string' : $var_name;
Please login to merge, or discard this patch.
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -480,9 +480,9 @@  discard block
 block discarded – undo
480 480
 		$var_name = ucwords( str_replace( '$', '', $var_name ) );
481 481
 		$is_method = method_exists( $var_name, $var );
482 482
 		$var_name = ucwords( str_replace( '_', ' ', $var_name ) );
483
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : "h5";
484
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
485
-        $result .= $is_method
483
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : "h5";
484
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
485
+		$result .= $is_method
486 486
 			? \EEH_Debug_Tools::grey_span('::') . \EEH_Debug_Tools::orange_span($var . "()")
487 487
 			: \EEH_Debug_Tools::grey_span(' : ') . \EEH_Debug_Tools::orange_span($var);
488 488
 		$result .= \EEH_Debug_Tools::file_and_line($file, $line);
@@ -496,93 +496,93 @@  discard block
 block discarded – undo
496 496
 
497 497
 
498 498
 
499
-    /**
500
-     * @param string $var_name
501
-     * @param string $heading_tag
502
-     * @param string $margin
503
-     * @return string
504
-     */
499
+	/**
500
+	 * @param string $var_name
501
+	 * @param string $heading_tag
502
+	 * @param string $margin
503
+	 * @return string
504
+	 */
505 505
 	protected static function heading( $var_name = '', $heading_tag = 'h5', $margin = '' ) {
506
-        if (defined('EE_TESTS_DIR')) {
507
-            return "\n\n{$var_name}";
508
-        }
509
-        return '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0'.$margin.';"><b>'.$var_name.'</b>';
510
-    }
506
+		if (defined('EE_TESTS_DIR')) {
507
+			return "\n\n{$var_name}";
508
+		}
509
+		return '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0'.$margin.';"><b>'.$var_name.'</b>';
510
+	}
511 511
 
512 512
 
513 513
 
514
-    /**
515
-     * @param string $heading_tag
516
-     * @return string
517
-     */
514
+	/**
515
+	 * @param string $heading_tag
516
+	 * @return string
517
+	 */
518 518
 	protected static function headingx( $heading_tag = 'h5' ) {
519
-        if (defined('EE_TESTS_DIR')) {
520
-            return "\n";
521
-        }
522
-        return '</' . $heading_tag . '>';
523
-    }
519
+		if (defined('EE_TESTS_DIR')) {
520
+			return "\n";
521
+		}
522
+		return '</' . $heading_tag . '>';
523
+	}
524 524
 
525 525
 
526 526
 
527
-    /**
528
-     * @param string $content
529
-     * @return string
530
-     */
527
+	/**
528
+	 * @param string $content
529
+	 * @return string
530
+	 */
531 531
 	protected static function grey_span( $content = '' ) {
532
-        if (defined('EE_TESTS_DIR')) {
533
-            return $content;
534
-        }
535
-        return '<span style="color:#999">' . $content . '</span>';
536
-    }
532
+		if (defined('EE_TESTS_DIR')) {
533
+			return $content;
534
+		}
535
+		return '<span style="color:#999">' . $content . '</span>';
536
+	}
537 537
 
538 538
 
539 539
 
540
-    /**
541
-     * @param string $file
542
-     * @param int    $line
543
-     * @return string
544
-     */
540
+	/**
541
+	 * @param string $file
542
+	 * @param int    $line
543
+	 * @return string
544
+	 */
545 545
 	protected static function file_and_line($file, $line) {
546
-        if (defined('EE_TESTS_DIR')) {
547
-            return "\n (" . $file . ' line no: ' . $line . ' ) ';
548
-        }
549
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file . '<br />line no: ' . $line . '</span>';
550
-    }
551
-
552
-
553
-
554
-    /**
555
-     * @param string $content
556
-     * @return string
557
-     */
558
-    protected static function orange_span($content = '')
559
-    {
560
-        if (defined('EE_TESTS_DIR')) {
561
-            return $content;
562
-        }
563
-        return '<span style="color:#E76700">' . $content . '</span>';
564
-    }
565
-
566
-
567
-
568
-    /**
569
-     * @param mixed $var
570
-     * @return string
571
-     */
572
-    protected static function pre_span($var)
573
-    {
574
-        ob_start();
575
-        var_dump($var);
576
-        $var = ob_get_clean();
577
-        if (defined('EE_TESTS_DIR')) {
578
-            return "\n" . $var;
579
-        }
580
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
581
-    }
582
-
583
-
584
-
585
-    /**
546
+		if (defined('EE_TESTS_DIR')) {
547
+			return "\n (" . $file . ' line no: ' . $line . ' ) ';
548
+		}
549
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file . '<br />line no: ' . $line . '</span>';
550
+	}
551
+
552
+
553
+
554
+	/**
555
+	 * @param string $content
556
+	 * @return string
557
+	 */
558
+	protected static function orange_span($content = '')
559
+	{
560
+		if (defined('EE_TESTS_DIR')) {
561
+			return $content;
562
+		}
563
+		return '<span style="color:#E76700">' . $content . '</span>';
564
+	}
565
+
566
+
567
+
568
+	/**
569
+	 * @param mixed $var
570
+	 * @return string
571
+	 */
572
+	protected static function pre_span($var)
573
+	{
574
+		ob_start();
575
+		var_dump($var);
576
+		$var = ob_get_clean();
577
+		if (defined('EE_TESTS_DIR')) {
578
+			return "\n" . $var;
579
+		}
580
+		return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
581
+	}
582
+
583
+
584
+
585
+	/**
586 586
 	 * @param mixed $var
587 587
 	 * @param string $var_name
588 588
 	 * @param string $file
@@ -593,8 +593,8 @@  discard block
 block discarded – undo
593 593
 	public static function printr( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $heading_tag = 5, $die = false ) {
594 594
 		// return;
595 595
 		$file = str_replace( rtrim( ABSPATH, '\\/' ), '', $file );
596
-        $margin = is_admin() ? ' 180px' : '0';
597
-        //$print_r = false;
596
+		$margin = is_admin() ? ' 180px' : '0';
597
+		//$print_r = false;
598 598
 		if ( is_string( $var ) ) {
599 599
 			EEH_Debug_Tools::printv( $var, $var_name, $file, $line, $heading_tag, $die, $margin );
600 600
 			return;
@@ -610,11 +610,11 @@  discard block
 block discarded – undo
610 610
 			$var_name = ! $var_name ? 'null' : $var_name;
611 611
 		}
612 612
 		$var_name = ucwords( str_replace( array( '$', '_' ), array( '', ' ' ), $var_name ) );
613
-        $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : "h5";
614
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
613
+		$heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : "h5";
614
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
615 615
 		$result .= \EEH_Debug_Tools::grey_span(' : ') . \EEH_Debug_Tools::orange_span(
616
-		    \EEH_Debug_Tools::pre_span($var)
617
-            );
616
+			\EEH_Debug_Tools::pre_span($var)
617
+			);
618 618
 		$result .= \EEH_Debug_Tools::file_and_line($file, $line);
619 619
 		$result .= \EEH_Debug_Tools::headingx($heading_tag);
620 620
 		if ( $die ) {
Please login to merge, or discard this patch.
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
2 2
 /**
3 3
  * Class EEH_Debug_Tools
4 4
  *
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since 				4.0
9 9
  *
10 10
  */
11
-class EEH_Debug_Tools{
11
+class EEH_Debug_Tools {
12 12
 
13 13
 	/**
14 14
 	 * 	instance of the EEH_Autoloader object
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 */
42 42
 	public static function instance() {
43 43
 		// check if class object is instantiated, and instantiated properly
44
-		if ( ! self::$_instance instanceof EEH_Debug_Tools ) {
44
+		if ( ! self::$_instance instanceof EEH_Debug_Tools) {
45 45
 			self::$_instance = new self();
46 46
 		}
47 47
 		return self::$_instance;
@@ -57,21 +57,21 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	private function __construct() {
59 59
 		// load Kint PHP debugging library
60
-		if ( ! class_exists( 'Kint' ) &&  file_exists( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' )){
60
+		if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) {
61 61
 			// despite EE4 having a check for an existing copy of the Kint debugging class,
62 62
 			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
63 63
 			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
64 64
 			// so we've moved it to our test folder so that it is not included with production releases
65 65
 			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
66
-			require_once( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' );
66
+			require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php');
67 67
 		}
68 68
 		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
69 69
 			//add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
70 70
 		// }
71
-		$plugin = basename( EE_PLUGIN_DIR_PATH );
72
-		add_action( "activate_{$plugin}", array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' ));
73
-		add_action( 'activated_plugin', array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' ));
74
-		add_action( 'shutdown', array( 'EEH_Debug_Tools', 'show_db_name' ));
71
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
72
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
73
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
74
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
75 75
 	}
76 76
 
77 77
 
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
 	 * 	@return void
83 83
 	 */
84 84
 	public static function show_db_name() {
85
-		if ( ! defined( 'DOING_AJAX' ) && ( defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS )) {
86
-			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '. DB_NAME .'</p>';
85
+		if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
86
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '.DB_NAME.'</p>';
87 87
 		}
88
-		if ( EE_DEBUG ) {
88
+		if (EE_DEBUG) {
89 89
 			EEH_Debug_Tools::instance()->show_times();
90 90
 		}
91 91
 	}
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function espresso_session_footer_dump() {
101 101
 		if (
102
-			( defined( 'WP_DEBUG' ) && WP_DEBUG )
103
-			&& ! defined( 'DOING_AJAX' )
104
-			&& class_exists( 'Kint' )
105
-			&& function_exists( 'wp_get_current_user' )
106
-			&& current_user_can( 'update_core' )
107
-			&& class_exists( 'EE_Registry' )
102
+			(defined('WP_DEBUG') && WP_DEBUG)
103
+			&& ! defined('DOING_AJAX')
104
+			&& class_exists('Kint')
105
+			&& function_exists('wp_get_current_user')
106
+			&& current_user_can('update_core')
107
+			&& class_exists('EE_Registry')
108 108
 		) {
109
-			Kint::dump(  EE_Registry::instance()->SSN->id() );
110
-			Kint::dump( EE_Registry::instance()->SSN );
109
+			Kint::dump(EE_Registry::instance()->SSN->id());
110
+			Kint::dump(EE_Registry::instance()->SSN);
111 111
 			//			Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
112 112
 			$this->espresso_list_hooked_functions();
113 113
 			$this->show_times();
@@ -124,27 +124,27 @@  discard block
 block discarded – undo
124 124
 	 * @param string $tag
125 125
 	 * @return void
126 126
 	 */
127
-	public function espresso_list_hooked_functions( $tag='' ){
127
+	public function espresso_list_hooked_functions($tag = '') {
128 128
 		global $wp_filter;
129 129
 		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
130
-		if ( $tag ) {
131
-			$hook[$tag]=$wp_filter[$tag];
132
-			if ( ! is_array( $hook[$tag] )) {
133
-				trigger_error( "Nothing found for '$tag' hook", E_USER_WARNING );
130
+		if ($tag) {
131
+			$hook[$tag] = $wp_filter[$tag];
132
+			if ( ! is_array($hook[$tag])) {
133
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
134 134
 				return;
135 135
 			}
136
-			echo '<h5>For Tag: '. $tag .'</h5>';
136
+			echo '<h5>For Tag: '.$tag.'</h5>';
137 137
 		}
138 138
 		else {
139
-			$hook=$wp_filter;
140
-			ksort( $hook );
139
+			$hook = $wp_filter;
140
+			ksort($hook);
141 141
 		}
142
-		foreach( $hook as $tag_name => $priorities ) {
142
+		foreach ($hook as $tag_name => $priorities) {
143 143
 			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
144
-			ksort( $priorities );
145
-			foreach( $priorities as $priority => $function ){
144
+			ksort($priorities);
145
+			foreach ($priorities as $priority => $function) {
146 146
 				echo $priority;
147
-				foreach( $function as $name => $properties ) {
147
+				foreach ($function as $name => $properties) {
148 148
 					echo "\t$name<br />";
149 149
 				}
150 150
 			}
@@ -159,15 +159,15 @@  discard block
 block discarded – undo
159 159
 	 * @param string $hook_name
160 160
 	 * @return array
161 161
 	 */
162
-	public static function registered_filter_callbacks( $hook_name = '' ) {
162
+	public static function registered_filter_callbacks($hook_name = '') {
163 163
 		$filters = array();
164 164
 		global $wp_filter;
165
-		if ( isset( $wp_filter[ $hook_name ] ) ) {
166
-			$filters[ $hook_name ] = array();
167
-			foreach ( $wp_filter[ $hook_name ] as $priority => $callbacks ) {
168
-				$filters[ $hook_name ][ $priority ] = array();
169
-				foreach ( $callbacks as $callback ) {
170
-					$filters[ $hook_name ][ $priority ][] = $callback['function'];
165
+		if (isset($wp_filter[$hook_name])) {
166
+			$filters[$hook_name] = array();
167
+			foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
168
+				$filters[$hook_name][$priority] = array();
169
+				foreach ($callbacks as $callback) {
170
+					$filters[$hook_name][$priority][] = $callback['function'];
171 171
 				}
172 172
 			}
173 173
 		}
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	/**
180 180
 	 * reset_times
181 181
 	 */
182
-	public function reset_times(){
182
+	public function reset_times() {
183 183
 		$this->_times = array();
184 184
 	}
185 185
 
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 	 * 	start_timer
190 190
 	 * @param null $timer_name
191 191
 	 */
192
-	public function start_timer( $timer_name = NULL ){
193
-		$this->_start_times[$timer_name] = microtime( TRUE );
192
+	public function start_timer($timer_name = NULL) {
193
+		$this->_start_times[$timer_name] = microtime(TRUE);
194 194
 	}
195 195
 
196 196
 
@@ -199,15 +199,15 @@  discard block
 block discarded – undo
199 199
 	 * stop_timer
200 200
 	 * @param string $timer_name
201 201
 	 */
202
-	public function stop_timer( $timer_name = '' ){
202
+	public function stop_timer($timer_name = '') {
203 203
 		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
204
-		if( isset( $this->_start_times[ $timer_name ] ) ){
205
-			$start_time = $this->_start_times[ $timer_name ];
206
-			unset( $this->_start_times[ $timer_name ] );
207
-		}else{
208
-			$start_time = array_pop( $this->_start_times );
204
+		if (isset($this->_start_times[$timer_name])) {
205
+			$start_time = $this->_start_times[$timer_name];
206
+			unset($this->_start_times[$timer_name]);
207
+		} else {
208
+			$start_time = array_pop($this->_start_times);
209 209
 		}
210
-		$this->_times[ $timer_name ] =  number_format( microtime( true ) - $start_time, 8 );
210
+		$this->_times[$timer_name] = number_format(microtime(true) - $start_time, 8);
211 211
 	}
212 212
 
213 213
 
@@ -217,10 +217,10 @@  discard block
 block discarded – undo
217 217
 	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
218 218
 	 * @return void
219 219
 	 */
220
-	public function measure_memory( $label, $output_now = false ) {
221
-		$memory_used = $this->convert( memory_get_peak_usage( true ) );
222
-		$this->_memory_usage_points[ $label ] = $memory_used;
223
-		if( $output_now ) {
220
+	public function measure_memory($label, $output_now = false) {
221
+		$memory_used = $this->convert(memory_get_peak_usage(true));
222
+		$this->_memory_usage_points[$label] = $memory_used;
223
+		if ($output_now) {
224 224
 			echo "\r\n<br>$label : $memory_used";
225 225
 		}
226 226
 	}
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 	 * @param int $size
231 231
 	 * @return string
232 232
 	 */
233
-	public function convert( $size ) {
234
-		$unit=array('b','kb','mb','gb','tb','pb');
235
-		return @round( $size / pow( 1024, $i = floor( log( $size, 1024 ) ) ), 2 ) . ' ' . $unit[ absint( $i ) ];
233
+	public function convert($size) {
234
+		$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
235
+		return @round($size / pow(1024, $i = floor(log($size, 1024))), 2).' '.$unit[absint($i)];
236 236
 	}
237 237
 
238 238
 
@@ -242,25 +242,25 @@  discard block
 block discarded – undo
242 242
 	 * @param bool $output_now
243 243
 	 * @return string
244 244
 	 */
245
-	public function show_times($output_now=true){
245
+	public function show_times($output_now = true) {
246 246
 		$output = '';
247
-		if ( ! empty( $this->_times )) {
247
+		if ( ! empty($this->_times)) {
248 248
 			$total = 0;
249 249
 			$output .= '<h2 style="margin:1em .5em 0;">Times:</h2>';
250 250
 			$output .= '<span style="color:#9999CC; font-size:.8em; margin:0 1.5em 0;">( in milliseconds )</span><br />';
251
-			foreach( $this->_times as $timer_name => $total_time ) {
252
-				$output .= $this->format_time( $timer_name, $total_time );
251
+			foreach ($this->_times as $timer_name => $total_time) {
252
+				$output .= $this->format_time($timer_name, $total_time);
253 253
 				$total += $total_time;
254 254
 			}
255 255
 			$output .= '<br />';
256 256
 			$output .= '<h4 style="margin:1em .5em 0;">TOTAL TIME</h4>';
257
-			$output .= $this->format_time( '', $total );
257
+			$output .= $this->format_time('', $total);
258 258
 			$output .= '<br />';
259 259
 		}
260
-		if ( ! empty( $this->_memory_usage_points )) {
261
-			$output .= '<h2 style="margin:1em .5em 0;">Memory</h2>' . implode( '<br />', $this->_memory_usage_points );
260
+		if ( ! empty($this->_memory_usage_points)) {
261
+			$output .= '<h2 style="margin:1em .5em 0;">Memory</h2>'.implode('<br />', $this->_memory_usage_points);
262 262
 		}
263
-		if( $output_now ){
263
+		if ($output_now) {
264 264
 			echo $output;
265 265
 			return '';
266 266
 		}
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
 	 * @param float $total_time
275 275
 	 * @return string
276 276
 	 */
277
-	public function format_time( $timer_name, $total_time ) {
277
+	public function format_time($timer_name, $total_time) {
278 278
 		$total_time = $total_time * 1000;
279
-		switch ( $total_time ) {
279
+		switch ($total_time) {
280 280
 			case $total_time < 0.01 :
281 281
 				$color = '#8A549A';
282 282
 				$bold = 'normal';
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 			. '; font-weight:'
308 308
 			. $bold
309 309
 			. '; font-size:1.2em;">'
310
-			. str_pad( number_format( $total_time, 5 ), 11, '0', STR_PAD_LEFT )
310
+			. str_pad(number_format($total_time, 5), 11, '0', STR_PAD_LEFT)
311 311
 			. '</span> '
312 312
 			. $timer_name
313 313
 			. '<br />';
@@ -321,25 +321,25 @@  discard block
 block discarded – undo
321 321
 	 * 	@return void
322 322
 	 */
323 323
 	public static function ee_plugin_activation_errors() {
324
-		if ( WP_DEBUG ) {
324
+		if (WP_DEBUG) {
325 325
 			$activation_errors = ob_get_contents();
326
-			if ( ! empty( $activation_errors ) ) {
327
-				$activation_errors = date( 'Y-m-d H:i:s' ) . "\n" . $activation_errors;
326
+			if ( ! empty($activation_errors)) {
327
+				$activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
328 328
 			}
329
-			espresso_load_required( 'EEH_File', EE_HELPERS . 'EEH_File.helper.php' );
330
-			if ( class_exists( 'EEH_File' )) {
329
+			espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
330
+			if (class_exists('EEH_File')) {
331 331
 				try {
332
-					EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' );
333
-					EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors );
334
-				} catch( EE_Error $e ){
335
-					EE_Error::add_error( sprintf( __(  'The Event Espresso activation errors file could not be setup because: %s', 'event_espresso' ), $e->getMessage() ), __FILE__, __FUNCTION__, __LINE__ );
332
+					EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html');
333
+					EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors);
334
+				} catch (EE_Error $e) {
335
+					EE_Error::add_error(sprintf(__('The Event Espresso activation errors file could not be setup because: %s', 'event_espresso'), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__);
336 336
 				}
337 337
 			} else {
338 338
 				// old school attempt
339
-				file_put_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors );
339
+				file_put_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors);
340 340
 			}
341
-			$activation_errors = get_option( 'ee_plugin_activation_errors', '' ) . $activation_errors;
342
-			update_option( 'ee_plugin_activation_errors', $activation_errors );
341
+			$activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
342
+			update_option('ee_plugin_activation_errors', $activation_errors);
343 343
 		}
344 344
 	}
345 345
 
@@ -368,33 +368,33 @@  discard block
 block discarded – undo
368 368
 		$applies_when = '',
369 369
 		$error_type = null
370 370
 	) {
371
-		$applies_when = ! empty( $applies_when ) ? $applies_when : espresso_version();
371
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
372 372
 		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
373 373
 		// because we swapped the parameter order around for the last two params,
374 374
 		// let's verify that some third party isn't still passing an error type value for the third param
375
-		if ( is_int( $applies_when ) ) {
375
+		if (is_int($applies_when)) {
376 376
 			$error_type = $applies_when;
377 377
 			$applies_when = espresso_version();
378 378
 		}
379 379
 		// if not displaying notices yet, then just leave
380
-		if ( version_compare( espresso_version(), $applies_when, '<' ) ) {
380
+		if (version_compare(espresso_version(), $applies_when, '<')) {
381 381
 			return;
382 382
 		}
383
-		do_action( 'AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
384
-		$version = $version === null ? '' : sprintf( __('(This message was added in version %s of Event Espresso)', 'event_espresso' ), $version );
385
-		$error_message = sprintf( esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s','event_espresso' ), $function, '<strong>', '</strong>', $message, $version );
383
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
384
+		$version = $version === null ? '' : sprintf(__('(This message was added in version %s of Event Espresso)', 'event_espresso'), $version);
385
+		$error_message = sprintf(esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), $function, '<strong>', '</strong>', $message, $version);
386 386
 
387 387
 		//don't trigger error if doing ajax, instead we'll add a transient EE_Error notice that in theory should show on the next request.
388
-		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
389
-			$error_message .= ' ' . esc_html__( 'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ', 'event_espresso' );
388
+		if (defined('DOING_AJAX') && DOING_AJAX) {
389
+			$error_message .= ' '.esc_html__('This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ', 'event_espresso');
390 390
 			$error_message .= '<ul><li>';
391
-			$error_message .= implode( '</li><li>', EE_Registry::instance()->REQ->params() );
391
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
392 392
 			$error_message .= '</ul>';
393
-			EE_Error::add_error( $error_message, 'debug::doing_it_wrong', $function, '42' );
393
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
394 394
 			//now we set this on the transient so it shows up on the next request.
395
-			EE_Error::get_notices( false, true );
395
+			EE_Error::get_notices(false, true);
396 396
 		} else {
397
-			trigger_error( $error_message, $error_type );
397
+			trigger_error($error_message, $error_type);
398 398
 		}
399 399
 	}
400 400
 
@@ -416,22 +416,22 @@  discard block
 block discarded – undo
416 416
 	 * @param string $debug_index
417 417
 	 * @param string $debug_key
418 418
 	 */
419
-	public static function log( $class='', $func = '', $line = '', $info = array(), $display_request = false,  $debug_index = '', $debug_key = 'EE_DEBUG_SPCO' ) {
420
-		if ( WP_DEBUG && false ) {
421
-			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
422
-			$debug_data = get_option( $debug_key, array() );
419
+	public static function log($class = '', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO') {
420
+		if (WP_DEBUG && false) {
421
+			$debug_key = $debug_key.'_'.EE_Session::instance()->id();
422
+			$debug_data = get_option($debug_key, array());
423 423
 			$default_data = array(
424
-				$class => $func . '() : ' . $line,
424
+				$class => $func.'() : '.$line,
425 425
 				'REQ'  => $display_request ? $_REQUEST : '',
426 426
 			);
427 427
 			// don't serialize objects
428
-			$info = self::strip_objects( $info );
429
-			$index = ! empty( $debug_index ) ? $debug_index : 0;
430
-			if ( ! isset( $debug_data[$index] ) ) {
428
+			$info = self::strip_objects($info);
429
+			$index = ! empty($debug_index) ? $debug_index : 0;
430
+			if ( ! isset($debug_data[$index])) {
431 431
 				$debug_data[$index] = array();
432 432
 			}
433
-			$debug_data[$index][microtime()] = array_merge( $default_data, $info );
434
-			update_option( $debug_key, $debug_data );
433
+			$debug_data[$index][microtime()] = array_merge($default_data, $info);
434
+			update_option($debug_key, $debug_data);
435 435
 		}
436 436
 	}
437 437
 
@@ -443,26 +443,26 @@  discard block
 block discarded – undo
443 443
 	 * @param array $info
444 444
 	 * @return array
445 445
 	 */
446
-	public static function strip_objects( $info = array() ) {
447
-		foreach ( $info as $key => $value ) {
448
-			if ( is_array( $value ) ) {
449
-				$info[ $key ] = self::strip_objects( $value );
450
-			} else if ( is_object( $value ) ) {
451
-				$object_class = get_class( $value );
452
-				$info[ $object_class ] = array();
453
-				$info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : spl_object_hash( $value );
454
-				if ( method_exists( $value, 'ID' ) ) {
455
-					$info[ $object_class ][ 'ID' ] = $value->ID();
446
+	public static function strip_objects($info = array()) {
447
+		foreach ($info as $key => $value) {
448
+			if (is_array($value)) {
449
+				$info[$key] = self::strip_objects($value);
450
+			} else if (is_object($value)) {
451
+				$object_class = get_class($value);
452
+				$info[$object_class] = array();
453
+				$info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
454
+				if (method_exists($value, 'ID')) {
455
+					$info[$object_class]['ID'] = $value->ID();
456 456
 				}
457
-				if ( method_exists( $value, 'status' ) ) {
458
-					$info[ $object_class ][ 'status' ] = $value->status();
459
-				} else if ( method_exists( $value, 'status_ID' ) ) {
460
-					$info[ $object_class ][ 'status' ] = $value->status_ID();
457
+				if (method_exists($value, 'status')) {
458
+					$info[$object_class]['status'] = $value->status();
459
+				} else if (method_exists($value, 'status_ID')) {
460
+					$info[$object_class]['status'] = $value->status_ID();
461 461
 				}
462
-				unset( $info[ $key ] );
462
+				unset($info[$key]);
463 463
 			}
464 464
 		}
465
-		return (array)$info;
465
+		return (array) $info;
466 466
 	}
467 467
 
468 468
 
@@ -475,20 +475,20 @@  discard block
 block discarded – undo
475 475
 	 * @param int $heading_tag
476 476
 	 * @param bool   $die
477 477
 	 */
478
-	public static function printv( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $heading_tag = 5, $die = false, $margin ) {
478
+	public static function printv($var, $var_name = '', $file = __FILE__, $line = __LINE__, $heading_tag = 5, $die = false, $margin) {
479 479
 		$var_name = ! $var_name ? 'string' : $var_name;
480
-		$var_name = ucwords( str_replace( '$', '', $var_name ) );
481
-		$is_method = method_exists( $var_name, $var );
482
-		$var_name = ucwords( str_replace( '_', ' ', $var_name ) );
480
+		$var_name = ucwords(str_replace('$', '', $var_name));
481
+		$is_method = method_exists($var_name, $var);
482
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
483 483
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : "h5";
484 484
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
485 485
         $result .= $is_method
486
-			? \EEH_Debug_Tools::grey_span('::') . \EEH_Debug_Tools::orange_span($var . "()")
487
-			: \EEH_Debug_Tools::grey_span(' : ') . \EEH_Debug_Tools::orange_span($var);
486
+			? \EEH_Debug_Tools::grey_span('::').\EEH_Debug_Tools::orange_span($var."()")
487
+			: \EEH_Debug_Tools::grey_span(' : ').\EEH_Debug_Tools::orange_span($var);
488 488
 		$result .= \EEH_Debug_Tools::file_and_line($file, $line);
489 489
 		$result .= \EEH_Debug_Tools::headingx($heading_tag);
490
-		if ( $die ) {
491
-			die( $result );
490
+		if ($die) {
491
+			die($result);
492 492
 		} else {
493 493
 			echo $result;
494 494
 		}
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
      * @param string $margin
503 503
      * @return string
504 504
      */
505
-	protected static function heading( $var_name = '', $heading_tag = 'h5', $margin = '' ) {
505
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') {
506 506
         if (defined('EE_TESTS_DIR')) {
507 507
             return "\n\n{$var_name}";
508 508
         }
@@ -515,11 +515,11 @@  discard block
 block discarded – undo
515 515
      * @param string $heading_tag
516 516
      * @return string
517 517
      */
518
-	protected static function headingx( $heading_tag = 'h5' ) {
518
+	protected static function headingx($heading_tag = 'h5') {
519 519
         if (defined('EE_TESTS_DIR')) {
520 520
             return "\n";
521 521
         }
522
-        return '</' . $heading_tag . '>';
522
+        return '</'.$heading_tag.'>';
523 523
     }
524 524
 
525 525
 
@@ -528,11 +528,11 @@  discard block
 block discarded – undo
528 528
      * @param string $content
529 529
      * @return string
530 530
      */
531
-	protected static function grey_span( $content = '' ) {
531
+	protected static function grey_span($content = '') {
532 532
         if (defined('EE_TESTS_DIR')) {
533 533
             return $content;
534 534
         }
535
-        return '<span style="color:#999">' . $content . '</span>';
535
+        return '<span style="color:#999">'.$content.'</span>';
536 536
     }
537 537
 
538 538
 
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
      */
545 545
 	protected static function file_and_line($file, $line) {
546 546
         if (defined('EE_TESTS_DIR')) {
547
-            return "\n (" . $file . ' line no: ' . $line . ' ) ';
547
+            return "\n (".$file.' line no: '.$line.' ) ';
548 548
         }
549
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file . '<br />line no: ' . $line . '</span>';
549
+        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'.$file.'<br />line no: '.$line.'</span>';
550 550
     }
551 551
 
552 552
 
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
         if (defined('EE_TESTS_DIR')) {
561 561
             return $content;
562 562
         }
563
-        return '<span style="color:#E76700">' . $content . '</span>';
563
+        return '<span style="color:#E76700">'.$content.'</span>';
564 564
     }
565 565
 
566 566
 
@@ -575,9 +575,9 @@  discard block
 block discarded – undo
575 575
         var_dump($var);
576 576
         $var = ob_get_clean();
577 577
         if (defined('EE_TESTS_DIR')) {
578
-            return "\n" . $var;
578
+            return "\n".$var;
579 579
         }
580
-        return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>';
580
+        return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>';
581 581
     }
582 582
 
583 583
 
@@ -590,35 +590,35 @@  discard block
 block discarded – undo
590 590
 	 * @param int $heading_tag
591 591
 	 * @param bool $die
592 592
 	 */
593
-	public static function printr( $var, $var_name = '', $file = __FILE__, $line = __LINE__, $heading_tag = 5, $die = false ) {
593
+	public static function printr($var, $var_name = '', $file = __FILE__, $line = __LINE__, $heading_tag = 5, $die = false) {
594 594
 		// return;
595
-		$file = str_replace( rtrim( ABSPATH, '\\/' ), '', $file );
595
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
596 596
         $margin = is_admin() ? ' 180px' : '0';
597 597
         //$print_r = false;
598
-		if ( is_string( $var ) ) {
599
-			EEH_Debug_Tools::printv( $var, $var_name, $file, $line, $heading_tag, $die, $margin );
598
+		if (is_string($var)) {
599
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
600 600
 			return;
601
-		} else if ( is_object( $var ) ) {
601
+		} else if (is_object($var)) {
602 602
 			$var_name = ! $var_name ? 'object' : $var_name;
603 603
 			//$print_r = true;
604
-		} else if ( is_array( $var ) ) {
604
+		} else if (is_array($var)) {
605 605
 			$var_name = ! $var_name ? 'array' : $var_name;
606 606
 			//$print_r = true;
607
-		} else if ( is_numeric( $var ) ) {
607
+		} else if (is_numeric($var)) {
608 608
 			$var_name = ! $var_name ? 'numeric' : $var_name;
609
-		} else if ( is_null( $var ) ) {
609
+		} else if (is_null($var)) {
610 610
 			$var_name = ! $var_name ? 'null' : $var_name;
611 611
 		}
612
-		$var_name = ucwords( str_replace( array( '$', '_' ), array( '', ' ' ), $var_name ) );
612
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
613 613
         $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : "h5";
614 614
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin);
615
-		$result .= \EEH_Debug_Tools::grey_span(' : ') . \EEH_Debug_Tools::orange_span(
615
+		$result .= \EEH_Debug_Tools::grey_span(' : ').\EEH_Debug_Tools::orange_span(
616 616
 		    \EEH_Debug_Tools::pre_span($var)
617 617
             );
618 618
 		$result .= \EEH_Debug_Tools::file_and_line($file, $line);
619 619
 		$result .= \EEH_Debug_Tools::headingx($heading_tag);
620
-		if ( $die ) {
621
-			die( $result );
620
+		if ($die) {
621
+			die($result);
622 622
 		} else {
623 623
 			echo $result;
624 624
 		}
@@ -635,8 +635,8 @@  discard block
 block discarded – undo
635 635
  * borrowed from Kint Debugger
636 636
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
637 637
  */
638
-if ( class_exists('Kint') && ! function_exists( 'dump_wp_query' ) ) {
639
-	function dump_wp_query(){
638
+if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
639
+	function dump_wp_query() {
640 640
 		global $wp_query;
641 641
 		d($wp_query);
642 642
 	}
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
  * borrowed from Kint Debugger
647 647
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
648 648
  */
649
-if ( class_exists('Kint') && ! function_exists( 'dump_wp' ) ) {
650
-	function dump_wp(){
649
+if (class_exists('Kint') && ! function_exists('dump_wp')) {
650
+	function dump_wp() {
651 651
 		global $wp;
652 652
 		d($wp);
653 653
 	}
@@ -657,8 +657,8 @@  discard block
 block discarded – undo
657 657
  * borrowed from Kint Debugger
658 658
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
659 659
  */
660
-if ( class_exists('Kint') && ! function_exists( 'dump_post' ) ) {
661
-	function dump_post(){
660
+if (class_exists('Kint') && ! function_exists('dump_post')) {
661
+	function dump_post() {
662 662
 		global $post;
663 663
 		d($post);
664 664
 	}
Please login to merge, or discard this patch.
core/services/container/OpenCoffeeShop.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * OpenCoffeeShop constructor.
34 34
 	 */
35 35
 	public function __construct()
36
-    {
36
+	{
37 37
 		// instantiate the container
38 38
 		$this->CoffeeShop = new CoffeeShop();
39 39
 		// create a dependency injector class for resolving class constructor arguments
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 			new Recipe(
84 84
 				'CommandHandlerManager',
85 85
 				'EventEspresso\core\services\commands\CommandHandlerManager',
86
-                array(
87
-                    'CommandHandlerManagerInterface',
88
-                    'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
89
-                ),
90
-                array(),
86
+				array(
87
+					'CommandHandlerManagerInterface',
88
+					'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
89
+				),
90
+				array(),
91 91
 				CoffeeMaker::BREW_SHARED
92 92
 			)
93 93
 		);
@@ -96,11 +96,11 @@  discard block
 block discarded – undo
96 96
 			new Recipe(
97 97
 				'CommandBus',
98 98
 				'EventEspresso\core\services\commands\CommandBus',
99
-                array(
100
-                    'CommandBusInterface',
101
-                    'EventEspresso\core\services\commands\CommandBusInterface',
102
-                ),
103
-                array(),
99
+				array(
100
+					'CommandBusInterface',
101
+					'EventEspresso\core\services\commands\CommandBusInterface',
102
+				),
103
+				array(),
104 104
 				CoffeeMaker::BREW_SHARED
105 105
 			)
106 106
 		);
@@ -110,22 +110,22 @@  discard block
 block discarded – undo
110 110
 			new Recipe(
111 111
 				'EEI_*',
112 112
 				'',
113
-                array(),
114
-                array(),
113
+				array(),
114
+				array(),
115 115
 				CoffeeMaker::BREW_LOAD_ONLY,
116
-                array(
117
-                    EE_INTERFACES . '*.php',
118
-                    EE_INTERFACES . '*.interfaces.php',
119
-                )
116
+				array(
117
+					EE_INTERFACES . '*.php',
118
+					EE_INTERFACES . '*.interfaces.php',
119
+				)
120 120
 			)
121 121
 		);
122 122
 		// add a wildcard recipe for loading models
123 123
 		$this->CoffeeShop->addRecipe(
124 124
 			new Recipe(
125 125
 				'EEM_*',
126
-                '',
127
-                array(),
128
-                array(),
126
+				'',
127
+				array(),
128
+				array(),
129 129
 				CoffeeMaker::BREW_SHARED,
130 130
 				EE_MODELS . '*.model.php'
131 131
 			)
@@ -134,10 +134,10 @@  discard block
 block discarded – undo
134 134
 		$this->CoffeeShop->addRecipe(
135 135
 			new Recipe(
136 136
 				'EE_*',
137
-                '',
138
-                array(),
139
-                array(),
140
-                CoffeeMaker::BREW_SHARED,
137
+				'',
138
+				array(),
139
+				array(),
140
+				CoffeeMaker::BREW_SHARED,
141 141
 				array(
142 142
 					EE_CORE . '*.core.php',
143 143
 					EE_ADMIN . '*.core.php',
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 		$this->CoffeeShop->addRecipe(
153 153
 			new Recipe(
154 154
 				'EE_Admin_Page*',
155
-                '',
156
-                array(),
157
-                array(),
158
-                CoffeeMaker::BREW_LOAD_ONLY,
155
+				'',
156
+				array(),
157
+				array(),
158
+				CoffeeMaker::BREW_LOAD_ONLY,
159 159
 				array( EE_ADMIN . '*.core.php' )
160 160
 			)
161 161
 		);
@@ -163,10 +163,10 @@  discard block
 block discarded – undo
163 163
 		// $this->CoffeeShop->addRecipe(
164 164
 		// 	new Recipe(
165 165
 		// 		'*_Admin_Page',
166
-        //      '',
167
-        //      array(),
168
-        // 		array(),
169
-        // 		CoffeeMaker::BREW_SHARED,
166
+		//      '',
167
+		//      array(),
168
+		// 		array(),
169
+		// 		CoffeeMaker::BREW_SHARED,
170 170
 		// 		array(
171 171
 		// 			EE_ADMIN_PAGES . 'transactions' . DS . '*.core.php',
172 172
 		// 		)
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\services\container;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -43,17 +43,17 @@  discard block
 block discarded – undo
43 43
 		);
44 44
 		// and some coffeemakers, one for creating new instances
45 45
 		$this->CoffeeShop->addCoffeeMaker(
46
-			new NewCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
46
+			new NewCoffeeMaker($this->CoffeeShop, $this->DependencyInjector),
47 47
 			CoffeeMaker::BREW_NEW
48 48
 		);
49 49
 		// one for shared services
50 50
 		$this->CoffeeShop->addCoffeeMaker(
51
-			new SharedCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
51
+			new SharedCoffeeMaker($this->CoffeeShop, $this->DependencyInjector),
52 52
 			CoffeeMaker::BREW_SHARED
53 53
 		);
54 54
 		// and one for classes that only get loaded
55 55
 		$this->CoffeeShop->addCoffeeMaker(
56
-			new LoadOnlyCoffeeMaker( $this->CoffeeShop, $this->DependencyInjector ),
56
+			new LoadOnlyCoffeeMaker($this->CoffeeShop, $this->DependencyInjector),
57 57
 			CoffeeMaker::BREW_LOAD_ONLY
58 58
 		);
59 59
 		// add default recipe, which should handle loading for most PSR-4 compatible classes
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
                 array(),
115 115
 				CoffeeMaker::BREW_LOAD_ONLY,
116 116
                 array(
117
-                    EE_INTERFACES . '*.php',
118
-                    EE_INTERFACES . '*.interfaces.php',
117
+                    EE_INTERFACES.'*.php',
118
+                    EE_INTERFACES.'*.interfaces.php',
119 119
                 )
120 120
 			)
121 121
 		);
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                 array(),
128 128
                 array(),
129 129
 				CoffeeMaker::BREW_SHARED,
130
-				EE_MODELS . '*.model.php'
130
+				EE_MODELS.'*.model.php'
131 131
 			)
132 132
 		);
133 133
 		// add a wildcard recipe for loading core classes
@@ -139,12 +139,12 @@  discard block
 block discarded – undo
139 139
                 array(),
140 140
                 CoffeeMaker::BREW_SHARED,
141 141
 				array(
142
-					EE_CORE . '*.core.php',
143
-					EE_ADMIN . '*.core.php',
144
-					EE_CPTS . '*.core.php',
145
-					EE_CORE . 'data_migration_scripts' . DS . '*.core.php',
146
-					EE_CORE . 'request_stack' . DS . '*.core.php',
147
-					EE_CORE . 'middleware' . DS . '*.core.php',
142
+					EE_CORE.'*.core.php',
143
+					EE_ADMIN.'*.core.php',
144
+					EE_CPTS.'*.core.php',
145
+					EE_CORE.'data_migration_scripts'.DS.'*.core.php',
146
+					EE_CORE.'request_stack'.DS.'*.core.php',
147
+					EE_CORE.'middleware'.DS.'*.core.php',
148 148
 				)
149 149
 			)
150 150
 		);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                 array(),
157 157
                 array(),
158 158
                 CoffeeMaker::BREW_LOAD_ONLY,
159
-				array( EE_ADMIN . '*.core.php' )
159
+				array(EE_ADMIN.'*.core.php')
160 160
 			)
161 161
 		);
162 162
 		// add a wildcard recipe for loading core classes
Please login to merge, or discard this patch.
core/services/container/Recipe.php 2 patches
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use RuntimeException;
8 8
 
9 9
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 
@@ -23,313 +23,313 @@  discard block
 block discarded – undo
23 23
 class Recipe implements RecipeInterface
24 24
 {
25 25
 
26
-    /**
27
-     * A default Recipe to use if none is specified for a class
28
-     */
29
-    const DEFAULT_ID = '*';
30
-
31
-    /**
32
-     * Identifier for the entity class to be constructed.
33
-     * Typically a Fully Qualified Class Name
34
-     *
35
-     * @var string $identifier
36
-     */
37
-    private $identifier;
38
-
39
-    /**
40
-     * Fully Qualified Class Name
41
-     *
42
-     * @var string $fqcn
43
-     */
44
-    private $fqcn;
45
-
46
-    /**
47
-     * a dependency class map array
48
-     * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments),
49
-     * and that class type hints for an interface, then this property allows you to configure what dependencies
50
-     * get used when instantiating the class.
51
-     * For example:
52
-     *  There's a class called Coffee, and one of its constructor arguments is BeanInterface
53
-     *  There are two implementations of BeanInterface: HonduranBean, and KenyanBean
54
-     *  We want one Coffee object to use HonduranBean for its BeanInterface,
55
-     *  and the 2nd Coffee object to use KenyanBean for its BeanInterface.
56
-     *  To do this, we need to create two Recipes:
57
-     *      one with an identifier of 'HonduranCoffee' using the following ingredients :
58
-     *          array('BeanInterface' => 'HonduranBean')
59
-     *      and the other with an identifier of 'KenyanCoffee' using the following ingredients :
60
-     *          array('BeanInterface' => 'KenyanBean')
61
-     *  Then, whenever the CoffeeShop brews an instance of HonduranCoffee,
62
-     *  an instance of HonduranBean will get injected for the BeanInterface dependency,
63
-     *  and whenever the CoffeeShop brews an instance of KenyanCoffee,
64
-     *  an instance of KenyanBean will get injected for the BeanInterface dependency
65
-     *
66
-     * @var array $ingredients
67
-     */
68
-    private $ingredients = array();
69
-
70
-    /**
71
-     * one of the class constants from CoffeeShop:
72
-     *  CoffeeMaker::BREW_NEW - creates a new instance
73
-     *  CoffeeMaker::BREW_SHARED - creates a shared instance
74
-     *  CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate
75
-     *
76
-     * @var string $type
77
-     */
78
-    private $type;
79
-
80
-    /**
81
-     * class name aliases - typically a Fully Qualified Interface that the class implements
82
-     * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name
83
-     *
84
-     * @var array $filters
85
-     */
86
-    private $filters = array();
87
-
88
-    /**
89
-     * array of full server filepaths to files that may contain the class
90
-     *
91
-     * @var array $paths
92
-     */
93
-    private $paths = array();
94
-
95
-
96
-
97
-    /**
98
-     * Recipe constructor.
99
-     *
100
-     * @param string $identifier    class identifier, can be an alias, or FQCN, or whatever
101
-     * @param string $fqcn          \Fully\Qualified\ClassName, optional if $identifier is FQCN
102
-     * @param array  $ingredients   array of dependencies that can not be resolved automatically,
103
-     *                              used for resolving concrete classes for type hinted interfaces
104
-     *                              for the dependencies of THIS class
105
-     * @param string $type          recipe type: one of the class constants on
106
-     *                              \EventEspresso\core\services\container\CoffeeMaker
107
-     * @param array  $filters       array of class aliases, or class interfaces
108
-     *                              this works somewhat opposite to the $ingredients array above,
109
-     *                              in that this array specifies interfaces or aliases
110
-     *                              that this Recipe can be used for when resolving OTHER class's dependencies
111
-     * @param array  $paths         if class can not be loaded via PSR-4 autoloading,
112
-     *                              then supply a filepath, or array of filepaths, so that it can be included
113
-     */
114
-    public function __construct(
115
-	    $identifier,
116
-        $fqcn = '',
117
-        $filters = array(),
118
-        $ingredients = array(),
119
-	    $type = CoffeeMaker::BREW_NEW,
120
-	    $paths = array()
121
-    )
122
-    {
123
-        $this->setIdentifier($identifier);
124
-        $this->setFilters((array)$filters);
125
-        $this->setIngredients((array)$ingredients);
126
-        $this->setType($type);
127
-        $this->setPaths($paths);
128
-        $this->setFqcn($fqcn);
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * @return string
135
-     */
136
-    public function identifier()
137
-    {
138
-        return $this->identifier;
139
-    }
140
-
141
-
142
-
143
-    /**
144
-     * @return string
145
-     */
146
-    public function fqcn()
147
-    {
148
-        return $this->fqcn;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * @return array
155
-     */
156
-    public function filters()
157
-    {
158
-        return (array)$this->filters;
159
-    }
160
-
161
-
162
-
163
-    /**
164
-     * @return array
165
-     */
166
-    public function ingredients()
167
-    {
168
-        return $this->ingredients;
169
-    }
170
-
171
-
172
-
173
-    /**
174
-     * @return string
175
-     */
176
-    public function type()
177
-    {
178
-        return $this->type;
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     * @return array
185
-     */
186
-    public function paths()
187
-    {
188
-        return (array)$this->paths;
189
-    }
190
-
191
-
192
-
193
-    /**
194
-     * @param  string $identifier Identifier for the entity class that the Recipe applies to
195
-     *                            Typically a Fully Qualified Class Name
196
-     */
197
-    public function setIdentifier($identifier)
198
-    {
199
-        if ( ! is_string($identifier) || empty($identifier)) {
200
-            throw new InvalidIdentifierException(
201
-                is_object($identifier) ? get_class($identifier) : gettype($identifier),
202
-                __('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
203
-            );
204
-        }
205
-        $this->identifier = $identifier;
206
-    }
207
-
208
-
209
-
210
-    /**
211
-     * Ensures incoming string is a valid Fully Qualified Class Name,
212
-     * except if this is the default wildcard Recipe ( * ),
213
-     * or it's NOT an actual FQCN because the Recipe is using filepaths
214
-     * for classes that are not PSR-4 compatible
215
-     * PLZ NOTE:
216
-     *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
217
-     *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
218
-     *
219
-     * @param string $fqcn
220
-     */
221
-    public function setFqcn($fqcn)
222
-    {
223
-	    $fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
224
-        if ( ! is_string($fqcn)) {
225
-            throw new InvalidDataTypeException(
226
-                '$fqcn',
227
-                is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
228
-                __('string (Fully\Qualified\ClassName)', 'event_espresso')
229
-            );
230
-        }
231
-        $fqcn = ltrim($fqcn, '\\');
232
-        if (
233
-            $fqcn !== Recipe::DEFAULT_ID
234
-            && ! empty($fqcn)
235
-            && empty($this->paths)
236
-            && ! class_exists($fqcn)
237
-        ) {
238
-            throw new InvalidClassException($fqcn);
239
-        }
240
-        $this->fqcn = $fqcn;
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * @param array $ingredients    an array of dependencies where keys are the aliases and values are the FQCNs
247
-     *                              example:
248
-     *                              array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
249
-     */
250
-    public function setIngredients(array $ingredients)
251
-    {
252
-        if (empty($ingredients)) {
253
-            return;
254
-        }
255
-        if ( ! is_array($ingredients)) {
256
-            throw new InvalidDataTypeException(
257
-                '$ingredients',
258
-                is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
259
-                __('array of class dependencies', 'event_espresso')
260
-            );
261
-        }
262
-        $this->ingredients = array_merge($this->ingredients, $ingredients);
263
-    }
264
-
265
-
266
-    /**
267
-     * @param string $type one of the class constants returned from CoffeeMaker::getTypes()
268
-     */
269
-    public function setType($type = CoffeeMaker::BREW_NEW)
270
-    {
271
-        $this->type = CoffeeMaker::validateType($type);
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * @param array $filters an array of filters where keys are the aliases and values are the FQCNs
278
-     *                          example:
279
-     *                          array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
280
-     */
281
-    public function setFilters(array $filters)
282
-    {
283
-        if (empty($filters)) {
284
-            return;
285
-        }
286
-        if ( ! is_array($filters)) {
287
-            throw new InvalidDataTypeException(
288
-                '$filters',
289
-                is_object($filters) ? get_class($filters) : gettype($filters),
290
-                __('array of class aliases', 'event_espresso')
291
-            );
292
-        }
293
-        $this->filters = array_merge($this->filters, $filters);
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * Ensures incoming paths is a valid filepath, or array of valid filepaths,
300
-     * and merges them in with any existing filepaths
301
-     *
302
-     * PLZ NOTE:
303
-     *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
304
-     *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
305
-     *
306
-     * @param string|array $paths
307
-     */
308
-    public function setPaths($paths = array())
309
-    {
310
-        if (empty($paths)) {
311
-            return;
312
-        }
313
-        if ( ! (is_string($paths) || is_array($paths))) {
314
-            throw new InvalidDataTypeException(
315
-                '$path',
316
-                is_object($paths) ? get_class($paths) : gettype($paths),
317
-                __('string or array of strings (full server filepath(s))', 'event_espresso')
318
-            );
319
-        }
320
-        $paths = (array)$paths;
321
-        foreach ($paths as $path) {
322
-            if (strpos($path, '*') === false && ! is_readable($path)) {
323
-                throw new RuntimeException(
324
-                    sprintf(
325
-                        __('The following filepath is not readable: "%1$s"', 'event_espresso'),
326
-                        $path
327
-                    )
328
-                );
329
-            }
330
-        }
331
-        $this->paths = array_merge($this->paths, $paths);
332
-    }
26
+	/**
27
+	 * A default Recipe to use if none is specified for a class
28
+	 */
29
+	const DEFAULT_ID = '*';
30
+
31
+	/**
32
+	 * Identifier for the entity class to be constructed.
33
+	 * Typically a Fully Qualified Class Name
34
+	 *
35
+	 * @var string $identifier
36
+	 */
37
+	private $identifier;
38
+
39
+	/**
40
+	 * Fully Qualified Class Name
41
+	 *
42
+	 * @var string $fqcn
43
+	 */
44
+	private $fqcn;
45
+
46
+	/**
47
+	 * a dependency class map array
48
+	 * If a Recipe is for a single class (or group of classes that shares the EXACT SAME constructor arguments),
49
+	 * and that class type hints for an interface, then this property allows you to configure what dependencies
50
+	 * get used when instantiating the class.
51
+	 * For example:
52
+	 *  There's a class called Coffee, and one of its constructor arguments is BeanInterface
53
+	 *  There are two implementations of BeanInterface: HonduranBean, and KenyanBean
54
+	 *  We want one Coffee object to use HonduranBean for its BeanInterface,
55
+	 *  and the 2nd Coffee object to use KenyanBean for its BeanInterface.
56
+	 *  To do this, we need to create two Recipes:
57
+	 *      one with an identifier of 'HonduranCoffee' using the following ingredients :
58
+	 *          array('BeanInterface' => 'HonduranBean')
59
+	 *      and the other with an identifier of 'KenyanCoffee' using the following ingredients :
60
+	 *          array('BeanInterface' => 'KenyanBean')
61
+	 *  Then, whenever the CoffeeShop brews an instance of HonduranCoffee,
62
+	 *  an instance of HonduranBean will get injected for the BeanInterface dependency,
63
+	 *  and whenever the CoffeeShop brews an instance of KenyanCoffee,
64
+	 *  an instance of KenyanBean will get injected for the BeanInterface dependency
65
+	 *
66
+	 * @var array $ingredients
67
+	 */
68
+	private $ingredients = array();
69
+
70
+	/**
71
+	 * one of the class constants from CoffeeShop:
72
+	 *  CoffeeMaker::BREW_NEW - creates a new instance
73
+	 *  CoffeeMaker::BREW_SHARED - creates a shared instance
74
+	 *  CoffeeMaker::BREW_LOAD_ONLY - loads but does not instantiate
75
+	 *
76
+	 * @var string $type
77
+	 */
78
+	private $type;
79
+
80
+	/**
81
+	 * class name aliases - typically a Fully Qualified Interface that the class implements
82
+	 * identifiers passed to the CoffeeShop will be run through the filters to find the correct class name
83
+	 *
84
+	 * @var array $filters
85
+	 */
86
+	private $filters = array();
87
+
88
+	/**
89
+	 * array of full server filepaths to files that may contain the class
90
+	 *
91
+	 * @var array $paths
92
+	 */
93
+	private $paths = array();
94
+
95
+
96
+
97
+	/**
98
+	 * Recipe constructor.
99
+	 *
100
+	 * @param string $identifier    class identifier, can be an alias, or FQCN, or whatever
101
+	 * @param string $fqcn          \Fully\Qualified\ClassName, optional if $identifier is FQCN
102
+	 * @param array  $ingredients   array of dependencies that can not be resolved automatically,
103
+	 *                              used for resolving concrete classes for type hinted interfaces
104
+	 *                              for the dependencies of THIS class
105
+	 * @param string $type          recipe type: one of the class constants on
106
+	 *                              \EventEspresso\core\services\container\CoffeeMaker
107
+	 * @param array  $filters       array of class aliases, or class interfaces
108
+	 *                              this works somewhat opposite to the $ingredients array above,
109
+	 *                              in that this array specifies interfaces or aliases
110
+	 *                              that this Recipe can be used for when resolving OTHER class's dependencies
111
+	 * @param array  $paths         if class can not be loaded via PSR-4 autoloading,
112
+	 *                              then supply a filepath, or array of filepaths, so that it can be included
113
+	 */
114
+	public function __construct(
115
+		$identifier,
116
+		$fqcn = '',
117
+		$filters = array(),
118
+		$ingredients = array(),
119
+		$type = CoffeeMaker::BREW_NEW,
120
+		$paths = array()
121
+	)
122
+	{
123
+		$this->setIdentifier($identifier);
124
+		$this->setFilters((array)$filters);
125
+		$this->setIngredients((array)$ingredients);
126
+		$this->setType($type);
127
+		$this->setPaths($paths);
128
+		$this->setFqcn($fqcn);
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * @return string
135
+	 */
136
+	public function identifier()
137
+	{
138
+		return $this->identifier;
139
+	}
140
+
141
+
142
+
143
+	/**
144
+	 * @return string
145
+	 */
146
+	public function fqcn()
147
+	{
148
+		return $this->fqcn;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * @return array
155
+	 */
156
+	public function filters()
157
+	{
158
+		return (array)$this->filters;
159
+	}
160
+
161
+
162
+
163
+	/**
164
+	 * @return array
165
+	 */
166
+	public function ingredients()
167
+	{
168
+		return $this->ingredients;
169
+	}
170
+
171
+
172
+
173
+	/**
174
+	 * @return string
175
+	 */
176
+	public function type()
177
+	{
178
+		return $this->type;
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 * @return array
185
+	 */
186
+	public function paths()
187
+	{
188
+		return (array)$this->paths;
189
+	}
190
+
191
+
192
+
193
+	/**
194
+	 * @param  string $identifier Identifier for the entity class that the Recipe applies to
195
+	 *                            Typically a Fully Qualified Class Name
196
+	 */
197
+	public function setIdentifier($identifier)
198
+	{
199
+		if ( ! is_string($identifier) || empty($identifier)) {
200
+			throw new InvalidIdentifierException(
201
+				is_object($identifier) ? get_class($identifier) : gettype($identifier),
202
+				__('class identifier (typically a \Fully\Qualified\ClassName)', 'event_espresso')
203
+			);
204
+		}
205
+		$this->identifier = $identifier;
206
+	}
207
+
208
+
209
+
210
+	/**
211
+	 * Ensures incoming string is a valid Fully Qualified Class Name,
212
+	 * except if this is the default wildcard Recipe ( * ),
213
+	 * or it's NOT an actual FQCN because the Recipe is using filepaths
214
+	 * for classes that are not PSR-4 compatible
215
+	 * PLZ NOTE:
216
+	 *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
217
+	 *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
218
+	 *
219
+	 * @param string $fqcn
220
+	 */
221
+	public function setFqcn($fqcn)
222
+	{
223
+		$fqcn = ! empty($fqcn) ? $fqcn : $this->identifier;
224
+		if ( ! is_string($fqcn)) {
225
+			throw new InvalidDataTypeException(
226
+				'$fqcn',
227
+				is_object($fqcn) ? get_class($fqcn) : gettype($fqcn),
228
+				__('string (Fully\Qualified\ClassName)', 'event_espresso')
229
+			);
230
+		}
231
+		$fqcn = ltrim($fqcn, '\\');
232
+		if (
233
+			$fqcn !== Recipe::DEFAULT_ID
234
+			&& ! empty($fqcn)
235
+			&& empty($this->paths)
236
+			&& ! class_exists($fqcn)
237
+		) {
238
+			throw new InvalidClassException($fqcn);
239
+		}
240
+		$this->fqcn = $fqcn;
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * @param array $ingredients    an array of dependencies where keys are the aliases and values are the FQCNs
247
+	 *                              example:
248
+	 *                              array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
249
+	 */
250
+	public function setIngredients(array $ingredients)
251
+	{
252
+		if (empty($ingredients)) {
253
+			return;
254
+		}
255
+		if ( ! is_array($ingredients)) {
256
+			throw new InvalidDataTypeException(
257
+				'$ingredients',
258
+				is_object($ingredients) ? get_class($ingredients) : gettype($ingredients),
259
+				__('array of class dependencies', 'event_espresso')
260
+			);
261
+		}
262
+		$this->ingredients = array_merge($this->ingredients, $ingredients);
263
+	}
264
+
265
+
266
+	/**
267
+	 * @param string $type one of the class constants returned from CoffeeMaker::getTypes()
268
+	 */
269
+	public function setType($type = CoffeeMaker::BREW_NEW)
270
+	{
271
+		$this->type = CoffeeMaker::validateType($type);
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * @param array $filters an array of filters where keys are the aliases and values are the FQCNs
278
+	 *                          example:
279
+	 *                          array( 'ClassInterface' => 'Fully\Qualified\ClassName' )
280
+	 */
281
+	public function setFilters(array $filters)
282
+	{
283
+		if (empty($filters)) {
284
+			return;
285
+		}
286
+		if ( ! is_array($filters)) {
287
+			throw new InvalidDataTypeException(
288
+				'$filters',
289
+				is_object($filters) ? get_class($filters) : gettype($filters),
290
+				__('array of class aliases', 'event_espresso')
291
+			);
292
+		}
293
+		$this->filters = array_merge($this->filters, $filters);
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * Ensures incoming paths is a valid filepath, or array of valid filepaths,
300
+	 * and merges them in with any existing filepaths
301
+	 *
302
+	 * PLZ NOTE:
303
+	 *  Recipe::setFqcn() has a check to see if Recipe::$paths is empty or not,
304
+	 *  therefore you should always call Recipe::setPaths() before Recipe::setFqcn()
305
+	 *
306
+	 * @param string|array $paths
307
+	 */
308
+	public function setPaths($paths = array())
309
+	{
310
+		if (empty($paths)) {
311
+			return;
312
+		}
313
+		if ( ! (is_string($paths) || is_array($paths))) {
314
+			throw new InvalidDataTypeException(
315
+				'$path',
316
+				is_object($paths) ? get_class($paths) : gettype($paths),
317
+				__('string or array of strings (full server filepath(s))', 'event_espresso')
318
+			);
319
+		}
320
+		$paths = (array)$paths;
321
+		foreach ($paths as $path) {
322
+			if (strpos($path, '*') === false && ! is_readable($path)) {
323
+				throw new RuntimeException(
324
+					sprintf(
325
+						__('The following filepath is not readable: "%1$s"', 'event_espresso'),
326
+						$path
327
+					)
328
+				);
329
+			}
330
+		}
331
+		$this->paths = array_merge($this->paths, $paths);
332
+	}
333 333
 
334 334
 
335 335
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -121,8 +121,8 @@  discard block
 block discarded – undo
121 121
     )
122 122
     {
123 123
         $this->setIdentifier($identifier);
124
-        $this->setFilters((array)$filters);
125
-        $this->setIngredients((array)$ingredients);
124
+        $this->setFilters((array) $filters);
125
+        $this->setIngredients((array) $ingredients);
126 126
         $this->setType($type);
127 127
         $this->setPaths($paths);
128 128
         $this->setFqcn($fqcn);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function filters()
157 157
     {
158
-        return (array)$this->filters;
158
+        return (array) $this->filters;
159 159
     }
160 160
 
161 161
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
      */
186 186
     public function paths()
187 187
     {
188
-        return (array)$this->paths;
188
+        return (array) $this->paths;
189 189
     }
190 190
 
191 191
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
                 __('string or array of strings (full server filepath(s))', 'event_espresso')
318 318
             );
319 319
         }
320
-        $paths = (array)$paths;
320
+        $paths = (array) $paths;
321 321
         foreach ($paths as $path) {
322 322
             if (strpos($path, '*') === false && ! is_readable($path)) {
323 323
                 throw new RuntimeException(
Please login to merge, or discard this patch.
core/services/container/DependencyInjector.php 1 patch
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use UnexpectedValueException;
5 5
 
6 6
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
7
-    exit('No direct script access allowed');
7
+	exit('No direct script access allowed');
8 8
 }
9 9
 
10 10
 
@@ -22,214 +22,214 @@  discard block
 block discarded – undo
22 22
 class DependencyInjector implements InjectorInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @var CoffeePotInterface $coffee_pot
27
-     */
28
-    private $coffee_pot;
29
-
30
-    /**
31
-     * @var \EEH_Array $array_helper
32
-     */
33
-    private $array_helper;
34
-
35
-    /**
36
-     * @var \ReflectionClass[] $reflectors
37
-     */
38
-    private $reflectors;
39
-
40
-    /**
41
-     * @var \ReflectionMethod[] $constructors
42
-     */
43
-    private $constructors;
44
-
45
-    /**
46
-     * @var \ReflectionParameter[] $parameters
47
-     */
48
-    private $parameters;
49
-
50
-
51
-
52
-    /**
53
-     * DependencyInjector constructor
54
-     *
55
-     * @param CoffeePotInterface $coffee_pot
56
-     * @param \EEH_Array         $array_helper
57
-     */
58
-    public function __construct(CoffeePotInterface $coffee_pot, \EEH_Array $array_helper)
59
-    {
60
-        $this->coffee_pot = $coffee_pot;
61
-        $this->array_helper = $array_helper;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * getReflectionClass
68
-     * checks if a ReflectionClass object has already been generated for a class
69
-     * and returns that instead of creating a new one
70
-     *
71
-     * @param string $class_name
72
-     * @return \ReflectionClass
73
-     */
74
-    public function getReflectionClass($class_name)
75
-    {
76
-        if (
77
-            ! isset($this->reflectors[$class_name])
78
-            || ! $this->reflectors[$class_name] instanceof \ReflectionClass
79
-        ) {
80
-            $this->reflectors[$class_name] = new \ReflectionClass($class_name);
81
-        }
82
-        return $this->reflectors[$class_name];
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * getConstructor
89
-     * checks if a ReflectionMethod object has already been generated for the class constructor
90
-     * and returns that instead of creating a new one
91
-     *
92
-     * @param \ReflectionClass $reflector
93
-     * @return \ReflectionMethod
94
-     */
95
-    protected function getConstructor(\ReflectionClass $reflector)
96
-    {
97
-        if (
98
-            ! isset($this->constructors[$reflector->getName()])
99
-            || ! $this->constructors[$reflector->getName()] instanceof \ReflectionMethod
100
-        ) {
101
-            $this->constructors[$reflector->getName()] = $reflector->getConstructor();
102
-        }
103
-        return $this->constructors[$reflector->getName()];
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     * getParameters
110
-     * checks if an array of ReflectionParameter objects has already been generated for the class constructor
111
-     * and returns that instead of creating a new one
112
-     *
113
-     * @param \ReflectionMethod $constructor
114
-     * @return \ReflectionParameter[]
115
-     */
116
-    protected function getParameters(\ReflectionMethod $constructor)
117
-    {
118
-        if ( ! isset($this->parameters[$constructor->class])) {
119
-            $this->parameters[$constructor->class] = $constructor->getParameters();
120
-        }
121
-        return $this->parameters[$constructor->class];
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * resolveDependencies
128
-     * examines the constructor for the requested class to determine
129
-     * if any dependencies exist, and if they can be injected.
130
-     * If so, then those classes will be added to the array of arguments passed to the constructor
131
-     * PLZ NOTE: this is achieved by type hinting the constructor params
132
-     * For example:
133
-     *        if attempting to load a class "Foo" with the following constructor:
134
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
135
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
136
-     *        but only IF they are NOT already present in the incoming arguments array,
137
-     *        and the correct classes can be loaded
138
-     *
139
-     * @param RecipeInterface   $recipe
140
-     * @param \ReflectionClass  $reflector
141
-     * @param array             $arguments
142
-     * @return array
143
-     */
144
-    public function resolveDependencies(RecipeInterface $recipe, \ReflectionClass $reflector, $arguments = array())
145
-    {
146
-        // if arguments array is numerically and sequentially indexed, then we want it to remain as is,
147
-        // else wrap it in an additional array so that it doesn't get split into multiple parameters
148
-        $arguments = $this->array_helper->is_array_numerically_and_sequentially_indexed($arguments)
149
-            ? $arguments
150
-            : array($arguments);
151
-        $resolved_parameters = array();
152
-        // let's examine the constructor
153
-        // let's examine the constructor
154
-        $constructor = $this->getConstructor($reflector);
155
-        // whu? huh? nothing?
156
-        if ( ! $constructor) {
157
-            return $arguments;
158
-        }
159
-        // get constructor parameters
160
-        $params = $this->getParameters($constructor);
161
-        if (empty($params)) {
162
-            return $resolved_parameters;
163
-        }
164
-        $ingredients = $recipe->ingredients();
165
-        // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
166
-        $argument_keys = array_keys($arguments);
167
-        // now loop thru all of the constructors expected parameters
168
-        foreach ($params as $index => $param) {
169
-            if ( ! $param instanceof \ReflectionParameter) {
170
-                continue;
171
-            }
172
-            // is this a dependency for a specific class ?
173
-            $param_class = $param->getClass() ? $param->getClass()->name : null;
174
-            if (
175
-                // param is specified in the list of ingredients for this Recipe
176
-                isset($ingredients[$param_class])
177
-            ) {
178
-                // attempt to inject the dependency
179
-                $resolved_parameters[$index] = $this->injectDependency($ingredients[$param_class]);
180
-            } else if (
181
-                // param is not even a class
182
-                empty($param_class)
183
-                // and something already exists in the incoming arguments for this param
184
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
185
-            ) {
186
-                // add parameter from incoming arguments
187
-                $resolved_parameters[$index] = $arguments[$argument_keys[$index]];
188
-            } else if (
189
-                // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
190
-                ! empty($param_class)
191
-                && isset($argument_keys[$index], $arguments[$argument_keys[$index]])
192
-                && $arguments[$argument_keys[$index]] instanceof $param_class
193
-            ) {
194
-                // add parameter from incoming arguments
195
-                $resolved_parameters[$index] = $arguments[$argument_keys[$index]];
196
-            } else if (
197
-                // parameter is type hinted as a class, and should be injected
198
-            ! empty($param_class)
199
-            ) {
200
-                // attempt to inject the dependency
201
-                $resolved_parameters[$index] = $this->injectDependency($param_class);
202
-            } else if ($param->isOptional()) {
203
-                $resolved_parameters[$index] = $param->getDefaultValue();
204
-            } else {
205
-                $resolved_parameters[$index] = null;
206
-            }
207
-        }
208
-        return $resolved_parameters;
209
-    }
210
-
211
-
212
-
213
-    /**
214
-     * @param string $param_class
215
-     * @return mixed
216
-     */
217
-    private function injectDependency($param_class)
218
-    {
219
-        $dependency = $this->coffee_pot->brew($param_class);
220
-        if ( ! $dependency instanceof $param_class) {
221
-            throw new UnexpectedValueException(
222
-                sprintf(
223
-                    __(
224
-                        'Could not resolve dependency for "%1$s" for the "%2$s" class constructor.',
225
-                        'event_espresso'
226
-                    ),
227
-                    $param_class
228
-                )
229
-            );
230
-        }
231
-        return $dependency;
232
-    }
25
+	/**
26
+	 * @var CoffeePotInterface $coffee_pot
27
+	 */
28
+	private $coffee_pot;
29
+
30
+	/**
31
+	 * @var \EEH_Array $array_helper
32
+	 */
33
+	private $array_helper;
34
+
35
+	/**
36
+	 * @var \ReflectionClass[] $reflectors
37
+	 */
38
+	private $reflectors;
39
+
40
+	/**
41
+	 * @var \ReflectionMethod[] $constructors
42
+	 */
43
+	private $constructors;
44
+
45
+	/**
46
+	 * @var \ReflectionParameter[] $parameters
47
+	 */
48
+	private $parameters;
49
+
50
+
51
+
52
+	/**
53
+	 * DependencyInjector constructor
54
+	 *
55
+	 * @param CoffeePotInterface $coffee_pot
56
+	 * @param \EEH_Array         $array_helper
57
+	 */
58
+	public function __construct(CoffeePotInterface $coffee_pot, \EEH_Array $array_helper)
59
+	{
60
+		$this->coffee_pot = $coffee_pot;
61
+		$this->array_helper = $array_helper;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * getReflectionClass
68
+	 * checks if a ReflectionClass object has already been generated for a class
69
+	 * and returns that instead of creating a new one
70
+	 *
71
+	 * @param string $class_name
72
+	 * @return \ReflectionClass
73
+	 */
74
+	public function getReflectionClass($class_name)
75
+	{
76
+		if (
77
+			! isset($this->reflectors[$class_name])
78
+			|| ! $this->reflectors[$class_name] instanceof \ReflectionClass
79
+		) {
80
+			$this->reflectors[$class_name] = new \ReflectionClass($class_name);
81
+		}
82
+		return $this->reflectors[$class_name];
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * getConstructor
89
+	 * checks if a ReflectionMethod object has already been generated for the class constructor
90
+	 * and returns that instead of creating a new one
91
+	 *
92
+	 * @param \ReflectionClass $reflector
93
+	 * @return \ReflectionMethod
94
+	 */
95
+	protected function getConstructor(\ReflectionClass $reflector)
96
+	{
97
+		if (
98
+			! isset($this->constructors[$reflector->getName()])
99
+			|| ! $this->constructors[$reflector->getName()] instanceof \ReflectionMethod
100
+		) {
101
+			$this->constructors[$reflector->getName()] = $reflector->getConstructor();
102
+		}
103
+		return $this->constructors[$reflector->getName()];
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 * getParameters
110
+	 * checks if an array of ReflectionParameter objects has already been generated for the class constructor
111
+	 * and returns that instead of creating a new one
112
+	 *
113
+	 * @param \ReflectionMethod $constructor
114
+	 * @return \ReflectionParameter[]
115
+	 */
116
+	protected function getParameters(\ReflectionMethod $constructor)
117
+	{
118
+		if ( ! isset($this->parameters[$constructor->class])) {
119
+			$this->parameters[$constructor->class] = $constructor->getParameters();
120
+		}
121
+		return $this->parameters[$constructor->class];
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * resolveDependencies
128
+	 * examines the constructor for the requested class to determine
129
+	 * if any dependencies exist, and if they can be injected.
130
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
131
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
132
+	 * For example:
133
+	 *        if attempting to load a class "Foo" with the following constructor:
134
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
135
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
136
+	 *        but only IF they are NOT already present in the incoming arguments array,
137
+	 *        and the correct classes can be loaded
138
+	 *
139
+	 * @param RecipeInterface   $recipe
140
+	 * @param \ReflectionClass  $reflector
141
+	 * @param array             $arguments
142
+	 * @return array
143
+	 */
144
+	public function resolveDependencies(RecipeInterface $recipe, \ReflectionClass $reflector, $arguments = array())
145
+	{
146
+		// if arguments array is numerically and sequentially indexed, then we want it to remain as is,
147
+		// else wrap it in an additional array so that it doesn't get split into multiple parameters
148
+		$arguments = $this->array_helper->is_array_numerically_and_sequentially_indexed($arguments)
149
+			? $arguments
150
+			: array($arguments);
151
+		$resolved_parameters = array();
152
+		// let's examine the constructor
153
+		// let's examine the constructor
154
+		$constructor = $this->getConstructor($reflector);
155
+		// whu? huh? nothing?
156
+		if ( ! $constructor) {
157
+			return $arguments;
158
+		}
159
+		// get constructor parameters
160
+		$params = $this->getParameters($constructor);
161
+		if (empty($params)) {
162
+			return $resolved_parameters;
163
+		}
164
+		$ingredients = $recipe->ingredients();
165
+		// and the keys for the incoming arguments array so that we can compare existing arguments with what is expected
166
+		$argument_keys = array_keys($arguments);
167
+		// now loop thru all of the constructors expected parameters
168
+		foreach ($params as $index => $param) {
169
+			if ( ! $param instanceof \ReflectionParameter) {
170
+				continue;
171
+			}
172
+			// is this a dependency for a specific class ?
173
+			$param_class = $param->getClass() ? $param->getClass()->name : null;
174
+			if (
175
+				// param is specified in the list of ingredients for this Recipe
176
+				isset($ingredients[$param_class])
177
+			) {
178
+				// attempt to inject the dependency
179
+				$resolved_parameters[$index] = $this->injectDependency($ingredients[$param_class]);
180
+			} else if (
181
+				// param is not even a class
182
+				empty($param_class)
183
+				// and something already exists in the incoming arguments for this param
184
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
185
+			) {
186
+				// add parameter from incoming arguments
187
+				$resolved_parameters[$index] = $arguments[$argument_keys[$index]];
188
+			} else if (
189
+				// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class
190
+				! empty($param_class)
191
+				&& isset($argument_keys[$index], $arguments[$argument_keys[$index]])
192
+				&& $arguments[$argument_keys[$index]] instanceof $param_class
193
+			) {
194
+				// add parameter from incoming arguments
195
+				$resolved_parameters[$index] = $arguments[$argument_keys[$index]];
196
+			} else if (
197
+				// parameter is type hinted as a class, and should be injected
198
+			! empty($param_class)
199
+			) {
200
+				// attempt to inject the dependency
201
+				$resolved_parameters[$index] = $this->injectDependency($param_class);
202
+			} else if ($param->isOptional()) {
203
+				$resolved_parameters[$index] = $param->getDefaultValue();
204
+			} else {
205
+				$resolved_parameters[$index] = null;
206
+			}
207
+		}
208
+		return $resolved_parameters;
209
+	}
210
+
211
+
212
+
213
+	/**
214
+	 * @param string $param_class
215
+	 * @return mixed
216
+	 */
217
+	private function injectDependency($param_class)
218
+	{
219
+		$dependency = $this->coffee_pot->brew($param_class);
220
+		if ( ! $dependency instanceof $param_class) {
221
+			throw new UnexpectedValueException(
222
+				sprintf(
223
+					__(
224
+						'Could not resolve dependency for "%1$s" for the "%2$s" class constructor.',
225
+						'event_espresso'
226
+					),
227
+					$param_class
228
+				)
229
+			);
230
+		}
231
+		return $dependency;
232
+	}
233 233
 
234 234
 }
235 235
 // End of file DependencyInjector.php
Please login to merge, or discard this patch.
core/services/container/InjectorInterface.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\services\container;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -17,39 +17,39 @@  discard block
 block discarded – undo
17 17
 interface InjectorInterface
18 18
 {
19 19
 
20
-    /**
21
-     * getReflectionClass
22
-     * checks if a ReflectionClass object has already been generated for a class
23
-     * and returns that instead of creating a new one
24
-     *
25
-     * @access public
26
-     * @param string $class_name
27
-     * @return \ReflectionClass
28
-     */
29
-    public function getReflectionClass($class_name);
30
-
31
-
32
-
33
-    /**
34
-     * resolveDependencies
35
-     * examines the constructor for the requested class to determine
36
-     * if any dependencies exist, and if they can be injected.
37
-     * If so, then those classes will be added to the array of arguments passed to the constructor
38
-     * PLZ NOTE: this is achieved by type hinting the constructor params
39
-     * For example:
40
-     *        if attempting to load a class "Foo" with the following constructor:
41
-     *        __construct( Bar $bar_class, Fighter $grohl_class )
42
-     *        then $bar_class and $grohl_class will be added to the $arguments array,
43
-     *        but only IF they are NOT already present in the incoming arguments array,
44
-     *        and the correct classes can be loaded
45
-     *
46
-     * @access public
47
-     * @param \EventEspresso\core\services\container\RecipeInterface $recipe
48
-     * @param \ReflectionClass                                       $reflector
49
-     * @param array                                                  $arguments
50
-     * @return array
51
-     */
52
-    public function resolveDependencies(RecipeInterface $recipe, \ReflectionClass $reflector, $arguments = array());
20
+	/**
21
+	 * getReflectionClass
22
+	 * checks if a ReflectionClass object has already been generated for a class
23
+	 * and returns that instead of creating a new one
24
+	 *
25
+	 * @access public
26
+	 * @param string $class_name
27
+	 * @return \ReflectionClass
28
+	 */
29
+	public function getReflectionClass($class_name);
30
+
31
+
32
+
33
+	/**
34
+	 * resolveDependencies
35
+	 * examines the constructor for the requested class to determine
36
+	 * if any dependencies exist, and if they can be injected.
37
+	 * If so, then those classes will be added to the array of arguments passed to the constructor
38
+	 * PLZ NOTE: this is achieved by type hinting the constructor params
39
+	 * For example:
40
+	 *        if attempting to load a class "Foo" with the following constructor:
41
+	 *        __construct( Bar $bar_class, Fighter $grohl_class )
42
+	 *        then $bar_class and $grohl_class will be added to the $arguments array,
43
+	 *        but only IF they are NOT already present in the incoming arguments array,
44
+	 *        and the correct classes can be loaded
45
+	 *
46
+	 * @access public
47
+	 * @param \EventEspresso\core\services\container\RecipeInterface $recipe
48
+	 * @param \ReflectionClass                                       $reflector
49
+	 * @param array                                                  $arguments
50
+	 * @return array
51
+	 */
52
+	public function resolveDependencies(RecipeInterface $recipe, \ReflectionClass $reflector, $arguments = array());
53 53
 
54 54
 }
55 55
 // End of file InjectorInterface.php
Please login to merge, or discard this patch.
core/services/container/SharedCoffeeMaker.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 namespace EventEspresso\core\services\container;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -24,46 +24,46 @@  discard block
 block discarded – undo
24 24
 
25 25
 
26 26
 
27
-    /**
28
-     * @return string
29
-     */
30
-    public function type()
31
-    {
32
-        return CoffeeMaker::BREW_SHARED;
33
-    }
27
+	/**
28
+	 * @return string
29
+	 */
30
+	public function type()
31
+	{
32
+		return CoffeeMaker::BREW_SHARED;
33
+	}
34 34
 
35 35
 
36 36
 
37
-    /**
38
-     * @param RecipeInterface $recipe
39
-     * @param array           $arguments
40
-     * @return mixed
41
-     */
42
-    public function brew(RecipeInterface $recipe, $arguments = array())
43
-    {
44
-        $this->resolveClassAndFilepath($recipe);
45
-        $reflector = $this->injector()->getReflectionClass($recipe->fqcn());
46
-        $method = $this->resolveInstantiationMethod($reflector);
47
-        switch ($method) {
48
-            case 'instance' :
49
-            case 'new_instance' :
50
-            case 'new_instance_from_db';
51
-                $service = call_user_func_array(
52
-                    array($reflector->getName(), $method),
53
-                    $this->injector()->resolveDependencies($recipe, $reflector, $arguments)
54
-                );
55
-                break;
56
-            case 'newInstance' :
57
-                $service = $reflector->newInstance();
58
-                break;
59
-            case 'newInstanceArgs' :
60
-            default :
61
-                $service = $reflector->newInstanceArgs(
62
-                    $this->injector()->resolveDependencies($recipe, $reflector, $arguments)
63
-                );
64
-        }
65
-        return $this->coffeePot()->addService($recipe->identifier(), $service);
66
-    }
37
+	/**
38
+	 * @param RecipeInterface $recipe
39
+	 * @param array           $arguments
40
+	 * @return mixed
41
+	 */
42
+	public function brew(RecipeInterface $recipe, $arguments = array())
43
+	{
44
+		$this->resolveClassAndFilepath($recipe);
45
+		$reflector = $this->injector()->getReflectionClass($recipe->fqcn());
46
+		$method = $this->resolveInstantiationMethod($reflector);
47
+		switch ($method) {
48
+			case 'instance' :
49
+			case 'new_instance' :
50
+			case 'new_instance_from_db';
51
+				$service = call_user_func_array(
52
+					array($reflector->getName(), $method),
53
+					$this->injector()->resolveDependencies($recipe, $reflector, $arguments)
54
+				);
55
+				break;
56
+			case 'newInstance' :
57
+				$service = $reflector->newInstance();
58
+				break;
59
+			case 'newInstanceArgs' :
60
+			default :
61
+				$service = $reflector->newInstanceArgs(
62
+					$this->injector()->resolveDependencies($recipe, $reflector, $arguments)
63
+				);
64
+		}
65
+		return $this->coffeePot()->addService($recipe->identifier(), $service);
66
+	}
67 67
 
68 68
 }
69 69
 // End of file SharedCoffeeMaker.php
Please login to merge, or discard this patch.