|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of phpspider. |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under The MIT License |
|
6
|
|
|
* For full copyright and license information, please see the MIT-LICENSE.txt |
|
7
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
8
|
|
|
* |
|
9
|
|
|
* @author seatle<[email protected]> |
|
10
|
|
|
* @copyright seatle<[email protected]> |
|
11
|
|
|
* @link http://www.phpspider.org/ |
|
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
|
13
|
|
|
*/ |
|
14
|
|
|
namespace phpspider; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* autoloader. |
|
18
|
|
|
*/ |
|
19
|
|
|
class autoloader |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Autoload root path. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected static $_autoload_root_path = ''; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Set autoload root path. |
|
30
|
|
|
* |
|
31
|
|
|
* @param string $root_path |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function set_root_path($root_path) |
|
35
|
|
|
{ |
|
36
|
|
|
self::$_autoload_root_path = $root_path; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Load files by namespace. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $name |
|
43
|
|
|
* @return boolean |
|
44
|
|
|
*/ |
|
45
|
|
|
public static function load_by_namespace($name) |
|
46
|
|
|
{ |
|
47
|
|
|
$class_path = str_replace('\\', DIRECTORY_SEPARATOR, $name); |
|
48
|
|
|
|
|
49
|
|
|
if (strpos($name, 'phpspider\\') === 0) |
|
50
|
|
|
{ |
|
51
|
|
|
$class_file = __DIR__ . substr($class_path, strlen('phpspider')) . '.php'; |
|
52
|
|
|
} |
|
53
|
|
|
else |
|
54
|
|
|
{ |
|
55
|
|
|
if (self::$_autoload_root_path) |
|
56
|
|
|
{ |
|
57
|
|
|
$class_file = self::$_autoload_root_path . DIRECTORY_SEPARATOR . $class_path . '.php'; |
|
58
|
|
|
} |
|
59
|
|
|
if (empty($class_file) || !is_file($class_file)) |
|
60
|
|
|
{ |
|
61
|
|
|
$class_file = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . "$class_path.php"; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if (is_file($class_file)) |
|
66
|
|
|
{ |
|
67
|
|
|
require_once($class_file); |
|
68
|
|
|
if (class_exists($name, false)) |
|
69
|
|
|
{ |
|
70
|
|
|
return true; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
spl_autoload_register('\phpspider\autoloader::load_by_namespace'); |
|
78
|
|
|
|