Target.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_ElementFactory */
  23. require_once 'Zend/Pdf/ElementFactory.php';
  24. /**
  25. * PDF target (action or destination)
  26. *
  27. * @package Zend_Pdf
  28. * @subpackage Actions
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. abstract class Zend_Pdf_Target
  33. {
  34. /**
  35. * Parse resource and return it as an Action or Explicit Destination
  36. *
  37. * $param Zend_Pdf_Element $resource
  38. * @return Zend_Pdf_Destination|
  39. * @throws Zend_Pdf_Exception
  40. */
  41. public static function load(Zend_Pdf_Element $resource) {
  42. if ($resource->getType() == Zend_Pdf_Element::TYPE_DICTIONARY) {
  43. if (($resource->Type === null || $resource->Type->value =='Action') && $resource->S !== null) {
  44. // It's a well-formed action, load it
  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. return Zend_Pdf_Destination::load($resource);
  59. } else {
  60. require_once 'Zend/Pdf/Exception.php';
  61. throw new Zend_Pdf_Exception( 'Wrong resource type.' );
  62. }
  63. }
  64. /**
  65. * Get resource
  66. *
  67. * @internal
  68. * @return Zend_Pdf_Element
  69. */
  70. abstract public function getResource();
  71. }