Completed
Branch BUG-9548-transaction-completio... (9c74af)
by
unknown
515:33 queued 500:28
created
core/helpers/EEH_Autoloader.helper.php 1 patch
Spacing   +48 added lines, -48 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
 /**
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 	 * @return \EEH_Autoloader
51 51
 	 */
52 52
 	private function __construct() {
53
-		if ( self::$_autoloaders === null ) {
53
+		if (self::$_autoloaders === null) {
54 54
 			self::$_autoloaders = array();
55 55
 			$this->_register_custom_autoloaders();
56
-			spl_autoload_register( array( $this, 'espresso_autoloader' ) );
56
+			spl_autoload_register(array($this, 'espresso_autoloader'));
57 57
 		}
58 58
 	}
59 59
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 */
66 66
 	public static function instance() {
67 67
 		// check if class object is instantiated
68
-		if ( ! self::$_instance instanceof EEH_Autoloader ) {
68
+		if ( ! self::$_instance instanceof EEH_Autoloader) {
69 69
 			self::$_instance = new self();
70 70
 		}
71 71
 		return self::$_instance;
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
 	 * @internal  param string $class_name - simple class name ie: session
83 83
 	 * @return 	void
84 84
 	 */
85
-	public static function espresso_autoloader( $class_name ) {
86
-		if ( isset( self::$_autoloaders[ $class_name ] ) ) {
87
-			require_once( self::$_autoloaders[ $class_name ] );
85
+	public static function espresso_autoloader($class_name) {
86
+		if (isset(self::$_autoloaders[$class_name])) {
87
+			require_once(self::$_autoloaders[$class_name]);
88 88
 		}
89 89
 	}
90 90
 
@@ -99,26 +99,26 @@  discard block
 block discarded – undo
99 99
 	 * @param bool           $debug **deprecated**
100 100
 	 * @throws \EE_Error
101 101
 	 */
102
-	public static function register_autoloader( $class_paths, $read_check = true, $debug = false ) {
103
-		$class_paths = is_array( $class_paths ) ? $class_paths : array( $class_paths );
104
-		foreach ( $class_paths as $class => $path ) {
102
+	public static function register_autoloader($class_paths, $read_check = true, $debug = false) {
103
+		$class_paths = is_array($class_paths) ? $class_paths : array($class_paths);
104
+		foreach ($class_paths as $class => $path) {
105 105
 			// don't give up! you gotta...
106 106
 			// get some class
107
-			if ( empty( $class )) {
108
-				throw new EE_Error ( sprintf( __( 'No Class name was specified while registering an autoloader for the following path: %s.','event_espresso' ), $path ));
107
+			if (empty($class)) {
108
+				throw new EE_Error(sprintf(__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
109 109
 			}
110 110
 			// one day you will find the path young grasshopper
111
-			if ( empty( $path )) {
112
-				throw new EE_Error ( sprintf( __( 'No path was specified while registering an autoloader for the %s class.','event_espresso' ), $class ));
111
+			if (empty($path)) {
112
+				throw new EE_Error(sprintf(__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
113 113
 			}
114 114
 			// is file readable ?
115
-			if ( $read_check && ! is_readable( $path )) {
116
-				throw new EE_Error ( sprintf( __( 'The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s','event_espresso' ), $class, $path ));
115
+			if ($read_check && ! is_readable($path)) {
116
+				throw new EE_Error(sprintf(__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
117 117
 			}
118
-			if ( ! isset( self::$_autoloaders[ $class ] )) {
119
-				self::$_autoloaders[ $class ] = str_replace( array( '/', '\\' ), DS, $path );
120
-				if ( EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug ) ) {
121
-					EEH_Debug_Tools::printr( self::$_autoloaders[ $class ], $class, __FILE__, __LINE__ );
118
+			if ( ! isset(self::$_autoloaders[$class])) {
119
+				self::$_autoloaders[$class] = str_replace(array('/', '\\'), DS, $path);
120
+				if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
121
+					EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__);
122 122
 				}
123 123
 			}
124 124
 		}
@@ -149,13 +149,13 @@  discard block
 block discarded – undo
149 149
 	private function _register_custom_autoloaders() {
150 150
 		EEH_Autoloader::$debug = '';
151 151
 		\EEH_Autoloader::register_helpers_autoloaders();
152
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'interfaces' );
153
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE );
154
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_INTERFACES, true );
155
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_MODELS, true );
156
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CLASSES );
157
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
158
-		if ( EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' ) {
152
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces');
153
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
154
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
155
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
156
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
157
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
158
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
159 159
 			EEH_Debug_Tools::instance()->show_times();
160 160
 		}
161 161
 	}
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @access public
169 169
 	 */
170 170
 	public static function register_helpers_autoloaders() {
171
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_HELPERS );
171
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
172 172
 	}
173 173
 
174 174
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	 * 	@return void
195 195
 	 */
196 196
 	public static function register_line_item_display_autoloaders() {
197
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(  EE_LIBRARIES . 'line_item_display' , true );
197
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true);
198 198
 	}
199 199
 
200 200
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 * 	@return void
208 208
 	 */
209 209
 	public static function register_line_item_filter_autoloaders() {
210
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(  EE_LIBRARIES . 'line_item_filters' , true );
210
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true);
211 211
 	}
212 212
 
213 213
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 	 * 	@return void
221 221
 	 */
222 222
 	public static function register_template_part_autoloaders() {
223
-		EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_LIBRARIES . 'template_parts', true );
223
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true);
224 224
 	}
225 225
 
226 226
 
@@ -237,35 +237,35 @@  discard block
 block discarded – undo
237 237
 	 * @param bool   $debug  **deprecated**
238 238
 	 * @throws \EE_Error
239 239
 	 */
240
-	public static function register_autoloaders_for_each_file_in_folder( $folder, $recursive = false, $debug = false ){
241
-		if ( EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug ) {
242
-			EEH_Debug_Tools::instance()->start_timer( basename( $folder ) );
240
+	public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false) {
241
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
242
+			EEH_Debug_Tools::instance()->start_timer(basename($folder));
243 243
 		}
244 244
 		// make sure last char is a /
245
-		$folder .= $folder[strlen($folder)-1] !== DS ? DS : '';
245
+		$folder .= $folder[strlen($folder) - 1] !== DS ? DS : '';
246 246
 		$class_to_filepath_map = array();
247
-		$exclude = array( 'index' );
247
+		$exclude = array('index');
248 248
 		//get all the files in that folder that end in php
249
-		$filepaths = glob( $folder.'*');
249
+		$filepaths = glob($folder.'*');
250 250
 
251
-		if ( empty( $filepaths ) ) {
251
+		if (empty($filepaths)) {
252 252
 			return;
253 253
 		}
254 254
 
255
-		foreach( $filepaths as $filepath ) {
256
-			if ( substr( $filepath, -4, 4 ) === '.php' ) {
257
-				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename( $filepath );
258
-				if ( ! in_array( $class_name, $exclude )) {
259
-					$class_to_filepath_map [ $class_name ] = $filepath;
255
+		foreach ($filepaths as $filepath) {
256
+			if (substr($filepath, -4, 4) === '.php') {
257
+				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
258
+				if ( ! in_array($class_name, $exclude)) {
259
+					$class_to_filepath_map [$class_name] = $filepath;
260 260
 				}
261
-			} else if ( $recursive ) {
262
-				EEH_Autoloader::register_autoloaders_for_each_file_in_folder( $filepath, $recursive );
261
+			} else if ($recursive) {
262
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive);
263 263
 			}
264 264
 		}
265 265
 		// we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
266
-		self::register_autoloader( $class_to_filepath_map, false, $debug );
267
-		if ( EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' ) {
268
-			EEH_Debug_Tools::instance()->stop_timer( basename( $folder ) );
266
+		self::register_autoloader($class_to_filepath_map, false, $debug);
267
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
268
+			EEH_Debug_Tools::instance()->stop_timer(basename($folder));
269 269
 		}
270 270
 	}
271 271
 
Please login to merge, or discard this patch.