1 | <?php |
||
13 | class Autoloader |
||
14 | { |
||
15 | /** |
||
16 | * An associative array where the key is a namespace prefix and the value |
||
17 | * is an array of base directories for classes in that namespace. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $prefixes = []; |
||
22 | |||
23 | /** |
||
24 | * Register loader with SPL autoloader stack. |
||
25 | */ |
||
26 | public function register() |
||
30 | |||
31 | /** |
||
32 | * Adds a base directory for a namespace prefix. |
||
33 | * |
||
34 | * @param string $prefix The namespace prefix. |
||
35 | * @param string $baseDir A base directory for class files in the |
||
36 | * namespace. |
||
37 | */ |
||
38 | public function addNamespace(string $prefix, string $baseDir) |
||
49 | |||
50 | /** |
||
51 | * Loads the class file for a given class name. |
||
52 | * |
||
53 | * @param string $class The fully-qualified class name. |
||
54 | * @return string The mapped file name on success, or emtpy string on |
||
55 | * failure. |
||
56 | */ |
||
57 | public function loadClass($class): string |
||
82 | |||
83 | /** |
||
84 | * Load the mapped file for a namespace prefix and relative class. |
||
85 | * |
||
86 | * @param string $prefix The namespace prefix. |
||
87 | * @param string $relativeClass The relative class name. |
||
88 | * |
||
89 | * @return string Empty string if no mapped file can be |
||
90 | * loaded, or the name of the mapped file that was loaded. |
||
91 | */ |
||
92 | protected function loadMappedFile($prefix, $relativeClass) |
||
112 | |||
113 | /** |
||
114 | * Normalize path using WordPress naming convertions. |
||
115 | * |
||
116 | * @param string $path Relative class path. |
||
117 | * @return string |
||
118 | */ |
||
119 | protected function normalizePath(string $path): string |
||
123 | |||
124 | /** |
||
125 | * Get relative file path. |
||
126 | * |
||
127 | * @param string $relativeClass Relative class. |
||
128 | * @return string |
||
129 | */ |
||
130 | protected function getRelativeFile(string $relativeClass): string |
||
143 | |||
144 | /** |
||
145 | * If a file exists, require it from the file system. |
||
146 | * |
||
147 | * @param string $file The file to require. |
||
148 | * @return bool True if the file exists, false if not. |
||
149 | */ |
||
150 | protected function requireFile(string $file): bool |
||
158 | } |
||
159 |