forked from opencaching/opencaching-pl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassPathDictionary.php
77 lines (71 loc) · 2.38 KB
/
ClassPathDictionary.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Autoload class solution.
*
* Classes can be loaded automaticly without need of use include statements.
* While new class creating, try use namespace, leading to class php file. Then script can extract
* path and class filename by namespace.
*
* Example:
*
* place file Classname.php in directory lib/Directoryname:
* <?php
* namespace lib\Directoryname;
* class Classname
* {
* ... (class body)
* }
*
* then to use this class it is enough to call:
* $variable = new \lib\Directoryname\Classname();
* and file is included automaticly.
*
*/
class ClassPathDictionary
{
/**
* While new class creating, try use namespace, leading to class php file. Thanks to that class
* can be loaded automaticly witch function getClassPath().
*
* use this method if using namespace is not possible any reason
*
* example:
* 'className' => 'path/to/filename.php',
*
* !!! please preserve alphabetical order. !!!
*/
private static $classDictionary = array(
'Smarty' => 'lib/Smarty/libs/Smarty.class.php',
'cache' => 'lib/cache.php',
'dataBase' => 'lib/Database/Db.php',
'MyDB' => 'lib/Database/MyDB.php',
'PasswordManager' => 'lib/passwordManager.php',
'GeoKretyApi' => 'GeoKretyAPI.php',
'GetRegions' => 'GetRegions.php',
'myninc' => 'lib/myn.inc.php',
'powerTrailBase' => 'powerTrail/powerTrailBase.php',
'powerTrailController' => 'powerTrail/powerTrailController.php',
'sendEmail' => 'powerTrail/sendEmail.php',
'Kint' => 'lib/kint/Kint.class.php',
'userInputFilter' => 'lib/userInputFilters/userInputFilter.php'
);
public static function getClassPath($className)
{
$classPathArr = explode('\\', $className);
if (isset($classPathArr[1])) { /* namespace solution */
$classPath = __DIR__ . '/../';
foreach ($classPathArr as $pathPiece) {
$classPath .= $pathPiece . '/';
}
$classPath = substr($classPath, 0, -1) . '.php';
return $classPath;
}
return __DIR__ . '/../' . self::$classDictionary[$className];
}
}
spl_autoload_register(function ($className) {
if(strpos($className, 'Smarty_') !== false){ /* ignore smary class autoloading */
return;
}
include_once ClassPathDictionary::getClassPath($className);
});