1 | <?php |
||
57 | class Psr4Autoloader { |
||
58 | |||
59 | /** |
||
60 | * An associative array where the key is a namespace prefix and the value |
||
61 | * is an array of base directories for classes in that namespace. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $prefixes = array(); |
||
66 | |||
67 | |||
68 | |||
69 | /** |
||
70 | * Register loader with SPL autoloader stack. |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | public function register() { |
||
77 | |||
78 | |||
79 | |||
80 | /** |
||
81 | * Adds a base directory for a namespace prefix. |
||
82 | * |
||
83 | * @param string $prefix The namespace prefix. |
||
84 | * @param string $base_dir A base directory for class files in the |
||
85 | * namespace. |
||
86 | * @param bool $prepend If true, prepend the base directory to the stack |
||
87 | * instead of appending it; this causes it to be searched first rather |
||
88 | * than last. |
||
89 | * @return void |
||
90 | */ |
||
91 | public function addNamespace( $prefix, $base_dir, $prepend = false ) { |
||
92 | // normalize namespace prefix |
||
93 | $prefix = trim( $prefix, '\\' ) . '\\'; |
||
94 | // normalize the base directory with a trailing separator |
||
95 | $base_dir = rtrim( $base_dir, DIRECTORY_SEPARATOR ) . '/'; |
||
96 | // initialize the namespace prefix array |
||
97 | if ( isset( $this->prefixes[ $prefix ] ) === false ) { |
||
98 | $this->prefixes[ $prefix ] = array(); |
||
99 | } |
||
100 | // retain the base directory for the namespace prefix |
||
101 | if ( $prepend ) { |
||
102 | array_unshift( $this->prefixes[ $prefix ], $base_dir ); |
||
103 | } else { |
||
104 | array_push( $this->prefixes[ $prefix ], $base_dir ); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | |||
109 | |||
110 | /** |
||
111 | * Loads the class file for a given class name. |
||
112 | * |
||
113 | * @param string $class The fully-qualified class name. |
||
114 | * @return mixed The mapped file name on success, or boolean false on |
||
115 | * failure. |
||
116 | */ |
||
117 | public function loadClass( $class ) { |
||
139 | |||
140 | |||
141 | |||
142 | /** |
||
143 | * Load the mapped file for a namespace prefix and relative class. |
||
144 | * |
||
145 | * @param string $prefix The namespace prefix. |
||
146 | * @param string $relative_class The relative class name. |
||
147 | * @return mixed Boolean false if no mapped file can be loaded, or the |
||
148 | * name of the mapped file that was loaded. |
||
149 | */ |
||
150 | protected function loadMappedFile( $prefix, $relative_class ) { |
||
172 | |||
173 | |||
174 | |||
175 | /** |
||
176 | * If a file exists, require it from the file system. |
||
177 | * |
||
178 | * @param string $file The file to require. |
||
179 | * @return bool True if the file exists, false if not. |
||
180 | */ |
||
181 | protected function requireFile( $file ) { |
||
188 | |||
189 | |||
190 | |||
191 | } |
||
192 | // End of file Psr4Autoloader.php |
||
193 | // Location: /core/Psr4Autoloader.php |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: