File size: 768 Bytes
0d5b03e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

/**

 *

 * 自动载入函数

 */
class Autoloader

{
    /**

     * 向PHP注册在自动载入函数

     */
    public static function register()

    {
        spl_autoload_register(array(new self, 'autoload'));
    }

    /**

     * 根据类名载入所在文件

     */
    public static function autoload($className)

    {

        // DIRECTORY_SEPARATOR:目录分隔符,linux上就是’/’    windows上是’\’
        $filePath = __DIR__ . DIRECTORY_SEPARATOR . $className;
        $filePath = str_replace('\\', DIRECTORY_SEPARATOR, $filePath) . '.php';
        if (file_exists($filePath)) {
            require_once $filePath;
            return true;
        } else {
            return false;
        }
    }
}