GoTo.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * Create new Zend_Pdf_Action_GoTo object using specified destination
  38. *
  39. * Object is created based on a provided dictionary. That allows to choose if it's
  40. * a direct or inderect object attached to some objects factory
  41. *
  42. * @param Zend_Pdf_Element|Zend_Pdf_Destination|string $destination
  43. * @param Zend_Pdf_ElementFactory $objectFactory
  44. * @return Zend_Pdf_Action_GoTo
  45. * @throws Zend_Pdf_Exception
  46. */
  47. public static function create($destination, $objectFactory = null)
  48. {
  49. if ($objectFactory === null) {
  50. $dictionary = new Zend_Pdf_Element_Dictionary();
  51. } else {
  52. $dictionary = $objectFactory->newObject(new Zend_Pdf_Element_Dictionary());
  53. }
  54. if ($dictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
  55. require_once 'Zend/Pdf/Exception.php';
  56. throw new Zend_Pdf_Exception('$dictionary mast be a direct or an indirect dictionary object.');
  57. }
  58. $dictionary->Type = new Zend_Pdf_Element_Name('Action');
  59. $dictionary->S = new Zend_Pdf_Element_Name('GoTo');
  60. $dictionary->Next = null;
  61. if (is_string($destination)) {
  62. // Named destination
  63. $dictionary->D = new Zend_Pdf_Element_String($destination);
  64. } else if ($destination instanceof Zend_Pdf_Element_Array) {
  65. // DestinationArray
  66. $dictionary->D = $destination;
  67. } else if ($destination instanceof Zend_Pdf_Destination) {
  68. $dictionary->D = $destination->getResource();
  69. } else {
  70. require_once 'Zend/Pdf/Exception.php';
  71. throw new Zend_Pdf_Exception('Wrong $destination parameter type');
  72. }
  73. return new Zend_Pdf_Action_GoTo($dictionary, null, new SplObjectStorage());
  74. }
  75. /**
  76. * Returns goto action destination
  77. * (Zend_Pdf_Element_Name or Zend_Pdf_Element_String for named destinations
  78. * or Zend_Pdf_Array for explicit destinations)
  79. *
  80. * @return Zend_Pdf_Destination|string
  81. */
  82. public function getDestination()
  83. {
  84. $destination = $this->_actionDictionary->D;
  85. if ($destination instanceof Zend_Pdf_Element_Name || $destination instanceof Zend_Pdf_Element_String) {
  86. return $destination->value;
  87. }
  88. return Zend_Pdf_Destination::load($this->_actionDictionary->D);
  89. }
  90. }