SimpleKeyCacheInputStream.php 2.5KB

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