Stream.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. */
  20. /**
  21. * @see Zend_Pdf
  22. */
  23. require_once 'Zend/Pdf.php';
  24. /**
  25. * @see Zend_Pdf_Element
  26. */
  27. require_once 'Zend/Pdf/Element.php';
  28. /**
  29. * @see Zend_Memory
  30. */
  31. require_once 'Zend/Memory.php';
  32. /**
  33. * PDF file 'stream' element implementation
  34. *
  35. * @category Zend
  36. * @package Zend_Pdf
  37. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  38. * @license http://framework.zend.com/license/new-bsd New BSD License
  39. */
  40. class Zend_Pdf_Element_Stream extends Zend_Pdf_Element
  41. {
  42. /**
  43. * Object value
  44. *
  45. * @var Zend_Memory_Container
  46. */
  47. public $value;
  48. /**
  49. * Object constructor
  50. *
  51. * @param string $val
  52. */
  53. public function __construct($val)
  54. {
  55. $this->value = Zend_Pdf::getMemoryManager()->create($val);
  56. }
  57. /**
  58. * Return type of the element.
  59. *
  60. * @return integer
  61. */
  62. public function getType()
  63. {
  64. return Zend_Pdf_Element::TYPE_STREAM;
  65. }
  66. /**
  67. * Stream length.
  68. * (Method is used to avoid string copying, which may occurs in some cases)
  69. *
  70. * @return integer
  71. */
  72. public function length()
  73. {
  74. return strlen($this->value->getRef());
  75. }
  76. /**
  77. * Clear stream
  78. *
  79. */
  80. public function clear()
  81. {
  82. $ref = &$this->value->getRef();
  83. $ref = '';
  84. $this->value->touch();
  85. }
  86. /**
  87. * Append value to a stream
  88. *
  89. * @param mixed $val
  90. */
  91. public function append($val)
  92. {
  93. $ref = &$this->value->getRef();
  94. $ref .= (string)$val;
  95. $this->value->touch();
  96. }
  97. /**
  98. * Return object as string
  99. *
  100. * @param Zend_Pdf_Factory $factory
  101. * @return string
  102. */
  103. public function toString($factory = null)
  104. {
  105. return "stream\n" . $this->value->getRef() . "\nendstream";
  106. }
  107. }