52 $this->_replacementFactory = $replacementFactory;
62 $this->_params = $params;
63 switch ($params[
'type'])
65 case self::TYPE_PROCESS:
68 case self::TYPE_SOCKET:
82 if (isset($this->_stream))
87 if (!array_key_exists(
'protocol', $this->_params)
88 || $value != $this->_params[
'protocol'])
92 stream_socket_enable_crypto(
93 $this->_stream,
true, STREAM_CRYPTO_METHOD_TLS_CLIENT
100 $this->_params[$param] = $value;
108 if (isset($this->_stream))
110 switch ($this->_params[
'type'])
112 case self::TYPE_PROCESS:
115 proc_close($this->_stream);
117 case self::TYPE_SOCKET:
119 fclose($this->_stream);
123 $this->_stream = null;
135 foreach ($this->_translations as $search => $replace)
137 if (!isset($replacements[$search]))
140 unset($this->_translations[$search]);
144 foreach ($replacements as $search => $replace)
146 if (!isset($this->_translations[$search]))
149 $this->_replacementFactory->createFilter($search, $replace), $search
151 $this->_translations[$search] =
true;
165 if (isset($this->_out) && !feof($this->_out))
167 $line = fgets($this->_out);
182 if (isset($this->_out) && !feof($this->_out))
184 $ret = fread($this->_out, $length);
199 if (isset($this->_in))
208 if (isset($this->_in)
209 && fwrite($this->_in, $bytes))
223 $host = $this->_params[
'host'];
224 if (!empty($this->_params[
'protocol']))
226 $host = $this->_params[
'protocol'] .
'://' . $host;
229 if (!empty($this->_params[
'timeout']))
231 $timeout = $this->_params[
'timeout'];
233 if (!$this->_stream = fsockopen($host, $this->_params[
'port'], $errno, $errstr, $timeout))
236 'Connection could not be established with host ' . $this->_params[
'host'] .
237 ' [' . $errstr .
' #' . $errno .
']'
240 if (!empty($this->_params[
'blocking']))
242 stream_set_blocking($this->_stream, 1);
246 stream_set_blocking($this->_stream, 0);
258 $command = $this->_params[
'command'];
259 $descriptorSpec = array(
260 0 => array(
'pipe',
'r'),
261 1 => array(
'pipe',
'w'),
262 2 => array(
'pipe',
'w')
264 $this->_stream = proc_open($command, $descriptorSpec, $pipes);
265 stream_set_blocking($pipes[2], 0);
266 if (
$err = stream_get_contents($pipes[2]))
269 'Process could not be started [' .
$err .
']'
272 $this->_in =& $pipes[0];
273 $this->_out =& $pipes[1];