PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://zoop.googlecode.com/
PHP | 158 lines | 65 code | 16 blank | 77 comment | 10 complexity | 49902dce92a798871f2946ef3d17c2a0 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 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 18 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 19 * @version    $Id: Element.php 20096 2010-01-06 02:05:09Z bkarwin $
 20 */
 21
 22
 23/**
 24 * PDF file element implementation
 25 *
 26 * @package    Zend_Pdf
 27 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 28 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 29 */
 30abstract class Zend_Pdf_Element
 31{
 32    const TYPE_BOOL        = 1;
 33    const TYPE_NUMERIC     = 2;
 34    const TYPE_STRING      = 3;
 35    const TYPE_NAME        = 4;
 36    const TYPE_ARRAY       = 5;
 37    const TYPE_DICTIONARY  = 6;
 38    const TYPE_STREAM      = 7;
 39    const TYPE_NULL        = 11;
 40
 41    /**
 42     * Reference to the top level indirect object, which contains this element.
 43     *
 44     * @var Zend_Pdf_Element_Object
 45     */
 46    private $_parentObject = null;
 47
 48    /**
 49     * Return type of the element.
 50     * See ZPdfPDFConst for possible values
 51     *
 52     * @return integer
 53     */
 54    abstract public function getType();
 55
 56    /**
 57     * Convert element to a string, which can be directly
 58     * written to a PDF file.
 59     *
 60     * $factory parameter defines operation context.
 61     *
 62     * @param Zend_Pdf_Factory $factory
 63     * @return string
 64     */
 65    abstract public function toString($factory = null);
 66
 67
 68    /**
 69     * Set top level parent indirect object.
 70     *
 71     * @param Zend_Pdf_Element_Object $parent
 72     */
 73    public function setParentObject(Zend_Pdf_Element_Object $parent)
 74    {
 75        $this->_parentObject = $parent;
 76    }
 77
 78
 79    /**
 80     * Get top level parent indirect object.
 81     *
 82     * @return Zend_Pdf_Element_Object
 83     */
 84    public function getParentObject()
 85    {
 86        return $this->_parentObject;
 87    }
 88
 89
 90    /**
 91     * Mark object as modified, to include it into new PDF file segment.
 92     *
 93     * We don't automate this action to keep control on PDF update process.
 94     * All new objects are treated as "modified" automatically.
 95     */
 96    public function touch()
 97    {
 98        if ($this->_parentObject !== null) {
 99            $this->_parentObject->touch();
100        }
101    }
102
103    /**
104     * Clean up resources, used by object
105     */
106    public function cleanUp()
107    {
108        // Do nothing
109    }
110
111    /**
112     * Convert PDF element to PHP type.
113     *
114     * @return mixed
115     */
116    public function toPhp()
117    {
118        return $this->value;
119    }
120
121    /**
122     * Convert PHP value into PDF element.
123     *
124     * @param mixed $input
125     * @return Zend_Pdf_Element
126     */
127    public static function phpToPdf($input)
128    {
129        if (is_numeric($input)) {
130            require_once 'Zend/Pdf/Element/Numeric.php';
131            return new Zend_Pdf_Element_Numeric($input);
132        } else if (is_bool($input)) {
133            require_once 'Zend/Pdf/Element/Boolean.php';
134            return new Zend_Pdf_Element_Boolean($input);
135        } else if (is_array($input)) {
136            $pdfElementsArray = array();
137            $isDictionary = false;
138
139            foreach ($input as $key => $value) {
140                if (is_string($key)) {
141                    $isDictionary = true;
142                }
143                $pdfElementsArray[$key] = Zend_Pdf_Element::phpToPdf($value);
144            }
145
146            if ($isDictionary) {
147                require_once 'Zend/Pdf/Element/Dictionary.php';
148                return new Zend_Pdf_Element_Dictionary($pdfElementsArray);
149            } else {
150                require_once 'Zend/Pdf/Element/Array.php';
151                return new Zend_Pdf_Element_Array($pdfElementsArray);
152            }
153        } else {
154            require_once 'Zend/Pdf/Element/String.php';
155            return new Zend_Pdf_Element_String((string)$input);
156        }
157    }
158}