class StreamDocument implements Documenttable{ protected $resource; protected $buffer;
public function __construct($resource,$buffer = 4096) { $this->resource=$resource; $this->buffer=$buffer; }
public functiongetId(){
return'resource-' .(int)$this->resource; }
public functiongetContent(){ $streamContent = ''; rewind($this->resource); while (feof($this->resource) === false){ $streamContent .= fread($this->resource,$this->buffer); } return$streamContent; } }
下面一个类是获取终端命令行的执行结果。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class CommandOutDocument implements Documenttable{ protected $command; public function __construct($command) { $this->command=$command; } public functiongetId(){ return$this->command; }
public functiongetContent(){ return shell_exec($this->command); }