Stream.php 2.5 KB

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