From c8cd14def574dc90b2164e545aae6c18e12aa4ef Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 5 Feb 2014 00:12:40 -0700 Subject: [PATCH] Use Horde_Stream methods to access stream, when possible --- .../Imap_Client/lib/Horde/Imap/Client/Ids.php | 4 ++-- .../lib/Horde/Imap/Client/Tokenize.php | 23 +++++++++++-------- framework/Imap_Client/package.xml | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Ids.php b/framework/Imap_Client/lib/Horde/Imap/Client/Ids.php index 25d204848ec..26b2ff2c6cc 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Ids.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Ids.php @@ -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; } diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php b/framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php index c7371a8905a..4c13ce392f2 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Tokenize.php @@ -78,7 +78,7 @@ public function __get($name) { switch ($name) { case 'eos': - return feof($this->_stream->stream); + return $this->_stream->eof(); } } @@ -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; } @@ -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; } @@ -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); @@ -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; @@ -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 = ''; @@ -264,7 +266,7 @@ protected function _parseStream() case ')': if (strlen($text)) { - fseek($stream, -1, SEEK_CUR); + $this->_stream->seek(-1); break 3; } --$this->_level; @@ -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)) { diff --git a/framework/Imap_Client/package.xml b/framework/Imap_Client/package.xml index 48549cd533d..55e291cd65d 100644 --- a/framework/Imap_Client/package.xml +++ b/framework/Imap_Client/package.xml @@ -301,7 +301,7 @@ Horde_Stream pear.horde.org - 1.0.0 + 1.4.0 2.0.0alpha1 2.0.0alpha1