-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoload.php
56 lines (50 loc) · 1.37 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
56
<?php
require_once "./vendor/autoload.php";
/**
* Auto import all the custom files, which are not part of the _framework.
*/
define("CUSTOM_DIR", ".");
/**
* Import all services classes
*/
$services = rsearch(CUSTOM_DIR . '/services', '/.*\.php/');
foreach ($services as $service) {
require_once($service);
}
/**
* Import all entites classes
*/
$entities = rsearch(CUSTOM_DIR . '/entities', '/.*\.php/');
foreach ($entities as $entity) {
require_once($entity);
}
/**
* Import all DAO (Data access object) classes
*/
$daos = rsearch(CUSTOM_DIR . '/dao', '/.*\.php/');
foreach ($daos as $dao) {
require_once($dao);
}
/**
* Import all route classes
*/
$routes = rsearch(CUSTOM_DIR . '/routes', '/.*\.php/');
foreach ($routes as $route) {
require_once($route);
}
// $regPattern should be using regular expression
// Source: https://stackoverflow.com/questions/17160696/php-glob-scan-in-subfolders-for-a-file
function rsearch($folder, $regPattern) {
try {
$dir = new RecursiveDirectoryIterator($folder);
$ite = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($ite, $regPattern, RegexIterator::GET_MATCH);
$fileList = array();
foreach($files as $file) {
$fileList = array_merge($fileList, $file);
}
return $fileList;
} catch (Exception $e) {
return [];
}
}