-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassLoader.php
37 lines (31 loc) · 929 Bytes
/
ClassLoader.php
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
36
37
<?php
/**
* Created by PhpStorm.
* User: Andrew
* Date: 2013.12.22.
* Time: 12:02
*/
class ClassLoader {
protected $paths = array();
public function addPath($path) {
$this->paths[] = $path;
}
public function register() {
spl_autoload_register(array(&$this, "autoload"));
}
public function autoload($class_name) {
$pearl = str_replace("\\", "_", $class_name);
$namespace = str_replace("\\", "/", $class_name);
foreach($this->paths as $path) {
if(file_exists($path.$pearl.".php")) {
require $path.$pearl.".php";
return;
}
if(file_exists($path.$namespace.".php")) {
require $path.$namespace.".php";
return;
}
}
throw new Exception("Class with the name \"{$class_name}\" could not be loaded because could not be found.");
}
}