You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.3 KiB

11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
  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_Pdf
  17. * @subpackage FileParser
  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. /** Zend_Pdf_FileParserDataSource */
  23. // require_once 'Zend/Pdf/FileParserDataSource.php';
  24. /**
  25. * Concrete subclass of {@link Zend_Pdf_FileParserDataSource} that provides an
  26. * interface to binary strings.
  27. *
  28. * @package Zend_Pdf
  29. * @subpackage FileParser
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Pdf_FileParserDataSource_String extends Zend_Pdf_FileParserDataSource
  34. {
  35. /**** Instance Variables ****/
  36. /**
  37. * The string to parse.
  38. * @var string
  39. */
  40. protected $_string = '';
  41. /**** Public Interface ****/
  42. /* Concrete Class Implementation */
  43. /**
  44. * Object constructor.
  45. *
  46. * Verifies that the string is not empty.
  47. *
  48. * @param string $string String to parse.
  49. */
  50. public function __construct($string)
  51. {
  52. if (empty($string)) {
  53. // require_once 'Zend/Pdf/Exception.php';
  54. throw new Zend_Pdf_Exception('String is empty',
  55. Zend_Pdf_Exception::PARAMETER_VALUE_OUT_OF_RANGE);
  56. }
  57. $this->_size = strlen($string);
  58. $this->_string = $string;
  59. }
  60. /**
  61. * Object destructor.
  62. */
  63. public function __destruct()
  64. {
  65. $this->_string = '';
  66. }
  67. /**
  68. * Returns the specified number of raw bytes from the string at the byte
  69. * offset of the current read position.
  70. *
  71. * Advances the read position by the number of bytes read.
  72. *
  73. * Throws an exception if there is insufficient data to completely fulfill
  74. * the request.
  75. *
  76. * @param integer $byteCount Number of bytes to read.
  77. * @return string
  78. * @throws Zend_Pdf_Exception
  79. */
  80. public function readBytes($byteCount)
  81. {
  82. if (($this->_offset + $byteCount) > $this->_size) {
  83. // require_once 'Zend/Pdf/Exception.php';
  84. throw new Zend_Pdf_Exception("Insufficient data to read $byteCount bytes",
  85. Zend_Pdf_Exception::INSUFFICIENT_DATA);
  86. }
  87. $bytes = substr($this->_string, $this->_offset, $byteCount);
  88. $this->_offset += $byteCount;
  89. return $bytes;
  90. }
  91. /**
  92. * Returns the entire string.
  93. *
  94. * Preserves the current read position.
  95. *
  96. * @return string
  97. */
  98. public function readAllBytes()
  99. {
  100. return $this->_string;
  101. }
  102. /* Object Magic Methods */
  103. /**
  104. * Returns a string containing the parsed string's length.
  105. *
  106. * @return string
  107. */
  108. public function __toString()
  109. {
  110. return "String ($this->_size bytes)";
  111. }
  112. }