Skip to content

Commit

Permalink
Use Horde_Stream methods to access stream, when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 5, 2014
1 parent ff058c5 commit c8cd14d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions framework/Imap_Client/lib/Horde/Imap/Client/Ids.php
Expand Up @@ -236,8 +236,8 @@ public function split($length)
$out = array();

do {
$out[] = stream_get_contents($id->stream, $length) . $id->getToChar(',');
} while (!feof($id->stream));
$out[] = $id->substring(0, $length) . $id->getToChar(',');
} while (!$id->eof());

return $out;
}
Expand Down
23 changes: 14 additions & 9 deletions framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php
Expand Up @@ -78,7 +78,7 @@ public function __get($name)
{
switch ($name) {
case 'eos':
return feof($this->_stream->stream);
return $this->_stream->eof();
}
}

Expand All @@ -93,9 +93,9 @@ public function __sleep()
*/
public function __toString()
{
$pos = ftell($this->_stream->stream);
$pos = $this->_stream->pos();
$out = $this->_current . ' ' . $this->_stream->getString();
fseek($this->_stream->stream, $pos);
$this->_stream->seek($pos, false);
return $out;
}

Expand Down Expand Up @@ -141,8 +141,8 @@ public function flushIterator($return = true, $sublevel = true)
$this->next();
}
} else {
fseek($this->_stream->stream, 0, SEEK_END);
fgetc($this->_stream->stream);
$this->_stream->end();
$this->_stream->getChar();
$this->_current = $this->_key = $this->_level = false;
}

Expand All @@ -159,7 +159,7 @@ public function flushIterator($return = true, $sublevel = true)
*/
public function getLiteralLength()
{
fseek($this->_stream->stream, -1, SEEK_END);
$this->_stream->end(-1);
if ($this->_stream->peek() === '}') {
$literal_data = $this->_stream->getString($this->_stream->search('{', true) - 1);
$literal_len = substr($literal_data, 2, -1);
Expand Down Expand Up @@ -211,7 +211,7 @@ public function next()
*/
public function rewind()
{
fseek($this->_stream->stream, 0);
$this->_stream->rewind();
$this->_current = false;
$this->_key = -1;
$this->_level = 0;
Expand All @@ -232,6 +232,8 @@ public function valid()
protected function _parseStream()
{
$in_quote = false;
/* Directly access stream here to drastically reduce the number of
* getChar() calls we would have to make. */
$stream = $this->_stream->stream;
$text = '';

Expand Down Expand Up @@ -264,7 +266,7 @@ protected function _parseStream()

case ')':
if (strlen($text)) {
fseek($stream, -1, SEEK_CUR);
$this->_stream->seek(-1);
break 3;
}
--$this->_level;
Expand All @@ -276,7 +278,10 @@ protected function _parseStream()
break;

case '{':
return stream_get_contents($stream, $this->_stream->getToChar('}'));
return $this->_stream->substring(
0,
intval($this->_stream->getToChar('}'))
);

case ' ':
if (strlen($text)) {
Expand Down
2 changes: 1 addition & 1 deletion framework/Imap_Client/package.xml
Expand Up @@ -301,7 +301,7 @@
<package>
<name>Horde_Stream</name>
<channel>pear.horde.org</channel>
<min>1.0.0</min>
<min>1.4.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
</package>
Expand Down

0 comments on commit c8cd14d

Please sign in to comment.