3
class IOFilter extends FILTER implements STREAMObjectInterface {
15
function __construct(&$info = NULL, STREAMWriterInterface $output = NULL, $sink = NULL, $outlet = 0, $flags = 0) {
16
parent::__construct($info, $output);
18
$this->extra_data = false;
20
$this->CreateFilter($sink, $outlet);
22
if ($flags&STREAM::GIFT) $this->resource_close = true;
23
else $this->resource_close = false;
28
- NULL : create standard
29
- resourse : create standard and initialize
30
- WriterI : use writer interface
31
- #number : dublicate sink
35
function CreateFilter($sink = NULL, $outlet = 0) {
39
if (is_resource($sink)) {
40
$this->sink = new IO($sink, is_int($outlet));
41
$this->sink_open = true;
42
} elseif ($sink instanceof STREAMWriterInterface) {
44
$this->sink_open = false;
46
throw new ADEIException(translate("Unsupported sink is supplied for the FILTER"));
48
$this->sink = new IO($NULL=NULL, is_int($outlet));
49
$this->sink_open = true;
52
if ($outlet === false) {
53
$this->outlet = false;
54
$this->outlet_open = false;
55
$this->filewriter = true;
56
$this->copymode = false;
57
} elseif (is_int($outlet)) {
58
$this->outlet = $this->sink;
59
$this->outlet_open = false;
60
$this->filewriter = false;
61
$this->copymode = true;
62
} elseif (is_resource($args[0])) {
63
$this->outlet = new IO($outlet, true);
64
$this->outlet_open = true;
65
$this->filewriter = false;
66
$this->copymode = false;
67
} elseif ($outlet instanceof STREAMWriterInterface) {
68
$this->outlet = $outlet;
69
$this->outlet_open = false;
70
$this->filewriter = false;
71
$this->copymode = false;
73
throw new ADEIException(translate("Unsupported outlet is supplied for the FILTER"));
75
$this->outlet = new IO($NULL=NULL, true);
76
$this->outlet_open = true;
77
$this->filewriter = false;
78
$this->copymode = false;
82
function OpenPipes(&$pipes) {
83
if ($this->sink_open) {
84
$this->sink->Open($pipes[0], $flags);
86
if ($this->outlet_open) {
87
$this->outlet->Open($pipes[1], $flags);
91
function ClosePipes(STREAMWriterInterface $h = NULL) {
92
if ($this->output) $h = $this->output;
94
// if outlet is copy of sink, we have outlet_open false
95
if ($this->sink_open) {
99
if ($this->outlet_open) {
100
return $this->outlet->Close($h);
104
function Open(&$args = NULL, &$pipes = NULL, $flags = 0) {
108
$this->OpenPipes($pipes, $flags);
109
$this->block_mode = false;
110
} else $this->block_mode = true;
113
function BlockStart(&$args = NULL, &$pipes = NULL, $flags = 0) {
114
if ($this->block_mode) {
116
$this->OpenPipes($pipes, $flags);
118
throw new ADEIException(translate("The actual pipes are not supplied IOFilter"));
122
function BlockEnd(STREAMWriterInterface $h = NULL) {
123
if ($this->block_mode) {
124
return $this->ClosePipes($h);
128
function Close(STREAMWriterInterface $h = NULL) {
129
if (!$this->block_mode) {
130
$res = $this->ClosePipes($h);
131
if ($res) return $res . parent::Close($h);
133
return parent::Close($h);
136
function WriteData(&$data, $flags = 0) {
137
$this->sink->Write($data);
140
function ReadData($limit = 0, $flags = 0) {
143
return new ADEIException(translate("The filter have STREAMWriter configured in. Therethore read requests are not permited"));
145
if ($this->extra_data) {
146
$res = $this->extra_data . $this->outlet->ReadData($limit, $flags);
147
$this->extra_data = false;
150
return $this->outlet->ReadData($limit, $flags);
152
throw new ADEIException(translate("The filter outlet is not configured"));
155
function StreamData(STREAMWriterInterface $h = NULL, $flags = 0) {
157
if ($this->output) $h = $this->output;
158
else if (!$h) throw new ADEIException(translate("The data routing is failed (there is no output specified for FILTER)"));
160
if ($this->extra_data) {
161
$h->WriteData($this->extra_data);
162
$this->extra_data = false;
164
$this->outlet->StreamData($h, $flags);
166
throw new ADEIException(translate("The filter outlet is not configured"));
171
if ($this->extra_data) return false;
172
return $this->outlet->EOS();
174
throw new ADEIException(translate("The filter outlet is not configured"));
b'\\ No newline at end of file'