-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoload.php
executable file
·35 lines (30 loc) · 980 Bytes
/
autoload.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
<?php
/**
* User: utku
* Date: 14.09.2017
* Web : http://www.utkukutlu.com
*/
function load($dir) {
$namespaces = array(
'app\\' => 'app',
'system\\' => 'system',
);
foreach ($namespaces as $namespace => $classpaths) {
if (!is_array($classpaths)) {
$classpaths = array($classpaths);
}
spl_autoload_register(function ($classname) use ($namespace, $classpaths, $dir) {
if (preg_match("#^" . preg_quote($namespace) . "#", $classname)) {
$classname = str_replace($namespace, "", $classname);
$filename = preg_replace("#\\\\#", "/", $classname) . ".php";
foreach ($classpaths as $classpath) {
$fullpath = $dir . "/" . $classpath . "/$filename";
if (file_exists($fullpath)) {
include_once $fullpath;
}
}
}
});
}
}
load(__DIR__);