class Ext_Wrapper { |
//存放模板文件内容的静态成员变量 |
protected static $_fileArr = array (); |
protected $_pos ; |
protected $_curFile ; |
public function stream_open( $path , $mode , $options , & $opened_path ) { |
$path = substr ( $path , 5, strlen ( $path ) - 5); |
//判断模板文件是否已经在变量中,不存在就读取 |
if (!isset(self:: $_fileArr [ $path ])) { |
self:: $_fileArr [ $path ] = file_get_contents ( $path ); |
} |
$this ->_curFile = $path ; |
$this ->_pos = 0; |
return true; |
} |
public function stream_read( $count ) { |
//直接从静态变量中读数据 |
$content = self:: $_fileArr [ $this ->_curFile]; |
$ret = substr ( $content , $this ->_pos, $count ); |
$this ->_pos += strlen ( $ret ); |
return $ret ; |
} |
//其他方法略 |
} |
//注册wrapper |
stream_register_wrapper( 'mem' , 'Ext_Wrapper' ); |