4 * This file is part of SwiftMailer.
5 * (c) 2004-2009 Chris Corbyn
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 //@require 'Swift/KeyCache.php';
12 //@require 'Swift/KeyCacheInputStream.php';
15 * Writes data to a KeyCache using a stream.
17 * @subpackage KeyCache
18 * @author Chris Corbyn
20 class Swift_KeyCache_SimpleKeyCacheInputStream
21 implements Swift_KeyCache_KeyCacheInputStream
24 /** The KeyCache being written to */
27 /** The nsKey of the KeyCache being written to */
30 /** The itemKey of the KeyCache being written to */
33 /** A stream to write through on each write() */
34 private $_writeThrough = null;
37 * Set the KeyCache to wrap.
38 * @param Swift_KeyCache $keyCache
40 public function setKeyCache(Swift_KeyCache
$keyCache)
42 $this->_keyCache
= $keyCache;
46 * Specify a stream to write through for each write().
47 * @param Swift_InputByteStream $is
49 public function setWriteThroughStream(Swift_InputByteStream
$is)
51 $this->_writeThrough
= $is;
55 * Writes $bytes to the end of the stream.
56 * @param string $bytes
57 * @param Swift_InputByteStream $is, optional
59 public function write($bytes, Swift_InputByteStream
$is = null)
61 $this->_keyCache
->setString(
62 $this->_nsKey
, $this->_itemKey
, $bytes, Swift_KeyCache
::MODE_APPEND
68 if (isset($this->_writeThrough
))
70 $this->_writeThrough
->write($bytes);
77 public function commit()
84 public function bind(Swift_InputByteStream
$is)
91 public function unbind(Swift_InputByteStream
$is)
96 * Flush the contents of the stream (empty it) and set the internal pointer
99 public function flushBuffers()
101 $this->_keyCache
->clearKey($this->_nsKey
, $this->_itemKey
);
105 * Set the nsKey which will be written to.
106 * @param string $nsKey
108 public function setNsKey($nsKey)
110 $this->_nsKey
= $nsKey;
114 * Set the itemKey which will be written to.
115 * @param string $itemKey
117 public function setItemKey($itemKey)
119 $this->_itemKey
= $itemKey;
123 * Any implementation should be cloneable, allowing the clone to access a
124 * separate $nsKey and $itemKey.
126 public function __clone()
128 $this->_writeThrough
= null;