Skip to content

Commit

Permalink
Move stream back to public method
Browse files Browse the repository at this point in the history
Undeprecate.  This is the only way to add things such as filters to the
underlying stream.  Horde_Stream, but its description, is meant to be a
utility method to help with accessing a stream, but its methods are not
the exclusive method.
  • Loading branch information
slusarz committed Jan 30, 2014
1 parent d9a2b4b commit aad0a0e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
52 changes: 23 additions & 29 deletions framework/Stream/lib/Horde/Stream.php
Expand Up @@ -21,27 +21,24 @@
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package Stream
*
* @property-read resource $stream Stream resource (@deprecated).
* @property boolean $utf8_char Parse character as UTF-8 data instead of
* single byte (@since 1.4.0).
*/
class Horde_Stream implements Serializable
{
/**
* Configuration parameters.
* Stream resource.
*
* @var array
* @var resource
*/
protected $_params;
public $stream;

/**
* Stream resource.
*
* @deprecated Will be removed in 2.0.0
* Configuration parameters.
*
* @var resource
* @var array
*/
protected $_stream;
protected $_params;

/**
* Parse character as UTF-8 data instead of single byte.
Expand All @@ -67,8 +64,8 @@ public function __construct(array $opts = array())
protected function _init()
{
// Sane default: read-write, 0-length stream.
if (!$this->_stream) {
$this->_stream = @fopen('php://temp', 'r+');
if (!$this->stream) {
$this->stream = @fopen('php://temp', 'r+');
}
}

Expand All @@ -77,9 +74,6 @@ protected function _init()
public function __get($name)
{
switch ($name) {
case 'stream':
return $this->_stream;

case 'utf8_char':
return $this->_utf8_char;
}
Expand All @@ -101,7 +95,7 @@ public function __set($name, $value)
public function __clone()
{
$data = strval($this);
$this->_stream = null;
$this->stream = null;
$this->_init();
$this->add($data);
}
Expand Down Expand Up @@ -146,7 +140,7 @@ public function add($data, $reset = false)
}
$data->seek($dpos, false);
} else {
fwrite($this->_stream, $data);
fwrite($this->stream, $data);
}

if ($reset) {
Expand Down Expand Up @@ -282,7 +276,7 @@ public function search($char, $reverse = false, $reset = true)
* getChar() a bunch of times. */
$fgetc = ($single_char && !$this->_utf8_char);

while (($c = ($fgetc ? fgetc($this->_stream) : $this->getChar())) !== false) {
while (($c = ($fgetc ? fgetc($this->stream) : $this->getChar())) !== false) {
if ($c == ($single_char ? $char : substr($char, 0, strlen($c)))) {
$found_pos = $this->pos() - ($single_char ? 1 : strlen($c));
break;
Expand Down Expand Up @@ -393,8 +387,8 @@ public function substring($start = 0, $length = null, $char = false)
}
}

while (!feof($this->_stream) && ($to_end || $length)) {
$read = fread($this->_stream, $to_end ? 16384 : $length);
while (!feof($this->stream) && ($to_end || $length)) {
$read = fread($this->stream, $to_end ? 16384 : $length);
$out .= $read;
if (!$to_end) {
$length -= strlen($read);
Expand Down Expand Up @@ -443,7 +437,7 @@ public function getEOL()
*/
public function getChar()
{
$char = fgetc($this->_stream);
$char = fgetc($this->stream);
if (!$this->_utf8_char) {
return $char;
}
Expand All @@ -464,7 +458,7 @@ public function getChar()
}

for ($i = 0; $i < $n; ++$i) {
if (($c = fgetc($this->_stream)) === false) {
if (($c = fgetc($this->stream)) === false) {
throw new Horde_Stream_Exception('ERROR');
}
$char .= $c;
Expand All @@ -482,7 +476,7 @@ public function getChar()
*/
public function pos()
{
return ftell($this->_stream);
return ftell($this->stream);
}

/**
Expand All @@ -494,7 +488,7 @@ public function pos()
*/
public function rewind()
{
return rewind($this->_stream);
return rewind($this->stream);
}

/**
Expand Down Expand Up @@ -538,7 +532,7 @@ public function seek($offset = 0, $curr = true, $char = false)
$offset = abs($offset);

while ($pos-- && $offset) {
fseek($this->_stream, -1, SEEK_CUR);
fseek($this->stream, -1, SEEK_CUR);
if ((ord($this->peek()) & 0xC0) != 0x80) {
--$offset;
}
Expand All @@ -548,7 +542,7 @@ public function seek($offset = 0, $curr = true, $char = false)
return true;
}

return (fseek($this->_stream, $offset, $curr ? SEEK_CUR : SEEK_SET) === 0);
return (fseek($this->stream, $offset, $curr ? SEEK_CUR : SEEK_SET) === 0);
}

/**
Expand All @@ -562,7 +556,7 @@ public function seek($offset = 0, $curr = true, $char = false)
*/
public function end($offset = 0)
{
return (fseek($this->_stream, $offset, SEEK_END) === 0);
return (fseek($this->stream, $offset, SEEK_END) === 0);
}

/**
Expand All @@ -574,7 +568,7 @@ public function end($offset = 0)
*/
public function eof()
{
return feof($this->_stream);
return feof($this->stream);
}

/**
Expand All @@ -584,8 +578,8 @@ public function eof()
*/
public function close()
{
if ($this->_stream) {
fclose($this->_stream);
if ($this->stream) {
fclose($this->stream);
}
}

Expand Down
2 changes: 1 addition & 1 deletion framework/Stream/lib/Horde/Stream/Existing.php
Expand Up @@ -39,7 +39,7 @@ public function __construct(array $opts = array())
throw new Horde_Stream_Exception('Need a stream resource.');
}

$this->_stream = $opts['stream'];
$this->stream = $opts['stream'];
unset($opts['stream']);

parent::__construct($opts);
Expand Down
2 changes: 1 addition & 1 deletion framework/Stream/lib/Horde/Stream/Temp.php
Expand Up @@ -48,7 +48,7 @@ protected function _init()
$cmd .= '/maxmemory:' . intval($this->_params['max_memory']);
}

if (($this->_stream = @fopen($cmd, 'r+')) === false) {
if (($this->stream = @fopen($cmd, 'r+')) === false) {
throw new Horde_Stream_Exception('Failed to open temporary memory stream.');
}
}
Expand Down

0 comments on commit aad0a0e

Please sign in to comment.