Trailer.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. * @package Zend_Pdf
  16. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  17. * @license http://framework.zend.com/license/new-bsd New BSD License
  18. */
  19. /** Zend_Pdf_Element_Dictionary */
  20. require_once 'Zend/Pdf/Element/Dictionary.php';
  21. /**
  22. * PDF file trailer
  23. *
  24. * @package Zend_Pdf
  25. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  26. * @license http://framework.zend.com/license/new-bsd New BSD License
  27. */
  28. abstract class Zend_Pdf_Trailer
  29. {
  30. private static $_allowedKeys = array('Size', 'Prev', 'Root', 'Encrypt', 'Info', 'ID', 'Index', 'W', 'XRefStm', 'DocChecksum');
  31. /**
  32. * Trailer dictionary.
  33. *
  34. * @var Zend_Pdf_Element_Dictionary
  35. */
  36. private $_dict;
  37. /**
  38. * Check if key is correct
  39. *
  40. * @param string $key
  41. * @throws Zend_Pdf_Exception
  42. */
  43. private function _checkDictKey($key)
  44. {
  45. if ( !in_array($key, self::$_allowedKeys) ) {
  46. /** @todo Make warning (log entry) instead of an exception */
  47. throw new Zend_Pdf_Exception("Unknown trailer dictionary key: '$key'.");
  48. }
  49. }
  50. /**
  51. * Object constructor
  52. *
  53. * @param Zend_Pdf_Element_Dictionary $dict
  54. */
  55. public function __construct(Zend_Pdf_Element_Dictionary $dict)
  56. {
  57. $this->_dict = $dict;
  58. foreach ($this->_dict->getKeys() as $dictKey) {
  59. $this->_checkDictKey($dictKey);
  60. }
  61. }
  62. /**
  63. * Get handler
  64. *
  65. * @param string $property
  66. * @return mixed
  67. */
  68. public function __get($property)
  69. {
  70. return $this->_dict->$property;
  71. }
  72. /**
  73. * Set handler
  74. *
  75. * @param string $property
  76. * @param mixed $value
  77. */
  78. public function __set($property, $value)
  79. {
  80. $this->_checkDictKey($property);
  81. $this->_dict->$property = $value;
  82. }
  83. /**
  84. * Return string trailer representation
  85. *
  86. * @return string
  87. */
  88. public function toString()
  89. {
  90. return "trailer\n" . $this->_dict->toString() . "\n";
  91. }
  92. /**
  93. * Get length of source PDF
  94. *
  95. * @return string
  96. */
  97. abstract public function getPDFLength();
  98. /**
  99. * Get PDF String
  100. *
  101. * @return string
  102. */
  103. abstract public function getPDFString();
  104. /**
  105. * Get header of free objects list
  106. * Returns object number of last free object
  107. *
  108. * @return integer
  109. */
  110. abstract public function getLastFreeObject();
  111. }