PEAR2_DB_Pl2Method-0.1.0 › PEAR2_DB_Pl2Method-0.1.0/php/PEAR2/Autoload.php
- PEAR2_DB_Pl2Method-0.1.0/
- doc/
- pear2.php.net/
- PEAR2_DB_Pl2Method/
- examples/
- examples/
- examples/
- PEAR2_DB_Pl2Method/
- pear2.php.net/
- php/
- PEAR2/
- Autoload.php
- DB/
- Pl2Method/
- Pl2Method.php
- Exception.php
- MultiErrors/
- MultiErrors.php
- PEAR2/
- doc/
- package.xml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace PEAR2;
if (!class_exists('\PEAR2\Autoload', false)) {
class Autoload
{
/**
* Whether the autoload class has been spl_autoload_register-ed
*
* @var bool
*/
protected static $registered = false;
/**
* Array of PEAR2 autoload paths registered
*
* @var array
*/
protected static $paths = array();
/**
* Initialize the PEAR2 autoloader
*
* @param string $path Directory path to register
*
* @return void
*/
static function initialize($path)
{
self::register();
self::addPath($path);
}
/**
* Register the PEAR2 autoload class with spl_autoload_register
*
* @return void
*/
protected static function register()
{
if (!self::$registered) {
// set up __autoload
$autoload = spl_autoload_functions();
spl_autoload_register('PEAR2\Autoload::load');
if (function_exists('__autoload') && ($autoload === false)) {
// __autoload() was being used, but now would be ignored, add
// it to the autoload stack
spl_autoload_register('__autoload');
}
}
self::$registered = true;
}
/**
* Add a path
*
* @param string $path The directory to add to the set of PEAR2 paths
*
* @return void
*/
protected static function addPath($path)
{
if (!in_array($path, self::$paths)) {
self::$paths[] = $path;
}
}
/**
* Load a PEAR2 class
*
* @param string $class The class to load
*
* @return bool
*/
static function load($class)
{
if (strtolower(substr($class, 0, 6)) !== 'pear2\\') {
return false;
}
$file = str_replace(array('_', '\\'), DIRECTORY_SEPARATOR, $class) . '.php';
foreach (self::$paths as $path) {
if (file_exists($path . DIRECTORY_SEPARATOR . $file)) {
require $path . DIRECTORY_SEPARATOR . $file;
if (!class_exists($class, false) && !interface_exists($class, false)) {
die(new \Exception('Class ' . $class . ' was not present in ' .
$path . DIRECTORY_SEPARATOR . $file .
'") [PEAR2_Autoload-0.2.3]'));
}
return true;
}
}
$e = new \Exception('Class ' . $class . ' could not be loaded from ' .
$file . ', file does not exist (registered paths="' .
implode(PATH_SEPARATOR, self::$paths) .
'") [PEAR2_Autoload-0.2.3]');
$trace = $e->getTrace();
if (isset($trace[2]) && isset($trace[2]['function']) &&
in_array($trace[2]['function'], array('class_exists', 'interface_exists'))) {
return false;
}
if (isset($trace[1]) && isset($trace[1]['function']) &&
in_array($trace[1]['function'], array('class_exists', 'interface_exists'))) {
return false;
}
die ((string) $e);
}
/**
* return the array of paths PEAR2 autoload has registered
*
* @return array
*/
static function getPaths()
{
return self::$paths;
}
}
}
Autoload::initialize(dirname(__DIR__));EOF
