TYPO3 API  SVNRelease
ClassReflection.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 /**
00026  * Extended version of the ReflectionClass
00027  *
00028  * @package Extbase
00029  * @subpackage Reflection
00030  * @version $Id: ClassReflection.php 1052 2009-08-05 21:51:32Z sebastian $
00031  */
00032 class Tx_Extbase_Reflection_ClassReflection extends ReflectionClass {
00033 
00034     /**
00035      * @var Tx_Extbase_Reflection_DocCommentParser Holds an instance of the doc comment parser for this class
00036      */
00037     protected $docCommentParser;
00038 
00039     /**
00040      * The constructor - initializes the class Tx_Extbase_Reflection_reflector
00041      *
00042      * @param  string $className: Name of the class Tx_Extbase_Reflection_to reflect
00043      */
00044     public function __construct($className) {
00045         parent::__construct($className);
00046     }
00047 
00048     /**
00049      * Replacement for the original getMethods() method which makes sure
00050      * that Tx_Extbase_Reflection_MethodReflection objects are returned instead of the
00051      * orginal ReflectionMethod instances.
00052      *
00053      * @param  long $filter: A filter mask
00054      * @return Tx_Extbase_Reflection_MethodReflection Method reflection objects of the methods in this class
00055      */
00056     public function getMethods($filter = NULL) {
00057         $extendedMethods = array();
00058 
00059         $methods = ($filter === NULL ? parent::getMethods() : parent::getMethods($filter));
00060         foreach ($methods as $method) {
00061             $extendedMethods[] = new Tx_Extbase_Reflection_MethodReflection($this->getName(), $method->getName());
00062         }
00063         return $extendedMethods;
00064     }
00065 
00066     /**
00067      * Replacement for the original getMethod() method which makes sure
00068      * that Tx_Extbase_Reflection_MethodReflection objects are returned instead of the
00069      * orginal ReflectionMethod instances.
00070      *
00071      * @return Tx_Extbase_Reflection_MethodReflection Method reflection object of the named method
00072      */
00073     public function getMethod($name) {
00074         $parentMethod = parent::getMethod($name);
00075         if (!is_object($parentMethod)) return $parentMethod;
00076         return new Tx_Extbase_Reflection_MethodReflection($this->getName(), $parentMethod->getName());
00077     }
00078 
00079     /**
00080      * Replacement for the original getConstructor() method which makes sure
00081      * that Tx_Extbase_Reflection_MethodReflection objects are returned instead of the
00082      * orginal ReflectionMethod instances.
00083      *
00084      * @return Tx_Extbase_Reflection_MethodReflection Method reflection object of the constructor method
00085      */
00086     public function getConstructor() {
00087         $parentConstructor = parent::getConstructor();
00088         if (!is_object($parentConstructor)) return $parentConstructor;
00089         return new Tx_Extbase_Reflection_MethodReflection($this->getName(), $parentConstructor->getName());
00090     }
00091 
00092     /**
00093      * Replacement for the original getProperties() method which makes sure
00094      * that Tx_Extbase_Reflection_PropertyReflection objects are returned instead of the
00095      * orginal ReflectionProperty instances.
00096      *
00097      * @param  long $filter: A filter mask
00098      * @return array of Tx_Extbase_Reflection_PropertyReflection Property reflection objects of the properties in this class
00099      */
00100     public function getProperties($filter = NULL) {
00101         $extendedProperties = array();
00102         $properties = ($filter === NULL ? parent::getProperties() : parent::getProperties($filter));
00103         foreach ($properties as $property) {
00104             $extendedProperties[] = new Tx_Extbase_Reflection_PropertyReflection($this->getName(), $property->getName());
00105         }
00106         return $extendedProperties;
00107     }
00108 
00109     /**
00110      * Replacement for the original getProperty() method which makes sure
00111      * that a Tx_Extbase_Reflection_PropertyReflection object is returned instead of the
00112      * orginal ReflectionProperty instance.
00113      *
00114      * @param  string $name: Name of the property
00115      * @return Tx_Extbase_Reflection_PropertyReflection Property reflection object of the specified property in this class
00116      */
00117     public function getProperty($name) {
00118         return new Tx_Extbase_Reflection_PropertyReflection($this->getName(), $name);
00119     }
00120 
00121     /**
00122      * Replacement for the original getInterfaces() method which makes sure
00123      * that Tx_Extbase_Reflection_ClassReflection objects are returned instead of the
00124      * orginal ReflectionClass instances.
00125      *
00126      * @return array of Tx_Extbase_Reflection_ClassReflection Class reflection objects of the properties in this class
00127      */
00128     public function getInterfaces() {
00129         $extendedInterfaces = array();
00130         $interfaces = parent::getInterfaces();
00131         foreach ($interfaces as $interface) {
00132             $extendedInterfaces[] = new Tx_Extbase_Reflection_ClassReflection($interface->getName());
00133         }
00134         return $extendedInterfaces;
00135     }
00136 
00137     /**
00138      * Replacement for the original getParentClass() method which makes sure
00139      * that a Tx_Extbase_Reflection_ClassReflection object is returned instead of the
00140      * orginal ReflectionClass instance.
00141      *
00142      * @return Tx_Extbase_Reflection_ClassReflection Reflection of the parent class - if any
00143      */
00144     public function getParentClass() {
00145         $parentClass = parent::getParentClass();
00146         return ($parentClass === FALSE) ? FALSE : new Tx_Extbase_Reflection_ClassReflection($parentClass->getName());
00147     }
00148 
00149     /**
00150      * Checks if the doc comment of this method is tagged with
00151      * the specified tag
00152      *
00153      * @param  string $tag: Tag name to check for
00154      * @return boolean TRUE if such a tag has been defined, otherwise FALSE
00155      */
00156     public function isTaggedWith($tag) {
00157         $result = $this->getDocCommentParser()->isTaggedWith($tag);
00158         return $result;
00159     }
00160 
00161     /**
00162      * Returns an array of tags and their values
00163      *
00164      * @return array Tags and values
00165      */
00166     public function getTagsValues() {
00167         return $this->getDocCommentParser()->getTagsValues();
00168     }
00169 
00170     /**
00171      * Returns the values of the specified tag
00172      * @return array Values of the given tag
00173      */
00174     public function getTagValues($tag) {
00175         return $this->getDocCommentParser()->getTagValues($tag);
00176     }
00177 
00178     /**
00179      * Returns an instance of the doc comment parser and
00180      * runs the parse() method.
00181      *
00182      * @return Tx_Extbase_Reflection_DocCommentParser
00183      */
00184     protected function getDocCommentParser() {
00185         if (!is_object($this->docCommentParser)) {
00186             $this->docCommentParser = new Tx_Extbase_Reflection_DocCommentParser;
00187             $this->docCommentParser->parseDocComment($this->getDocComment());
00188         }
00189         return $this->docCommentParser;
00190     }
00191 }
00192 
00193 ?>