1 | <?php |
||
18 | class Loader extends Component implements SingletonInterface |
||
19 | { |
||
20 | /** |
||
21 | * Default memory segment. |
||
22 | */ |
||
23 | const MEMORY = 'loadmap'; |
||
24 | |||
25 | /** |
||
26 | * Loader memory segment. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $name = ''; |
||
31 | |||
32 | /** |
||
33 | * List of classes loaded while this working session. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | private $classes = []; |
||
38 | |||
39 | /** |
||
40 | * Association between class and it's location. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | private $loadmap = []; |
||
45 | |||
46 | /** |
||
47 | * Is SPL methods handled. |
||
48 | * |
||
49 | * @var bool |
||
50 | */ |
||
51 | private $enabled = false; |
||
52 | |||
53 | /** |
||
54 | * @invisible |
||
55 | * @var MemoryInterface |
||
56 | */ |
||
57 | protected $memory = null; |
||
58 | |||
59 | /** |
||
60 | * Loader will automatically handle SPL autoload functions to start caching loadmap. |
||
61 | * |
||
62 | * @param MemoryInterface $memory |
||
63 | * @param bool $enable Automatically enable. |
||
64 | * @param string $name |
||
65 | */ |
||
66 | public function __construct( |
||
78 | |||
79 | /** |
||
80 | * Check if loader is enabled. |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function isEnabled(): bool |
||
88 | |||
89 | /** |
||
90 | * Handle SPL auto location, will go to top of spl chain. |
||
91 | * |
||
92 | * @return $this|self |
||
93 | */ |
||
94 | public function enable(): Loader |
||
107 | |||
108 | /** |
||
109 | * Stop handling SPL calls. |
||
110 | * |
||
111 | * @return $this|self |
||
112 | */ |
||
113 | public function disable(): Loader |
||
126 | |||
127 | /** |
||
128 | * Re-enable autoload to push it up into food chain. |
||
129 | */ |
||
130 | public function reset() |
||
134 | |||
135 | /** |
||
136 | * Try to load class declaration from memory or delegate it to other auto-loaders. |
||
137 | * |
||
138 | * @param string $class Class name with namespace included. |
||
139 | */ |
||
140 | public function loadClass(string $class) |
||
156 | |||
157 | /** |
||
158 | * All loaded classes. |
||
159 | * |
||
160 | * @return array |
||
161 | */ |
||
162 | public function getClasses(): array |
||
166 | |||
167 | /** |
||
168 | * Check if desired class exists in loadmap. |
||
169 | * |
||
170 | * @param string $class |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | public function isKnown(string $class): bool |
||
178 | |||
179 | /** |
||
180 | * Destroy loader. |
||
181 | */ |
||
182 | public function __destruct() |
||
186 | |||
187 | /** |
||
188 | * Try to load class using external auto-loaders. |
||
189 | * |
||
190 | * @param string $class |
||
191 | */ |
||
192 | protected function loadExternal(string $class) |
||
229 | } |
||
230 |