-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoload.php
56 lines (46 loc) · 1.38 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require "Core/utils.php";
$autoload_limit = 100;
$autoload_counter = 0;
spl_autoload_register(function (string $class)
use($autoload_limit, &$autoload_counter) : void
{
$file = str_replace('\\', '/', $class . '.php');
if(file_exists($file))
{
require $file;
\Core\initClass($class);
return;
}
return;
// The following code is case insensitive path search,
// in case you prefer different file naming conventions.
// It actually should not affect some systems, so you
// better not remove it unless you know what you're doing.
// Still, i recommend that you don't happen to use it,
// because scanning directories is slower than knowing
// the correct path from the beginning.
$path = explode('/', strtolower($file));
$target = '.';
while(count($path) && is_dir($target))
{
foreach(scandir($target) as $item)
{
if(strtolower($item) == $path[0])
{
$path = array_slice($path, 1);
$target = $target . '/' . $item;
}
}
}
if(file_exists($target))
{
require $target;
\Core\initClass($class);
}
});