PageRenderTime 29ms CodeModel.GetById 21ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Zend/Pdf/Element/Array.php

https://bitbucket.org/hamidrezas/melobit
PHP | 181 lines | 71 code | 25 blank | 85 comment | 6 complexity | ffc374e90a7651650a3084260797180a MD5 | raw file
Possible License(s): AGPL-1.0
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
 18 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 19 * @version    $Id: Array.php 24594 2012-01-05 21:27:01Z matthew $
 20 */
 21
 22
 23/** Zend_Pdf_Element */
 24require_once 'Zend/Pdf/Element.php';
 25
 26
 27/**
 28 * PDF file 'array' element implementation
 29 *
 30 * @category   Zend
 31 * @package    Zend_Pdf
 32 * @copyright  Copyright (c) 2005-2012 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_Array extends Zend_Pdf_Element
 36{
 37    /**
 38     * Array element items
 39     *
 40     * Array of Zend_Pdf_Element objects
 41     *
 42     * @var array
 43     */
 44    public $items;
 45
 46
 47    /**
 48     * Object constructor
 49     *
 50     * @param array $val   - array of Zend_Pdf_Element objects
 51     * @throws Zend_Pdf_Exception
 52     */
 53    public function __construct($val = null)
 54    {
 55        $this->items = new ArrayObject();
 56
 57        if ($val !== null  &&  is_array($val)) {
 58            foreach ($val as $element) {
 59                if (!$element instanceof Zend_Pdf_Element) {
 60                    require_once 'Zend/Pdf/Exception.php';
 61                    throw new Zend_Pdf_Exception('Array elements must be Zend_Pdf_Element objects');
 62                }
 63                $this->items[] = $element;
 64            }
 65        } else if ($val !== null){
 66            require_once 'Zend/Pdf/Exception.php';
 67            throw new Zend_Pdf_Exception('Argument must be an array');
 68        }
 69    }
 70
 71
 72    /**
 73     * Getter
 74     *
 75     * @param string $property
 76     * @throws Zend_Pdf_Exception
 77     */
 78    public function __get($property) {
 79        require_once 'Zend/Pdf/Exception.php';
 80        throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
 81    }
 82
 83
 84    /**
 85     * Setter
 86     *
 87     * @param mixed $offset
 88     * @param mixed $value
 89     * @throws Zend_Pdf_Exception
 90     */
 91    public function __set($property, $value) {
 92        require_once 'Zend/Pdf/Exception.php';
 93        throw new Zend_Pdf_Exception('Undefined property: Zend_Pdf_Element_Array::$' . $property);
 94    }
 95
 96    /**
 97     * Return type of the element.
 98     *
 99     * @return integer
100     */
101    public function getType()
102    {
103        return Zend_Pdf_Element::TYPE_ARRAY;
104    }
105
106
107    /**
108     * Return object as string
109     *
110     * @param Zend_Pdf_Factory $factory
111     * @return string
112     */
113    public function toString($factory = null)
114    {
115        $outStr = '[';
116        $lastNL = 0;
117
118        foreach ($this->items as $element) {
119            if (strlen($outStr) - $lastNL > 128)  {
120                $outStr .= "\n";
121                $lastNL = strlen($outStr);
122            }
123
124            $outStr .= $element->toString($factory) . ' ';
125        }
126        $outStr .= ']';
127
128        return $outStr;
129    }
130
131    /**
132     * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
133     *
134     * @param Zend_Pdf_ElementFactory $factory  The factory to attach
135     * @param array &$processed  List of already processed indirect objects, used to avoid objects duplication
136     * @param integer $mode  Cloning mode (defines filter for objects cloning)
137     * @returns Zend_Pdf_Element
138     */
139    public function makeClone(Zend_Pdf_ElementFactory $factory, array &$processed, $mode)
140    {
141        $newArray = new self();
142
143        foreach ($this->items as $key => $value) {
144            $newArray->items[$key] = $value->makeClone($factory, $processed, $mode);
145        }
146
147        return $newArray;
148    }
149
150    /**
151     * Set top level parent indirect object.
152     *
153     * @param Zend_Pdf_Element_Object $parent
154     */
155    public function setParentObject(Zend_Pdf_Element_Object $parent)
156    {
157        parent::setParentObject($parent);
158
159        foreach ($this->items as $item) {
160            $item->setParentObject($parent);
161        }
162    }
163
164    /**
165     * Convert PDF element to PHP type.
166     *
167     * Dictionary is returned as an associative array
168     *
169     * @return mixed
170     */
171    public function toPhp()
172    {
173        $phpArray = array();
174
175        foreach ($this->items as $item) {
176            $phpArray[] = $item->toPhp();
177        }
178
179        return $phpArray;
180    }
181}