我从这个thread获得一个代码,讨论使用php流阻止DWOO但我无法理解如何使用这段代码。谁能告诉我如何使用它?
最近的问题:
由于在cache / dwoo / compiled文件夹中创建了大量缓存文件,因此我的Web托管存储存在严重问题。我使用codeigniter框架开发了我的网站。我想禁用此功能(在cache / dwoo / compiled文件夹中自动创建缓存文件),因为它在我的存储上占用了大量空间。
这是代码:
include 'lib/dwooAutoload.php';
include 'Dwoo/Compiler.php';
$dwoo = new Dwoo();
stream_wrapper_register('dwoomem', 'Dwoo_Template_Memory_StreamWrapper');
$dwoo->addResource('memory', 'Dwoo_Template_Memory');
$tpl = new Dwoo_Template_Memory('test.html');
$dwoo->output($tpl, array('foo'=>'FOO', 'bar'=>'BAR'));
class Dwoo_Template_Memory extends Dwoo_Template_File
{
protected $chmod = null;
public function getCompiledFilename(Dwoo $dwoo) {
// no compile id was provided, set default
if ($this->compileId===null) {
$this->compileId = $this->getResourceIdentifier();
}
return 'dwoomem://'.$this->compileId;
}
protected function makeDirectory($path)
{
}
}
class Dwoo_Template_Memory_StreamWrapper
{
protected static $streams = array();
function stream_open($path, $mode, $options, &$opened_path)
{
if (!isset(self::$streams[$path])) {
if(!($mem = fopen('php://memory', 'w+'))) {
return false;
}
self::$streams[$path] = $mem;
}
$this->res = self::$streams[$path];
$this->stream_seek(0);
return true;
}
function stream_read($count)
{
return fread($this->res, $count);
}
function stream_write($data)
{
return fwrite($this->res, $data);
}
function stream_eof()
{
return feof($this->res);
}
function stream_seek($offset, $whence=SEEK_SET)
{
return fseek($this->res, $offset, $whence);
}
function stream_stat()
{
return fstat($this->res);
}
public static function url_stat($path, $flags)
{
return array();
}
}