-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.php
37 lines (32 loc) · 1.07 KB
/
init.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
// InitFile
// Add Reusable Directory Auto Loader
// Class Auto Loader will detect all the subdirectories and add the class files followed under "/lib" directory on your server root.
// PHP 7.2^ preferred method
function requireClass($classFile, $className)
{
if (!class_exists($className) && $className === basename($classFile, ".php")) require_once $classFile;
}
function retrieveDir($dirs, $currentPath, $className)
{
foreach ($dirs as $dir) {
if ($dir == ".." || $dir == ".") {
continue;
}
$newPath = $currentPath . '/' . $dir;
if (is_dir($newPath)) {
$subdirs = scandir($newPath);
retrieveDir($subdirs, $newPath, $className);
} else {
requireClass($newPath, $className);
}
}
}
if (!function_exists('autoClassLoader')) {
function autoClassLoader($className)
{
$subdirs = scandir($_SERVER['DOCUMENT_ROOT'] . '/lib');
$classFile = retrieveDir($subdirs, $_SERVER['DOCUMENT_ROOT'] . '/lib', $className);
}
}
spl_autoload_register('autoClassLoader');