@@ -192,8 +192,8 @@ |
||
| 192 | 192 | // replace namespace separators with directory separators |
| 193 | 193 | // in the relative class name, append with .php |
| 194 | 194 | $file = $base_dir |
| 195 | - . str_replace( '\\', '/', $relative_class ) |
|
| 196 | - . '.php'; |
|
| 195 | + . str_replace( '\\', '/', $relative_class ) |
|
| 196 | + . '.php'; |
|
| 197 | 197 | |
| 198 | 198 | // if the mapped file exists, require it |
| 199 | 199 | if ( $this->requireFile( $file ) ) { |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | 100 | public function register() { |
| 101 | - spl_autoload_register( array( $this, 'loadClass' ) ); |
|
| 101 | + spl_autoload_register(array($this, 'loadClass')); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -113,23 +113,23 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - public function addNamespace( $prefix, $base_dir, $prepend = false ) { |
|
| 116 | + public function addNamespace($prefix, $base_dir, $prepend = false) { |
|
| 117 | 117 | // normalize namespace prefix |
| 118 | - $prefix = trim( $prefix, '\\' ) . '\\'; |
|
| 118 | + $prefix = trim($prefix, '\\') . '\\'; |
|
| 119 | 119 | |
| 120 | 120 | // normalize the base directory with a trailing separator |
| 121 | - $base_dir = rtrim( $base_dir, DIRECTORY_SEPARATOR ) . '/'; |
|
| 121 | + $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/'; |
|
| 122 | 122 | |
| 123 | 123 | // initialize the namespace prefix array |
| 124 | - if ( isset( $this->prefixes[ $prefix ] ) === false ) { |
|
| 124 | + if (isset($this->prefixes[ $prefix ]) === false) { |
|
| 125 | 125 | $this->prefixes[ $prefix ] = array(); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // retain the base directory for the namespace prefix |
| 129 | - if ( $prepend ) { |
|
| 130 | - array_unshift( $this->prefixes[ $prefix ], $base_dir ); |
|
| 129 | + if ($prepend) { |
|
| 130 | + array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
| 131 | 131 | } else { |
| 132 | - array_push( $this->prefixes[ $prefix ], $base_dir ); |
|
| 132 | + array_push($this->prefixes[ $prefix ], $base_dir); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -141,29 +141,29 @@ discard block |
||
| 141 | 141 | * @return mixed The mapped file name on success, or boolean false on |
| 142 | 142 | * failure. |
| 143 | 143 | */ |
| 144 | - public function loadClass( $class ) { |
|
| 144 | + public function loadClass($class) { |
|
| 145 | 145 | // the current namespace prefix |
| 146 | 146 | $prefix = $class; |
| 147 | 147 | |
| 148 | 148 | // work backwards through the namespace names of the fully-qualified |
| 149 | 149 | // class name to find a mapped file name |
| 150 | - while ( false !== $pos = strrpos( $prefix, '\\' ) ) { |
|
| 150 | + while (false !== $pos = strrpos($prefix, '\\')) { |
|
| 151 | 151 | |
| 152 | 152 | // retain the trailing namespace separator in the prefix |
| 153 | - $prefix = substr( $class, 0, $pos + 1 ); |
|
| 153 | + $prefix = substr($class, 0, $pos + 1); |
|
| 154 | 154 | |
| 155 | 155 | // the rest is the relative class name |
| 156 | - $relative_class = substr( $class, $pos + 1 ); |
|
| 156 | + $relative_class = substr($class, $pos + 1); |
|
| 157 | 157 | |
| 158 | 158 | // try to load a mapped file for the prefix and relative class |
| 159 | - $mapped_file = $this->loadMappedFile( $prefix, $relative_class ); |
|
| 160 | - if ( $mapped_file ) { |
|
| 159 | + $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
|
| 160 | + if ($mapped_file) { |
|
| 161 | 161 | return $mapped_file; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // remove the trailing namespace separator for the next iteration |
| 165 | 165 | // of strrpos() |
| 166 | - $prefix = rtrim( $prefix, '\\' ); |
|
| 166 | + $prefix = rtrim($prefix, '\\'); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | // never found a mapped file |
@@ -179,24 +179,24 @@ discard block |
||
| 179 | 179 | * @return mixed Boolean false if no mapped file can be loaded, or the |
| 180 | 180 | * name of the mapped file that was loaded. |
| 181 | 181 | */ |
| 182 | - protected function loadMappedFile( $prefix, $relative_class ) { |
|
| 182 | + protected function loadMappedFile($prefix, $relative_class) { |
|
| 183 | 183 | // are there any base directories for this namespace prefix? |
| 184 | - if ( isset( $this->prefixes[ $prefix ] ) === false ) { |
|
| 184 | + if (isset($this->prefixes[ $prefix ]) === false) { |
|
| 185 | 185 | return false; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // look through base directories for this namespace prefix |
| 189 | - foreach ( $this->prefixes[ $prefix ] as $base_dir ) { |
|
| 189 | + foreach ($this->prefixes[ $prefix ] as $base_dir) { |
|
| 190 | 190 | |
| 191 | 191 | // replace the namespace prefix with the base directory, |
| 192 | 192 | // replace namespace separators with directory separators |
| 193 | 193 | // in the relative class name, append with .php |
| 194 | 194 | $file = $base_dir |
| 195 | - . str_replace( '\\', '/', $relative_class ) |
|
| 195 | + . str_replace('\\', '/', $relative_class) |
|
| 196 | 196 | . '.php'; |
| 197 | 197 | |
| 198 | 198 | // if the mapped file exists, require it |
| 199 | - if ( $this->requireFile( $file ) ) { |
|
| 199 | + if ($this->requireFile($file)) { |
|
| 200 | 200 | // yes, we're done |
| 201 | 201 | return $file; |
| 202 | 202 | } |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | * |
| 214 | 214 | * @return bool True if the file exists, false if not. |
| 215 | 215 | */ |
| 216 | - protected function requireFile( $file ) { |
|
| 217 | - if ( file_exists( $file ) ) { |
|
| 216 | + protected function requireFile($file) { |
|
| 217 | + if (file_exists($file)) { |
|
| 218 | 218 | require $file; |
| 219 | 219 | |
| 220 | 220 | return true; |