forked from thevajko/cv-06
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClassLoader.php
30 lines (27 loc) · 916 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
<?php
/**
* Class ClassLoader
* Just for automated class loading by namespace
*/
class ClassLoader
{
public static function Boot()
{
spl_autoload_register(function ($class_name) {
// input param is full name of the required class
// there must be the same dir structure as namespace to make this work correctly
// first we must convert namespace separators to dir separators of current system
$file = str_replace('\\', DIRECTORY_SEPARATOR, $class_name) . '.php';
// check if file with class exists
if (file_exists($file)) {
// if do include it
require $file;
} else {
// if not throw exception
throw new Exception("Class {$class_name} file {$file} was not found.");
}
});
}
}
// register class loading
ClassLoader::Boot();