chengkun
2025-04-30 6ab292fb7415be124651e312ec4f21c594568f17
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
<?php
 
/**
 * Created by PhpStorm.
 * User: sunyaoyao
 * Date: 2016/1/7
 * Time: 17:20
 * 自动加载类库
 */
class Autoloader
{
    /**
     * @param string $class 对象类名
     * @return void
     */
    public static function autoload($class)
    {
        $name = $class;
        if (false !== strpos($name, '\\')) {
            $name = strstr($class, '\\', true);
        }
 
        $searchDirectoryList = array();
        $searchDirectoryList[] = 'nuomiopenplatform';
        $searchDirectoryList[] = 'nuomiopenplatform/requests';
        $searchDirectoryList[] = 'nuomiopenplatform/library';
        $searchDirectoryList[] = 'nuomiopenplatform/library/request';
        $searchDirectoryList[] = 'nuomiopenplatform/library/sign';
 
 
        foreach($searchDirectoryList as $dir){
 
            /**
             * 兼容性判断,没有办法使用__DIR__这个魔术变量在PHP5.3版本之前,要用dirname(__FILE__)替代
             */
 
            $filename =  sprintf("%s/%s/%s.php",dirname(__FILE__) , $dir,$name);
 
            if (is_file($filename)) {
                require_once $filename;
                return;
            }
        }
    }
 
}
 
spl_autoload_register('Autoloader::autoload');
?>