SimpleKeyCacheInputStream.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. *
  12. * @author Chris Corbyn
  13. */
  14. class Swift_KeyCache_SimpleKeyCacheInputStream implements Swift_KeyCache_KeyCacheInputStream
  15. {
  16. /** The KeyCache being written to */
  17. private $_keyCache;
  18. /** The nsKey of the KeyCache being written to */
  19. private $_nsKey;
  20. /** The itemKey of the KeyCache being written to */
  21. private $_itemKey;
  22. /** A stream to write through on each write() */
  23. private $_writeThrough = null;
  24. /**
  25. * Set the KeyCache to wrap.
  26. *
  27. * @param Swift_KeyCache $keyCache
  28. */
  29. public function setKeyCache(Swift_KeyCache $keyCache)
  30. {
  31. $this->_keyCache = $keyCache;
  32. }
  33. /**
  34. * Specify a stream to write through for each write().
  35. *
  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. *
  45. * @param string $bytes
  46. * @param Swift_InputByteStream $is optional
  47. */
  48. public function write($bytes, Swift_InputByteStream $is = null)
  49. {
  50. $this->_keyCache->setString(
  51. $this->_nsKey, $this->_itemKey, $bytes, Swift_KeyCache::MODE_APPEND
  52. );
  53. if (isset($is)) {
  54. $is->write($bytes);
  55. }
  56. if (isset($this->_writeThrough)) {
  57. $this->_writeThrough->write($bytes);
  58. }
  59. }
  60. /**
  61. * Not used.
  62. */
  63. public function commit()
  64. {
  65. }
  66. /**
  67. * Not used.
  68. */
  69. public function bind(Swift_InputByteStream $is)
  70. {
  71. }
  72. /**
  73. * Not used.
  74. */
  75. public function unbind(Swift_InputByteStream $is)
  76. {
  77. }
  78. /**
  79. * Flush the contents of the stream (empty it) and set the internal pointer
  80. * to the beginning.
  81. */
  82. public function flushBuffers()
  83. {
  84. $this->_keyCache->clearKey($this->_nsKey, $this->_itemKey);
  85. }
  86. /**
  87. * Set the nsKey which will be written to.
  88. *
  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. *
  98. * @param string $itemKey
  99. */
  100. public function setItemKey($itemKey)
  101. {
  102. $this->_itemKey = $itemKey;
  103. }
  104. /**
  105. * Any implementation should be cloneable, allowing the clone to access a
  106. * separate $nsKey and $itemKey.
  107. */
  108. public function __clone()
  109. {
  110. $this->_writeThrough = null;
  111. }
  112. }