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 |
||
75 | |||
76 | /** |
||
77 | * Load the mapped file for a namespace prefix and relative class. |
||
78 | * |
||
79 | * @param string $prefix The namespace prefix. |
||
80 | * @param string $relativeClass The relative class name. |
||
81 | * |
||
82 | * @return string Empty string if no mapped file can be |
||
83 | * loaded, or the name of the mapped file that was loaded. |
||
84 | */ |
||
85 | protected function loadMappedFile($prefix, $relativeClass) |
||
105 | |||
106 | /** |
||
107 | * Normalize path using WordPress naming convertions. |
||
108 | * |
||
109 | * @param string $path Relative class path. |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function normalizePath(string $path): string |
||
116 | |||
117 | /** |
||
118 | * Get relative file path. |
||
119 | * |
||
120 | * @param string $relativeClass Relative class. |
||
121 | * @return string |
||
122 | */ |
||
123 | protected function getRelativeFile(string $relativeClass): string |
||
136 | |||
137 | /** |
||
138 | * If a file exists, require it from the file system. |
||
139 | * |
||
140 | * @param string $file The file to require. |
||
141 | * @return bool True if the file exists, false if not. |
||
142 | */ |
||
143 | protected function requireFile(string $file): bool |
||
151 | } |
||
152 |