Autoloader.php
1.45 KB
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
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 13-12-31
* Time: 7:12
*/
namespace Q;
class Q_Autoloader
{
public function __construct()
{
spl_autoload_register(array($this, 'register'));
}
private function register($className)
{
if (stristr($className, '\\') === FALSE) {
$classNamePath = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
} else {
$parts = explode('\\', $className);
$classNamePath = implode(DIRECTORY_SEPARATOR, $parts) . '.php';
}
$includePath = explode(':', get_include_path());
foreach ($includePath as $path) {
$classPath = $path . DIRECTORY_SEPARATOR . $classNamePath;
if (file_exists($classPath)) {
//Yaf_Loader::import($classPath);
require_once($classPath);
return;
}
}
}
public function tree($directory)
{
$mydir = dir($directory);
while ($file = $mydir->read()) {
if ((is_dir($directory . DIRECTORY_SEPARATOR . $file)) AND ($file != ".") AND ($file != "..")) {
$this->tree("$directory/$file");
} elseif ($file != "." AND $file != "..") {
echo $directory . DIRECTORY_SEPARATOR . $file;
}
}
$mydir->close();
}
public static function loader()
{
new Q_Autoloader();
}
}
Q_Autoloader::loader();