PEAR2_Exception › PEAR2_Exception-0.2.0/php/PEAR2/Autoload.php
- PEAR2_Exception-0.2.0/
- php/
- PEAR2/
- php/
- 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
119
120
121
<?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 include path
*
* @return void
*/
protected static function addPath($path)
{
if (!in_array($path, self::$paths)) {
$paths = explode(PATH_SEPARATOR, get_include_path());
if (!in_array($path, $paths)) {
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
}
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';
$fp = @fopen($file, 'r', true);
if ($fp) {
fclose($fp);
require $file;
if (!class_exists($class, false) && !interface_exists($class, false)) {
die(new \Exception('Class ' . $class . ' was not present in ' .
$file . ' (include_path="' . get_include_path() .
'") [PEAR2_Autoload version 1.1]'));
}
return true;
}
$e = new \Exception('Class ' . $class . ' could not be loaded from ' .
$file . ', file does not exist (include_path="' . get_include_path() .
'") [PEAR2_Autoload version 1.1]');
$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
