MimeBodyString.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Gdata
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * A wrapper for strings for buffered reading.
  23. *
  24. * @category Zend
  25. * @package Zend_Gdata_MimeBodyString
  26. * @subpackage Gdata
  27. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. class Zend_Gdata_MimeBodyString
  31. {
  32. /**
  33. * The source string.
  34. *
  35. * @var string
  36. */
  37. protected $_sourceString = '';
  38. /**
  39. * The size of the MIME message.
  40. * @var integer
  41. */
  42. protected $_bytesRead = 0;
  43. /**
  44. * Create a new MimeBodyString object.
  45. *
  46. * @param string $sourceString The string we are wrapping.
  47. */
  48. public function __construct($sourceString)
  49. {
  50. $this->_sourceString = $sourceString;
  51. $this->_bytesRead = 0;
  52. }
  53. /**
  54. * Read the next chunk of the string.
  55. *
  56. * @param integer $bytesRequested The size of the chunk that is to be read.
  57. * @return string A corresponding piece of the string.
  58. */
  59. public function read($bytesRequested)
  60. {
  61. $len = strlen($this->_sourceString);
  62. if($this->_bytesRead == $len) {
  63. return FALSE;
  64. } else if($bytesRequested > $len - $this->_bytesRead) {
  65. $bytesRequested = $len - $this->_bytesRead;
  66. }
  67. $buffer = substr($this->_sourceString, $this->_bytesRead, $bytesRequested);
  68. $this->_bytesRead += $bytesRequested;
  69. return $buffer;
  70. }
  71. /**
  72. * The length of the string.
  73. *
  74. * @return int The length of the string contained in the object.
  75. */
  76. public function getSize()
  77. {
  78. return strlen($this->_sourceString);
  79. }
  80. }