PageRenderTime 19ms CodeModel.GetById 8ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://zoop.googlecode.com/
PHP | 250 lines | 90 code | 34 blank | 126 comment | 7 complexity | 8af16a41329849a78fad5382bfffbae6 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: Object.php 20096 2010-01-06 02:05:09Z bkarwin $
 20 */
 21
 22
 23/** Zend_Pdf_Element */
 24require_once 'Zend/Pdf/Element.php';
 25
 26
 27/**
 28 * PDF file 'indirect object' element implementation
 29 *
 30 * @category   Zend
 31 * @package    Zend_Pdf
 32 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 33 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 34 */
 35class Zend_Pdf_Element_Object extends Zend_Pdf_Element
 36{
 37    /**
 38     * Object value
 39     *
 40     * @var Zend_Pdf_Element
 41     */
 42    protected $_value;
 43
 44    /**
 45     * Object number within PDF file
 46     *
 47     * @var integer
 48     */
 49    protected $_objNum;
 50
 51    /**
 52     * Generation number
 53     *
 54     * @var integer
 55     */
 56    protected $_genNum;
 57
 58    /**
 59     * Reference to the factory.
 60     *
 61     * @var Zend_Pdf_ElementFactory
 62     */
 63    protected $_factory;
 64
 65    /**
 66     * Object constructor
 67     *
 68     * @param Zend_Pdf_Element $val
 69     * @param integer $objNum
 70     * @param integer $genNum
 71     * @param Zend_Pdf_ElementFactory $factory
 72     * @throws Zend_Pdf_Exception
 73     */
 74    public function __construct(Zend_Pdf_Element $val, $objNum, $genNum, Zend_Pdf_ElementFactory $factory)
 75    {
 76        if ($val instanceof self) {
 77            require_once 'Zend/Pdf/Exception.php';
 78            throw new Zend_Pdf_Exception('Object number must not be an instance of Zend_Pdf_Element_Object.');
 79        }
 80
 81        if ( !(is_integer($objNum) && $objNum > 0) ) {
 82            require_once 'Zend/Pdf/Exception.php';
 83            throw new Zend_Pdf_Exception('Object number must be positive integer.');
 84        }
 85
 86        if ( !(is_integer($genNum) && $genNum >= 0) ) {
 87            require_once 'Zend/Pdf/Exception.php';
 88            throw new Zend_Pdf_Exception('Generation number must be non-negative integer.');
 89        }
 90
 91        $this->_value   = $val;
 92        $this->_objNum  = $objNum;
 93        $this->_genNum  = $genNum;
 94        $this->_factory = $factory;
 95
 96        $this->setParentObject($this);
 97
 98        $factory->registerObject($this, $objNum . ' ' . $genNum);
 99    }
100
101
102    /**
103     * Check, that object is generated by specified factory
104     *
105     * @return Zend_Pdf_ElementFactory
106     */
107    public function getFactory()
108    {
109        return $this->_factory;
110    }
111
112    /**
113     * Return type of the element.
114     *
115     * @return integer
116     */
117    public function getType()
118    {
119        return $this->_value->getType();
120    }
121
122
123    /**
124     * Get object number
125     *
126     * @return integer
127     */
128    public function getObjNum()
129    {
130        return $this->_objNum;
131    }
132
133
134    /**
135     * Get generation number
136     *
137     * @return integer
138     */
139    public function getGenNum()
140    {
141        return $this->_genNum;
142    }
143
144
145    /**
146     * Return reference to the object
147     *
148     * @param Zend_Pdf_Factory $factory
149     * @return string
150     */
151    public function toString($factory = null)
152    {
153        if ($factory === null) {
154            $shift = 0;
155        } else {
156            $shift = $factory->getEnumerationShift($this->_factory);
157        }
158
159        return $this->_objNum + $shift . ' ' . $this->_genNum . ' R';
160    }
161
162
163    /**
164     * Dump object to a string to save within PDF file.
165     *
166     * $factory parameter defines operation context.
167     *
168     * @param Zend_Pdf_ElementFactory $factory
169     * @return string
170     */
171    public function dump(Zend_Pdf_ElementFactory $factory)
172    {
173        $shift = $factory->getEnumerationShift($this->_factory);
174
175        return  $this->_objNum + $shift . " " . $this->_genNum . " obj \n"
176             .  $this->_value->toString($factory) . "\n"
177             . "endobj\n";
178    }
179
180    /**
181     * Get handler
182     *
183     * @param string $property
184     * @return mixed
185     */
186    public function __get($property)
187    {
188        return $this->_value->$property;
189    }
190
191    /**
192     * Set handler
193     *
194     * @param string $property
195     * @param  mixed $value
196     */
197    public function __set($property, $value)
198    {
199        $this->_value->$property = $value;
200    }
201
202    /**
203     * Call handler
204     *
205     * @param string $method
206     * @param array  $args
207     * @return mixed
208     */
209    public function __call($method, $args)
210    {
211        return call_user_func_array(array($this->_value, $method), $args);
212    }
213
214
215    /**
216     * Mark object as modified, to include it into new PDF file segment
217     */
218    public function touch()
219    {
220        $this->_factory->markAsModified($this);
221    }
222
223    /**
224     * Return object, which can be used to identify object and its references identity
225     *
226     * @return Zend_Pdf_Element_Object
227     */
228    public function getObject()
229    {
230        return $this;
231    }
232
233    /**
234     * Clean up resources, used by object
235     */
236    public function cleanUp()
237    {
238        $this->_value = null;
239    }
240
241    /**
242     * Convert PDF element to PHP type.
243     *
244     * @return mixed
245     */
246    public function toPhp()
247    {
248        return $this->_value->toPhp();
249    }
250}