TP框架-storage类分析

来源:互联网 发布:手机号码追踪软件 编辑:程序博客网 时间:2024/06/04 23:20

//storage这个类的主要作用:1.统一分布式文件存储类的入口  这样以后可以通过更改配置文件调整网站的文件存储方式

//2.使子类中所有的普通方法可以通过调用静态方法来访问.

namespace Think;

// 分布式文件存储类
class Storage {


    /**
     * 操作句柄
     * @var string
     * @access protected
     */
    static protected $handler    ;


    /**
     * 连接分布式文件系统
     * @access public
     * @param string $type 文件类型
     * @param array $options  配置数组
     * @return void

     */

  //这个函数在think.class.php文件中有调用

 //默认是文件存储

    static public function connect($type='File',$options=array()) {

        $class  =   'Think\\Storage\\Driver\\'.ucwords($type);

//生成的类对象赋值给操作句柄handler

        self::$handler = new $class($options);
    }

//当调用storage类不存在的静态方法时,都会进入这个函数中

//然后与call_user_func_array结合就可以实现子类的普通方法可以静态调用了

//method_exists 判断类对象中的某个方法是否存在


    static public function __callstatic($method,$args){
        //调用缓存驱动的方法
        if(method_exists(self::$handler, $method)){
           return call_user_func_array(array(self::$handler,$method), $args);
        }
    }
}
0 0