SimpleKeyCacheInputStream.php 2.8KB

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. *
  12. * @package Swift
  13. * @subpackage KeyCache
  14. * @author Chris Corbyn
  15. */
  16. class Swift_KeyCache_SimpleKeyCacheInputStream 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. *
  29. * @param Swift_KeyCache $keyCache
  30. */
  31. public function setKeyCache(Swift_KeyCache $keyCache)
  32. {
  33. $this->_keyCache = $keyCache;
  34. }
  35. /**
  36. * Specify a stream to write through for each write().
  37. *
  38. * @param Swift_InputByteStream $is
  39. */
  40. public function setWriteThroughStream(Swift_InputByteStream $is)
  41. {
  42. $this->_writeThrough = $is;
  43. }
  44. /**
  45. * Writes $bytes to the end of the stream.
  46. *
  47. * @param string $bytes
  48. * @param Swift_InputByteStream $is optional
  49. */
  50. public function write($bytes, Swift_InputByteStream $is = null)
  51. {
  52. $this->_keyCache->setString(
  53. $this->_nsKey, $this->_itemKey, $bytes, Swift_KeyCache::MODE_APPEND
  54. );
  55. if (isset($is)) {
  56. $is->write($bytes);
  57. }
  58. if (isset($this->_writeThrough)) {
  59. $this->_writeThrough->write($bytes);
  60. }
  61. }
  62. /**
  63. * Not used.
  64. */
  65. public function commit()
  66. {
  67. }
  68. /**
  69. * Not used.
  70. */
  71. public function bind(Swift_InputByteStream $is)
  72. {
  73. }
  74. /**
  75. * Not used.
  76. */
  77. public function unbind(Swift_InputByteStream $is)
  78. {
  79. }
  80. /**
  81. * Flush the contents of the stream (empty it) and set the internal pointer
  82. * to the beginning.
  83. */
  84. public function flushBuffers()
  85. {
  86. $this->_keyCache->clearKey($this->_nsKey, $this->_itemKey);
  87. }
  88. /**
  89. * Set the nsKey which will be written to.
  90. *
  91. * @param string $nsKey
  92. */
  93. public function setNsKey($nsKey)
  94. {
  95. $this->_nsKey = $nsKey;
  96. }
  97. /**
  98. * Set the itemKey which will be written to.
  99. *
  100. * @param string $itemKey
  101. */
  102. public function setItemKey($itemKey)
  103. {
  104. $this->_itemKey = $itemKey;
  105. }
  106. /**
  107. * Any implementation should be cloneable, allowing the clone to access a
  108. * separate $nsKey and $itemKey.
  109. */
  110. public function __clone()
  111. {
  112. $this->_writeThrough = null;
  113. }
  114. }