1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class AutoLoader |
5
|
|
|
* |
6
|
|
|
* @todo Changes to this file may require further testing. |
7
|
|
|
* @todo Use PSR-0 or PSR-4 based autoloading in the future, or through Composer |
8
|
|
|
*/ |
9
|
|
|
class AutoLoader |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
private static $pgAutoLoader = array( |
13
|
|
|
'Wiki' => 'Includes/Wiki.php', |
14
|
|
|
'User' => 'Includes/User.php', |
15
|
|
|
'Page' => 'Includes/Page.php', |
16
|
|
|
'Image' => 'Includes/Image.php', |
17
|
|
|
'XMLParse' => 'Includes/XMLParse.php', |
18
|
|
|
'Script' => 'Script.php', |
19
|
|
|
'UtfNormal' => 'Plugins/normalize/UtfNormal.php', |
20
|
|
|
'DatabaseMySQL' => 'Plugins/database/MySQL.php', |
21
|
|
|
'DatabaseMySQLi' => 'Plugins/database/MySQLi.php', |
22
|
|
|
'DatabasePgSQL' => 'Plugins/database/PgSQL.php', |
23
|
|
|
'DatabaseBase' => 'Plugins/database.php', |
24
|
|
|
'ResultWrapper' => 'Plugins/database.php', |
25
|
|
|
'lime_test' => 'Includes/lime_test.php', |
26
|
|
|
'lime_output' => 'Includes/limeOutput.php', |
27
|
|
|
'lime_output_color' => 'Includes/limeOutputColor.php', |
28
|
|
|
'lime_colorizer' => 'Includes/limeColorizer.php', |
29
|
|
|
'lime_harness' => 'Includes/limeHarness.php', |
30
|
|
|
'lime_coverage' => 'Includes/limeCoverage.php', |
31
|
|
|
'lime_registration' => 'Includes/limeRegistration.php', |
32
|
|
|
'sfYaml' => 'Plugins/yaml/sfYaml.php', |
33
|
|
|
'sfYamlDumper' => 'Plugins/yaml/sfYamlDumper.php', |
34
|
|
|
'sfYamlInline' => 'Plugins/yaml/sfYamlInline.php', |
35
|
|
|
'sfYamlParser' => 'Plugins/yaml/sfYamlParser.php', |
36
|
|
|
'Text_Diff' => 'Plugins/diff/textdiff/Diff.php', |
37
|
|
|
'Text_MappedDiff' => 'Plugins/diff/textdiff/Diff.php', |
38
|
|
|
'Text_Diff_Op' => 'Plugins/diff/textdiff/Diff.php', |
39
|
|
|
'Text_Diff_Op_copy' => 'Plugins/diff/textdiff/Diff.php', |
40
|
|
|
'Text_Diff_Op_delete' => 'Plugins/diff/textdiff/Diff.php', |
41
|
|
|
'Text_Diff_Op_add' => 'Plugins/diff/textdiff/Diff.php', |
42
|
|
|
'Text_Diff_Op_change' => 'Plugins/diff/textdiff/Diff.php', |
43
|
|
|
'Text_Diff3' => 'Plugins/diff/textdiff/Diff3.php', |
44
|
|
|
'Text_Diff3_Op' => 'Plugins/diff/textdiff/Diff3.php', |
45
|
|
|
'Text_Diff3_Op_copy' => 'Plugins/diff/textdiff/Diff3.php', |
46
|
|
|
'Text_Diff3_BlockBuilder' => 'Plugins/diff/textdiff/Diff3.php', |
47
|
|
|
'Text_Diff_ThreeWay' => 'Plugins/diff/textdiff/Diff/ThreeWay.php', |
48
|
|
|
'Text_Diff_ThreeWay_Op' => 'Plugins/diff/textdiff/Diff/ThreeWay.php', |
49
|
|
|
'Text_Diff_ThreeWay_Op_copy' => 'Plugins/diff/textdiff/Diff/ThreeWay.php', |
50
|
|
|
'Text_Diff_ThreeWay_BlockBuilder' => 'Plugins/diff/textdiff/Diff/ThreeWay.php', |
51
|
|
|
'Text_Diff_Renderer' => 'Plugins/diff/textdiff/Diff/Renderer.php', |
52
|
|
|
'Text_Diff_Mapped' => 'Plugins/diff/textdiff/Diff/Mapped.php', |
53
|
|
|
'Text_Diff_Renderer_unified' => 'Plugins/diff/textdiff/Diff/Renderer/unified.php', |
54
|
|
|
'Text_Diff_Renderer_inline' => 'Plugins/diff/textdiff/Diff/Renderer/inline.php', |
55
|
|
|
'Text_Diff_Renderer_context' => 'Plugins/diff/textdiff/Diff/Renderer/context.php', |
56
|
|
|
'Text_Diff_Renderer_colorized' => 'Plugins/diff/textdiff/Diff/Renderer/colorized.php', |
57
|
|
|
'Text_Diff_Renderer_dualview' => 'Plugins/diff/textdiff/Diff/Renderer/dualview.php', |
58
|
|
|
'Text_Diff_Engine_xdiff' => 'Plugins/diff/textdiff/Diff/Engine/xdiff.php', |
59
|
|
|
'Text_Diff_Engine_string' => 'Plugins/diff/textdiff/Diff/Engine/string.php', |
60
|
|
|
'Text_Diff_Engine_shell' => 'Plugins/diff/textdiff/Diff/Engine/shell.php', |
61
|
|
|
'Text_Diff_Engine_native' => 'Plugins/diff/textdiff/Diff/Engine/native.php', |
62
|
|
|
'PeachyAWBFunctions' => 'Includes/PeachyAWBFunctions.php', |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Takes a class name and attempt to load it. Class name must be found in $pgAutoLoader. |
67
|
|
|
* |
68
|
|
|
* @param string $class_name Name of class we're looking for. |
69
|
|
|
* @return boolean|null Returns true if the function successfully loads the class. Otherwise returns false. |
70
|
|
|
* Returning false is important on failure as it allows Zend to try and look in other registered autoloaders as well. |
71
|
|
|
*/ |
72
|
|
|
public static function autoload($class_name) |
73
|
|
|
{ |
74
|
|
|
global $pgIP; |
75
|
|
|
|
76
|
|
|
if (isset(self::$pgAutoLoader[$class_name]) && is_file($pgIP . self::$pgAutoLoader[$class_name])) { |
77
|
|
|
require_once($pgIP . self::$pgAutoLoader[$class_name]); |
78
|
|
|
|
79
|
|
|
return true; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (is_file($pgIP . 'Plugins/' . $class_name . '.php')) { |
83
|
|
|
Hooks::runHook('LoadPlugin', array(&$class_name)); |
84
|
|
|
require_once($pgIP . 'Plugins/' . $class_name . '.php'); |
85
|
|
|
|
86
|
|
|
return true; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
spl_autoload_register(array('AutoLoader', 'autoload')); |
92
|
|
|
|
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.