File indexing completed on 2024-05-26 06:03:16

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Pdf
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 
0023 /** Zend_Pdf_Element */
0024 // require_once 'Zend/Pdf/Element.php';
0025 
0026 
0027 /**
0028  * PDF file 'array' element implementation
0029  *
0030  * @category   Zend
0031  * @package    Zend_Pdf
0032  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0033  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0034  */
0035 class Zend_Pdf_Element_Array extends Zend_Pdf_Element
0036 {
0037     /**
0038      * Array element items
0039      *
0040      * Array of Zend_Pdf_Element objects
0041      *
0042      * @var array
0043      */
0044     public $items;
0045 
0046 
0047     /**
0048      * Object constructor
0049      *
0050      * @param array $val   - array of Zend_Pdf_Element objects
0051      * @throws Zend_Pdf_Exception
0052      */
0053     public function __construct($val = null)
0054     {
0055         $this->items = new ArrayObject();
0056 
0057         if ($val !== null  &&  is_array($val)) {
0058             foreach ($val as $element) {
0059                 if (!$element instanceof Zend_Pdf_Element) {
0060                     // require_once 'Zend/Pdf/Exception.php';
0061                     throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
0062                 }
0063                 $this->items[] = $element;
0064             }
0065         } else if ($val !== null){
0066             // require_once 'Zend/Pdf/Exception.php';
0067             throw new Zend_Pdf_Exception('Argument must be an array');
0068         }
0069     }
0070 
0071 
0072     /**
0073      * Getter
0074      *
0075      * @param string $property
0076      * @throws Zend_Pdf_Exception
0077      */
0078     public function __get($property) {
0079         // require_once 'Zend/Pdf/Exception.php';
0080         throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
0081     }
0082 
0083 
0084     /**
0085      * Setter
0086      *
0087      * @param mixed $offset
0088      * @param mixed $value
0089      * @throws Zend_Pdf_Exception
0090      */
0091     public function __set($property, $value) {
0092         // require_once 'Zend/Pdf/Exception.php';
0093         throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
0094     }
0095 
0096     /**
0097      * Return type of the element.
0098      *
0099      * @return integer
0100      */
0101     public function getType()
0102     {
0103         return Zend_Pdf_Element::TYPE_ARRAY;
0104     }
0105 
0106 
0107     /**
0108      * Return object as string
0109      *
0110      * @param Zend_Pdf_Factory $factory
0111      * @return string
0112      */
0113     public function toString($factory = null)
0114     {
0115         $outStr = '[';
0116         $lastNL = 0;
0117 
0118         foreach ($this->items as $element) {
0119             if (strlen($outStr) - $lastNL > 128)  {
0120                 $outStr .= "\n";
0121                 $lastNL = strlen($outStr);
0122             }
0123 
0124             $outStr .= $element->toString($factory) . ' ';
0125         }
0126         $outStr .= ']';
0127 
0128         return $outStr;
0129     }
0130 
0131     /**
0132      * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
0133      *
0134      * @param Zend_Pdf_ElementFactory $factory  The factory to attach
0135      * @param array &$processed  List of already processed indirect objects, used to avoid objects duplication
0136      * @param integer $mode  Cloning mode (defines filter for objects cloning)
0137      * @returns Zend_Pdf_Element
0138      */
0139     public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
0140     {
0141         $newArray = new self();
0142 
0143         foreach ($this->items as $key => $value) {
0144             $newArray->items[$key] = $value->makeClone($factory, $processed, $mode);
0145         }
0146 
0147         return $newArray;
0148     }
0149 
0150     /**
0151      * Set top level parent indirect object.
0152      *
0153      * @param Zend_Pdf_Element_Object $parent
0154      */
0155     public function setParentObject(Zend_Pdf_Element_Object $parent)
0156     {
0157         parent::setParentObject($parent);
0158 
0159         foreach ($this->items as $item) {
0160             $item->setParentObject($parent);
0161         }
0162     }
0163 
0164     /**
0165      * Convert PDF element to PHP type.
0166      *
0167      * Dictionary is returned as an associative array
0168      *
0169      * @return mixed
0170      */
0171     public function toPhp()
0172     {
0173         $phpArray = array();
0174 
0175         foreach ($this->items as $item) {
0176             $phpArray[] = $item->toPhp();
0177         }
0178 
0179         return $phpArray;
0180     }
0181 }