GoTo.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 Actions
  18. * @copyright Copyright (c) 2005-2009 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_Action */
  23. require_once 'Zend/Pdf/Action.php';
  24. /** Zend_Pdf_Destination */
  25. require_once 'Zend/Pdf/Destination.php';
  26. /**
  27. * PDF 'Go to' action
  28. *
  29. * @package Zend_Pdf
  30. * @subpackage Actions
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Pdf_Action_GoTo extends Zend_Pdf_Action
  35. {
  36. /**
  37. * GoTo Action destination
  38. *
  39. * @var Zend_Pdf_Destination
  40. */
  41. protected $_destination;
  42. /**
  43. * Object constructor
  44. *
  45. * @param Zend_Pdf_Element_Dictionary $dictionary
  46. * @param SplObjectStorage $processedActions list of already processed action dictionaries, used to avoid cyclic references
  47. * @throws Zend_Pdf_Exception
  48. */
  49. public function __construct(Zend_Pdf_Element $dictionary, SplObjectStorage $processedActions)
  50. {
  51. parent::__construct($dictionary, $processedActions);
  52. $this->_destination = Zend_Pdf_Destination::load($dictionary->D);
  53. }
  54. /**
  55. * Create new Zend_Pdf_Action_GoTo object using specified destination
  56. *
  57. * @param Zend_Pdf_Destination|string $destination
  58. * @return Zend_Pdf_Action_GoTo
  59. */
  60. public static function create($destination)
  61. {
  62. if (is_string($destination)) {
  63. require_once 'Zend/Pdf/Destination/Named.php';
  64. $destination = Zend_Pdf_Destination_Named::create($destination);
  65. }
  66. if (!$destination instanceof Zend_Pdf_Destination) {
  67. require_once 'Zend/Pdf/Exception.php';
  68. throw new Zend_Pdf_Exception('$destination parameter must be a Zend_Pdf_Destination object or string.');
  69. }
  70. $dictionary = new Zend_Pdf_Element_Dictionary();
  71. $dictionary->Type = new Zend_Pdf_Element_Name('Action');
  72. $dictionary->S = new Zend_Pdf_Element_Name('GoTo');
  73. $dictionary->Next = null;
  74. $dictionary->D = $destination->getResource();
  75. return new Zend_Pdf_Action_GoTo($dictionary, new SplObjectStorage());
  76. }
  77. /**
  78. * Set goto action destination
  79. *
  80. * @return Zend_Pdf_Action_GoTo
  81. */
  82. public function setDestination(Zend_Pdf_Destination $destination)
  83. {
  84. $this->_destination = $destination;
  85. $this->_actionDictionary->touch();
  86. $this->_actionDictionary->D = $destination->getResource();
  87. return $this;
  88. }
  89. /**
  90. * Get goto action destination
  91. *
  92. * @return Zend_Pdf_Destination
  93. */
  94. public function getDestination()
  95. {
  96. return $this->_destination;
  97. }
  98. }