MimeBodyString.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * A wrapper for strings for buffered reading.
  24. *
  25. * @category Zend
  26. * @package Zend_Gdata
  27. * @subpackage Gdata
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_Gdata_MimeBodyString
  32. {
  33. /**
  34. * The source string.
  35. *
  36. * @var string
  37. */
  38. protected $_sourceString = '';
  39. /**
  40. * The size of the MIME message.
  41. * @var integer
  42. */
  43. protected $_bytesRead = 0;
  44. /**
  45. * Create a new MimeBodyString object.
  46. *
  47. * @param string $sourceString The string we are wrapping.
  48. */
  49. public function __construct($sourceString)
  50. {
  51. $this->_sourceString = $sourceString;
  52. $this->_bytesRead = 0;
  53. }
  54. /**
  55. * Read the next chunk of the string.
  56. *
  57. * @param integer $bytesRequested The size of the chunk that is to be read.
  58. * @return string A corresponding piece of the string.
  59. */
  60. public function read($bytesRequested)
  61. {
  62. $len = strlen($this->_sourceString);
  63. if($this->_bytesRead == $len) {
  64. return FALSE;
  65. } else if($bytesRequested > $len - $this->_bytesRead) {
  66. $bytesRequested = $len - $this->_bytesRead;
  67. }
  68. $buffer = substr($this->_sourceString, $this->_bytesRead, $bytesRequested);
  69. $this->_bytesRead += $bytesRequested;
  70. return $buffer;
  71. }
  72. /**
  73. * The length of the string.
  74. *
  75. * @return int The length of the string contained in the object.
  76. */
  77. public function getSize()
  78. {
  79. return strlen($this->_sourceString);
  80. }
  81. }