forked from Maxlab/php-tasks-to-prepare-for-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.php
25 lines (20 loc) · 735 Bytes
/
loader.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
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
spl_autoload_register(function ($class) {
$parts = explode('\\', $class);
$yourStartingPath = dirname(__FILE__).DIRECTORY_SEPARATOR.'src';
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($yourStartingPath),
RecursiveIteratorIterator::SELF_FIRST
);
foreach($iterator as $file) {
if($file->isDir()) {
$file_path = $file->getRealpath().DIRECTORY_SEPARATOR.end($parts).'.php';
if(file_exists($file_path)) {
$file_path = str_replace(dirname(__FILE__).DIRECTORY_SEPARATOR, '', $file_path);
require_once($file_path);
}
}
}
});