1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* class autoloader |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package PSI |
9
|
|
|
* @author Michael Cramer <[email protected]> |
10
|
|
|
* @copyright 2009 phpSysInfo |
11
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
12
|
|
|
* @version SVN: $Id: autoloader.inc.php 660 2012-08-27 11:08:40Z namiltd $ |
13
|
|
|
* @link http://phpsysinfo.sourceforge.net |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
error_reporting(E_ALL | E_STRICT); |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* automatic loading classes when using them |
20
|
|
|
* |
21
|
|
|
* @param string $class_name name of the class which must be loaded |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
function __autoload($class_name) |
26
|
|
|
{ |
27
|
|
|
//$class_name = str_replace('-', '', $class_name); |
|
|
|
|
28
|
|
|
|
29
|
|
|
/* case-insensitive folders */ |
30
|
|
|
$dirs = array('/plugins/'.strtolower($class_name).'/', '/includes/mb/', '/includes/ups/'); |
31
|
|
|
|
32
|
|
View Code Duplication |
foreach ($dirs as $dir) { |
|
|
|
|
33
|
|
|
if (file_exists(APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php')) { |
34
|
|
|
include_once APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php'; |
35
|
|
|
|
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/* case-sensitive folders */ |
41
|
|
|
$dirs = array('/includes/', '/includes/interface/', '/includes/to/', '/includes/to/device/', '/includes/os/', '/includes/plugin/', '/includes/xml/', '/includes/web/', '/includes/error/', '/includes/js/', '/includes/output/'); |
42
|
|
|
|
43
|
|
View Code Duplication |
foreach ($dirs as $dir) { |
|
|
|
|
44
|
|
|
if (file_exists(APP_ROOT.$dir.'class.'.$class_name.'.inc.php')) { |
45
|
|
|
include_once APP_ROOT.$dir.'class.'.$class_name.'.inc.php'; |
46
|
|
|
|
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$error = PSI_Error::singleton(); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$error->addError("_autoload(\"".$class_name."\")", "autoloading of class file (class.".$class_name.".inc.php) failed!"); |
|
|
|
|
54
|
|
|
$error->errorsAsXML(); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* sets a user-defined error handler function |
59
|
|
|
* |
60
|
|
|
* @param integer $level contains the level of the error raised, as an integer. |
61
|
|
|
* @param string $message contains the error message, as a string. |
62
|
|
|
* @param string $file which contains the filename that the error was raised in, as a string. |
63
|
|
|
* @param integer $line which contains the line number the error was raised at, as an integer. |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
function errorHandlerPsi($level, $message, $file, $line) |
68
|
|
|
{ |
69
|
|
|
$error = PSI_Error::singleton(); |
|
|
|
|
70
|
|
|
$error->addPhpError("errorHandlerPsi : ", "Level : ".$level." Message : ".$message." File : ".$file." Line : ".$line); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
set_error_handler('errorHandlerPsi'); |
74
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.