-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.php
62 lines (49 loc) · 1.62 KB
/
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
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
57
58
59
60
61
62
<?php
/********************************
*
* File Name: Loader.php
* Description: Module loader
*
*******************************/
function LoadModule($module, $params = NULL) {
$matches = array();
$reason = '';
$ret = preg_match('/^(?P<package>(?:[a-z\\d\\-]+\\.)+)(?P<name>(?P<flag>[lfc]{1})[a-z\\d\\-]+)$/i', $module, $matches);
if ($ret === FALSE) {
$reason = 'Illegal character in module name.';
goto errorHandler;
}
if ($ret === 0) {
$reason = 'There was an error in the package name you\'ve specified.';
goto errorHandler;
}
$package = $matches['package'];
$name = $matches['name'];
$flag = $matches['flag'];
$path = LIBRARY_ROOT . str_replace('.', DIRECTORY_SEPARATOR, $package) . $name . '.php';
if (!file_exists($path)) {
$reason = "Module not found. File path = '$path'.";
goto errorHandler;
}
require_once($path);
switch ($flag) {
case 'l': case 'L':
// Load functions from file.
// Functions are global by default
// Load only
return TRUE;
case 'f': case 'F':
// Load functions from file.
// Functions are global by default
// Load and execute
return $name($params);
case 'c': case 'C':
// Load classes from file.
// Must create return an object
return new $name($params);
}
errorHandler:
trigger_error("Error loading module '$module'. Reason: $reason.", E_USER_ERROR);
return FALSE;
}
?>