-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathloader.php
More file actions
35 lines (31 loc) · 706 Bytes
/
loader.php
File metadata and controls
35 lines (31 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* Convenience loader. Use very optional.
*/
/**
* Simple class loader.
*/
class MyLoader
{
protected $bases = [];
public function __construct(array $bases) {
$this->bases = $bases;
}
/**
* @input $name FQ classname, without a leading "\".
*/
function load($name) {
foreach($this->bases as $prefix => $basePath) {
if(strpos($name, $prefix) === 0) {
$name = substr($name, strlen($prefix));
$path = $basePath . "/" . str_replace("\\", "/", $name) . ".php";
include_once $path;
}
}
}
}
$myPath = dirname(realpath(__FILE__));
$myLoader = new MyLoader([
"JsonSchema" => $myPath]
);
spl_autoload_register([$myLoader, "load"]);