You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.7 KiB

11 years ago
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Target.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. /**
  23. * PDF target (action or destination)
  24. *
  25. * @package Zend_Pdf
  26. * @subpackage Actions
  27. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. abstract class Zend_Pdf_Target
  31. {
  32. /**
  33. * Parse resource and return it as an Action or Explicit Destination
  34. *
  35. * $param Zend_Pdf_Element $resource
  36. * @return Zend_Pdf_Destination|
  37. * @throws Zend_Pdf_Exception
  38. */
  39. public static function load(Zend_Pdf_Element $resource) {
  40. // require_once 'Zend/Pdf/Element.php';
  41. if ($resource->getType() == Zend_Pdf_Element::TYPE_DICTIONARY) {
  42. if (($resource->Type === null || $resource->Type->value =='Action') && $resource->S !== null) {
  43. // It's a well-formed action, load it
  44. // require_once 'Zend/Pdf/Action.php';
  45. return Zend_Pdf_Action::load($resource);
  46. } else if ($resource->D !== null) {
  47. // It's a destination
  48. $resource = $resource->D;
  49. } else {
  50. // require_once 'Zend/Pdf/Exception.php';
  51. throw new Zend_Pdf_Exception('Wrong resource type.');
  52. }
  53. }
  54. if ($resource->getType() == Zend_Pdf_Element::TYPE_ARRAY ||
  55. $resource->getType() == Zend_Pdf_Element::TYPE_NAME ||
  56. $resource->getType() == Zend_Pdf_Element::TYPE_STRING) {
  57. // Resource is an array, just treat it as an explicit destination array
  58. // require_once 'Zend/Pdf/Destination.php';
  59. return Zend_Pdf_Destination::load($resource);
  60. } else {
  61. // require_once 'Zend/Pdf/Exception.php';
  62. throw new Zend_Pdf_Exception( 'Wrong resource type.' );
  63. }
  64. }
  65. /**
  66. * Get resource
  67. *
  68. * @internal
  69. * @return Zend_Pdf_Element
  70. */
  71. abstract public function getResource();
  72. }