1: <?php
2:
3: /*
4: * This file is part of SwiftMailer.
5: * (c) 2004-2009 Chris Corbyn
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10:
11: /**
12: * Writes data to a KeyCache using a stream.
13: * @package Swift
14: * @subpackage KeyCache
15: * @author Chris Corbyn
16: */
17: class Swift_KeyCache_SimpleKeyCacheInputStream implements Swift_KeyCache_KeyCacheInputStream
18: {
19: /** The KeyCache being written to */
20: private $_keyCache;
21:
22: /** The nsKey of the KeyCache being written to */
23: private $_nsKey;
24:
25: /** The itemKey of the KeyCache being written to */
26: private $_itemKey;
27:
28: /** A stream to write through on each write() */
29: private $_writeThrough = null;
30:
31: /**
32: * Set the KeyCache to wrap.
33: * @param Swift_KeyCache $keyCache
34: */
35: public function setKeyCache(Swift_KeyCache $keyCache)
36: {
37: $this->_keyCache = $keyCache;
38: }
39:
40: /**
41: * Specify a stream to write through for each write().
42: * @param Swift_InputByteStream $is
43: */
44: public function setWriteThroughStream(Swift_InputByteStream $is)
45: {
46: $this->_writeThrough = $is;
47: }
48:
49: /**
50: * Writes $bytes to the end of the stream.
51: * @param string $bytes
52: * @param Swift_InputByteStream $is, optional
53: */
54: public function write($bytes, Swift_InputByteStream $is = null)
55: {
56: $this->_keyCache->setString(
57: $this->_nsKey, $this->_itemKey, $bytes, Swift_KeyCache::MODE_APPEND
58: );
59: if (isset($is)) {
60: $is->write($bytes);
61: }
62: if (isset($this->_writeThrough)) {
63: $this->_writeThrough->write($bytes);
64: }
65: }
66:
67: /**
68: * Not used.
69: */
70: public function commit()
71: {
72: }
73:
74: /**
75: * Not used.
76: */
77: public function bind(Swift_InputByteStream $is)
78: {
79: }
80:
81: /**
82: * Not used.
83: */
84: public function unbind(Swift_InputByteStream $is)
85: {
86: }
87:
88: /**
89: * Flush the contents of the stream (empty it) and set the internal pointer
90: * to the beginning.
91: */
92: public function flushBuffers()
93: {
94: $this->_keyCache->clearKey($this->_nsKey, $this->_itemKey);
95: }
96:
97: /**
98: * Set the nsKey which will be written to.
99: * @param string $nsKey
100: */
101: public function setNsKey($nsKey)
102: {
103: $this->_nsKey = $nsKey;
104: }
105:
106: /**
107: * Set the itemKey which will be written to.
108: * @param string $itemKey
109: */
110: public function setItemKey($itemKey)
111: {
112: $this->_itemKey = $itemKey;
113: }
114:
115: /**
116: * Any implementation should be cloneable, allowing the clone to access a
117: * separate $nsKey and $itemKey.
118: */
119: public function __clone()
120: {
121: $this->_writeThrough = null;
122: }
123: }
124: