-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoloader.php
39 lines (30 loc) · 887 Bytes
/
autoloader.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
38
39
<?php
namespace pdfcreator;
/**
* It likes to load things
* @author 10usb
*/
class Autoloader {
/**
* Registeres the autoloader
*/
public static function register() {
spl_autoload_register('pdfcreator\\Autoloader::load');
}
/**
* Load a class or interface by its name, ain't that cool?
* @param string $name Class name
* @throws \Exception
* @return boolean
*/
public static function load($name){
if(substr($name, 0, 11)!='pdfcreator\\') return false;
$filename = __DIR__.'/src/'.implode('/', array_slice(explode('\\', $name), 1)).'.php';
if(!file_exists($filename)) throw new \Exception('File "'.$filename.'" not found');
require_once $filename;
if(class_exists($name) || interface_exists($name)) return true;
throw new \Exception('Class or Interface "'.$name.'" not exists');
}
}
// Lets kick some ass
Autoloader::register();