1<?php 2 3/** 4 * Swift Mailer Output stream to read bytes from cached data 5 * Please read the LICENSE file 6 * @author Chris Corbyn <chris@w3style.co.uk> 7 * @package Swift_Cache 8 * @license GNU Lesser General Public License 9 */ 10 11/** 12 * The wraps the streaming functionality of the cache 13 * @package Swift_Cache 14 * @author Chris Corbyn <chris@w3style.co.uk> 15 */ 16class Swift_Cache_OutputStream 17{ 18 /** 19 * The key to read in the actual cache 20 * @var string 21 */ 22 protected $key; 23 /** 24 * The cache object to read 25 * @var Swift_Cache 26 */ 27 protected $cache; 28 29 /** 30 * Ctor. 31 * @param Swift_Cache The cache to read from 32 * @param string The key for the cached data 33 */ 34 public function __construct(Swift_Cache $cache, $key) 35 { 36 $this->cache = $cache; 37 $this->key = $key; 38 } 39 /** 40 * Read bytes from the cache and seek through the buffer 41 * Returns false if EOF is reached 42 * @param int The number of bytes to read (could be ignored) 43 * @return string The read bytes 44 */ 45 public function read($size=null) 46 { 47 return $this->cache->read($this->key, $size); 48 } 49 /** 50 * Read the entire cached data as one string 51 * @return string 52 */ 53 public function readFull() 54 { 55 $ret = ""; 56 while (false !== $bytes = $this->read()) 57 $ret .= $bytes; 58 return $ret; 59 } 60} 61