PageRenderTime 32ms CodeModel.GetById 3ms app.highlight 19ms RepoModel.GetById 4ms app.codeStats 0ms

/framework/vendor/zend/Zend/Reflection/Class.php

http://zoop.googlecode.com/
PHP | 247 lines | 131 code | 18 blank | 98 comment | 21 complexity | fed7b983cbc14beb0993547c3dd87f32 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_Reflection
 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: Class.php 20096 2010-01-06 02:05:09Z bkarwin $
 20 */
 21
 22/**
 23 * @see Zend_Reflection_Property
 24 */
 25require_once 'Zend/Reflection/Property.php';
 26
 27/**
 28 * @see Zend_Reflection_Method
 29 */
 30require_once 'Zend/Reflection/Method.php';
 31
 32/**
 33 * Zend_Reflection_Docblock
 34 */
 35require_once 'Zend/Reflection/Docblock.php';
 36
 37/**
 38 * @category   Zend
 39 * @package    Zend_Reflection
 40 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 41 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 42 */
 43class Zend_Reflection_Class extends ReflectionClass
 44{
 45    /**
 46     * Return the reflection file of the declaring file.
 47     *
 48     * @return Zend_Reflection_File
 49     */
 50    public function getDeclaringFile($reflectionClass = 'Zend_Reflection_File')
 51    {
 52        $instance = new $reflectionClass($this->getFileName());
 53        if (!$instance instanceof Zend_Reflection_File) {
 54            require_once 'Zend/Reflection/Exception.php';
 55            throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_File');
 56        }
 57        return $instance;
 58    }
 59
 60    /**
 61     * Return the classes Docblock reflection object
 62     *
 63     * @param  string $reflectionClass Name of reflection class to use
 64     * @return Zend_Reflection_Docblock
 65     * @throws Zend_Reflection_Exception for missing docblock or invalid reflection class
 66     */
 67    public function getDocblock($reflectionClass = 'Zend_Reflection_Docblock')
 68    {
 69        if ('' == $this->getDocComment()) {
 70            require_once 'Zend/Reflection/Exception.php';
 71            throw new Zend_Reflection_Exception($this->getName() . ' does not have a docblock');
 72        }
 73
 74        $instance = new $reflectionClass($this);
 75        if (!$instance instanceof Zend_Reflection_Docblock) {
 76            require_once 'Zend/Reflection/Exception.php';
 77            throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Docblock');
 78        }
 79        return $instance;
 80    }
 81
 82    /**
 83     * Return the start line of the class
 84     *
 85     * @param bool $includeDocComment
 86     * @return int
 87     */
 88    public function getStartLine($includeDocComment = false)
 89    {
 90        if ($includeDocComment) {
 91            if ($this->getDocComment() != '') {
 92                return $this->getDocblock()->getStartLine();
 93            }
 94        }
 95
 96        return parent::getStartLine();
 97    }
 98
 99    /**
100     * Return the contents of the class
101     *
102     * @param bool $includeDocblock
103     * @return string
104     */
105    public function getContents($includeDocblock = true)
106    {
107        $filename  = $this->getFileName();
108        $filelines = file($filename);
109        $startnum  = $this->getStartLine($includeDocblock);
110        $endnum    = $this->getEndLine() - $this->getStartLine();
111
112        return implode('', array_splice($filelines, $startnum, $endnum, true));
113    }
114
115    /**
116     * Get all reflection objects of implemented interfaces
117     *
118     * @param  string $reflectionClass Name of reflection class to use
119     * @return array Array of Zend_Reflection_Class
120     */
121    public function getInterfaces($reflectionClass = 'Zend_Reflection_Class')
122    {
123        $phpReflections  = parent::getInterfaces();
124        $zendReflections = array();
125        while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
126            $instance = new $reflectionClass($phpReflection->getName());
127            if (!$instance instanceof Zend_Reflection_Class) {
128                require_once 'Zend/Reflection/Exception.php';
129                throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Class');
130            }
131            $zendReflections[] = $instance;
132            unset($phpReflection);
133        }
134        unset($phpReflections);
135        return $zendReflections;
136    }
137
138    /**
139     * Return method reflection by name
140     *
141     * @param  string $name
142     * @param  string $reflectionClass Reflection class to utilize
143     * @return Zend_Reflection_Method
144     */
145    public function getMethod($name, $reflectionClass = 'Zend_Reflection_Method')
146    {
147        $phpReflection  = parent::getMethod($name);
148        $zendReflection = new $reflectionClass($this->getName(), $phpReflection->getName());
149
150        if (!$zendReflection instanceof Zend_Reflection_Method) {
151            require_once 'Zend/Reflection/Exception.php';
152            throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Method');
153        }
154
155        unset($phpReflection);
156        return $zendReflection;
157    }
158
159    /**
160     * Get reflection objects of all methods
161     *
162     * @param  string $filter
163     * @param  string $reflectionClass Reflection class to use for methods
164     * @return array Array of Zend_Reflection_Method objects
165     */
166    public function getMethods($filter = -1, $reflectionClass = 'Zend_Reflection_Method')
167    {
168        $phpReflections  = parent::getMethods($filter);
169        $zendReflections = array();
170        while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
171            $instance = new $reflectionClass($this->getName(), $phpReflection->getName());
172            if (!$instance instanceof Zend_Reflection_Method) {
173                require_once 'Zend/Reflection/Exception.php';
174                throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Method');
175            }
176            $zendReflections[] = $instance;
177            unset($phpReflection);
178        }
179        unset($phpReflections);
180        return $zendReflections;
181    }
182
183    /**
184     * Get parent reflection class of reflected class
185     *
186     * @param  string $reflectionClass Name of Reflection class to use
187     * @return Zend_Reflection_Class
188     */
189    public function getParentClass($reflectionClass = 'Zend_Reflection_Class')
190    {
191        $phpReflection = parent::getParentClass();
192        if ($phpReflection) {
193            $zendReflection = new $reflectionClass($phpReflection->getName());
194            if (!$zendReflection instanceof Zend_Reflection_Class) {
195                require_once 'Zend/Reflection/Exception.php';
196                throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Class');
197            }
198            unset($phpReflection);
199            return $zendReflection;
200        } else {
201            return false;
202        }
203    }
204
205    /**
206     * Return reflection property of this class by name
207     *
208     * @param  string $name
209     * @param  string $reflectionClass Name of reflection class to use
210     * @return Zend_Reflection_Property
211     */
212    public function getProperty($name, $reflectionClass = 'Zend_Reflection_Property')
213    {
214        $phpReflection  = parent::getProperty($name);
215        $zendReflection = new $reflectionClass($this->getName(), $phpReflection->getName());
216        if (!$zendReflection instanceof Zend_Reflection_Property) {
217            require_once 'Zend/Reflection/Exception.php';
218            throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Property');
219        }
220        unset($phpReflection);
221        return $zendReflection;
222    }
223
224    /**
225     * Return reflection properties of this class
226     *
227     * @param  int $filter
228     * @param  string $reflectionClass Name of reflection class to use
229     * @return array Array of Zend_Reflection_Property
230     */
231    public function getProperties($filter = -1, $reflectionClass = 'Zend_Reflection_Property')
232    {
233        $phpReflections = parent::getProperties($filter);
234        $zendReflections = array();
235        while ($phpReflections && ($phpReflection = array_shift($phpReflections))) {
236            $instance = new $reflectionClass($this->getName(), $phpReflection->getName());
237            if (!$instance instanceof Zend_Reflection_Property) {
238                require_once 'Zend/Reflection/Exception.php';
239                throw new Zend_Reflection_Exception('Invalid reflection class specified; must extend Zend_Reflection_Property');
240            }
241            $zendReflections[] = $instance;
242            unset($phpReflection);
243        }
244        unset($phpReflections);
245        return $zendReflections;
246    }
247}