PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

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

http://zoop.googlecode.com/
PHP | 148 lines | 56 code | 20 blank | 72 comment | 6 complexity | 0ee5f8ce02b6ceb728125cd39b28e293 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: Array.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 'array' 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_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     * Convert PDF element to PHP type.
133     *
134     * Dictionary is returned as an associative array
135     *
136     * @return mixed
137     */
138    public function toPhp()
139    {
140        $phpArray = array();
141
142        foreach ($this->items as $item) {
143            $phpArray[] = $item->toPhp();
144        }
145
146        return $phpArray;
147    }
148}