PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/framework/vendor/zend/Zend/Pdf/Target.php

http://zoop.googlecode.com/
PHP | 76 lines | 28 code | 4 blank | 44 comment | 13 complexity | 6e67923202be64f668e854612c69a85a MD5 | raw file
 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-2010 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 20096 2010-01-06 02:05:09Z bkarwin $
21 */
22
23
24/**
25 * PDF target (action or destination)
26 *
27 * @package    Zend_Pdf
28 * @subpackage Actions
29 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
30 * @license    http://framework.zend.com/license/new-bsd     New BSD License
31 */
32abstract 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        require_once 'Zend/Pdf/Element.php';
43        if ($resource->getType() == Zend_Pdf_Element::TYPE_DICTIONARY) {
44            if (($resource->Type === null  ||  $resource->Type->value =='Action')  &&  $resource->S !== null) {
45                // It's a well-formed action, load it
46                require_once 'Zend/Pdf/Action.php';
47                return Zend_Pdf_Action::load($resource);
48            } else if ($resource->D !== null) {
49                // It's a destination
50                $resource = $resource->D;
51            } else {
52                require_once 'Zend/Pdf/Exception.php';
53                throw new Zend_Pdf_Exception('Wrong resource type.');
54            }
55        }
56
57        if ($resource->getType() == Zend_Pdf_Element::TYPE_ARRAY  ||
58            $resource->getType() == Zend_Pdf_Element::TYPE_NAME   ||
59            $resource->getType() == Zend_Pdf_Element::TYPE_STRING) {
60            // Resource is an array, just treat it as an explicit destination array
61            require_once 'Zend/Pdf/Destination.php';
62            return Zend_Pdf_Destination::load($resource);
63        } else {
64            require_once 'Zend/Pdf/Exception.php';
65            throw new Zend_Pdf_Exception( 'Wrong resource type.' );
66        }
67    }
68
69    /**
70     * Get resource
71     *
72     * @internal
73     * @return Zend_Pdf_Element
74     */
75    abstract public function getResource();
76}