1

我从这个线程得到一个代码,它谈论使用 php 流阻止 DWOO,但我不明白如何使用这个代码。谁能告诉我如何使用它?

最近的问题:
由于在 cache/dwoo/compiled 文件夹中创建了很多缓存文件,我在网络托管上的存储存在严重问题。我使用 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();
    }
}
4

0 回答 0