*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Pdf / Element.php
blobbee10bfb7fc37b4fa30ad9c86ccb38021dd535d0
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Pdf
17 * @copyright Copyright (c) 2005-2009 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 16978 2009-07-22 19:59:40Z alexander $
23 /** Zend_Pdf_Element_Object */
24 require_once 'Zend/Pdf/Element/Object.php';
27 /**
28 * PDF file element implementation
30 * @package Zend_Pdf
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
34 abstract class Zend_Pdf_Element
36 const TYPE_BOOL = 1;
37 const TYPE_NUMERIC = 2;
38 const TYPE_STRING = 3;
39 const TYPE_NAME = 4;
40 const TYPE_ARRAY = 5;
41 const TYPE_DICTIONARY = 6;
42 const TYPE_STREAM = 7;
43 const TYPE_NULL = 11;
45 /**
46 * Reference to the top level indirect object, which contains this element.
48 * @var Zend_Pdf_Element_Object
50 private $_parentObject = null;
52 /**
53 * Return type of the element.
54 * See ZPdfPDFConst for possible values
56 * @return integer
58 abstract public function getType();
60 /**
61 * Convert element to a string, which can be directly
62 * written to a PDF file.
64 * $factory parameter defines operation context.
66 * @param Zend_Pdf_Factory $factory
67 * @return string
69 abstract public function toString($factory = null);
72 /**
73 * Set top level parent indirect object.
75 * @param Zend_Pdf_Element_Object $parent
77 public function setParentObject(Zend_Pdf_Element_Object $parent)
79 $this->_parentObject = $parent;
83 /**
84 * Get top level parent indirect object.
86 * @return Zend_Pdf_Element_Object
88 public function getParentObject()
90 return $this->_parentObject;
94 /**
95 * Mark object as modified, to include it into new PDF file segment.
97 * We don't automate this action to keep control on PDF update process.
98 * All new objects are treated as "modified" automatically.
100 public function touch()
102 if ($this->_parentObject !== null) {
103 $this->_parentObject->touch();
108 * Clean up resources, used by object
110 public function cleanUp()
112 // Do nothing
116 * Convert PDF element to PHP type.
118 * @return mixed
120 public function toPhp()
122 return $this->value;
126 * Convert PHP value into PDF element.
128 * @param mixed $input
129 * @return Zend_Pdf_Element
131 public static function phpToPdf($input)
133 if (is_numeric($input)) {
134 return new Zend_Pdf_Element_Numeric($input);
135 } else if (is_bool($input)) {
136 return new Zend_Pdf_Element_Boolean($input);
137 } else if (is_array($input)) {
138 $pdfElementsArray = array();
139 $isDictionary = false;
141 foreach ($input as $key => $value) {
142 if (is_string($key)) {
143 $isDictionary = true;
145 $pdfElementsArray[$key] = Zend_Pdf_Element::phpToPdf($value);
148 if ($isDictionary) {
149 return new Zend_Pdf_Element_Dictionary($pdfElementsArray);
150 } else {
151 return new Zend_Pdf_Element_Array($pdfElementsArray);
153 } else {
154 return new Zend_Pdf_Element_String((string)$input);