Raised DBAL version from 1.1.5 to 1.1.6
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Reflection / ClassReflection.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Extended version of the ReflectionClass
27 *
28 * @package Extbase
29 * @subpackage Reflection
30 * @version $Id: ClassReflection.php 1052 2009-08-05 21:51:32Z sebastian $
31 */
32 class Tx_Extbase_Reflection_ClassReflection extends ReflectionClass {
33
34 /**
35 * @var Tx_Extbase_Reflection_DocCommentParser Holds an instance of the doc comment parser for this class
36 */
37 protected $docCommentParser;
38
39 /**
40 * The constructor - initializes the class Tx_Extbase_Reflection_reflector
41 *
42 * @param string $className: Name of the class Tx_Extbase_Reflection_to reflect
43 */
44 public function __construct($className) {
45 parent::__construct($className);
46 }
47
48 /**
49 * Replacement for the original getMethods() method which makes sure
50 * that Tx_Extbase_Reflection_MethodReflection objects are returned instead of the
51 * orginal ReflectionMethod instances.
52 *
53 * @param long $filter: A filter mask
54 * @return Tx_Extbase_Reflection_MethodReflection Method reflection objects of the methods in this class
55 */
56 public function getMethods($filter = NULL) {
57 $extendedMethods = array();
58
59 $methods = ($filter === NULL ? parent::getMethods() : parent::getMethods($filter));
60 foreach ($methods as $method) {
61 $extendedMethods[] = new Tx_Extbase_Reflection_MethodReflection($this->getName(), $method->getName());
62 }
63 return $extendedMethods;
64 }
65
66 /**
67 * Replacement for the original getMethod() method which makes sure
68 * that Tx_Extbase_Reflection_MethodReflection objects are returned instead of the
69 * orginal ReflectionMethod instances.
70 *
71 * @return Tx_Extbase_Reflection_MethodReflection Method reflection object of the named method
72 */
73 public function getMethod($name) {
74 $parentMethod = parent::getMethod($name);
75 if (!is_object($parentMethod)) return $parentMethod;
76 return new Tx_Extbase_Reflection_MethodReflection($this->getName(), $parentMethod->getName());
77 }
78
79 /**
80 * Replacement for the original getConstructor() method which makes sure
81 * that Tx_Extbase_Reflection_MethodReflection objects are returned instead of the
82 * orginal ReflectionMethod instances.
83 *
84 * @return Tx_Extbase_Reflection_MethodReflection Method reflection object of the constructor method
85 */
86 public function getConstructor() {
87 $parentConstructor = parent::getConstructor();
88 if (!is_object($parentConstructor)) return $parentConstructor;
89 return new Tx_Extbase_Reflection_MethodReflection($this->getName(), $parentConstructor->getName());
90 }
91
92 /**
93 * Replacement for the original getProperties() method which makes sure
94 * that Tx_Extbase_Reflection_PropertyReflection objects are returned instead of the
95 * orginal ReflectionProperty instances.
96 *
97 * @param long $filter: A filter mask
98 * @return array of Tx_Extbase_Reflection_PropertyReflection Property reflection objects of the properties in this class
99 */
100 public function getProperties($filter = NULL) {
101 $extendedProperties = array();
102 $properties = ($filter === NULL ? parent::getProperties() : parent::getProperties($filter));
103 foreach ($properties as $property) {
104 $extendedProperties[] = new Tx_Extbase_Reflection_PropertyReflection($this->getName(), $property->getName());
105 }
106 return $extendedProperties;
107 }
108
109 /**
110 * Replacement for the original getProperty() method which makes sure
111 * that a Tx_Extbase_Reflection_PropertyReflection object is returned instead of the
112 * orginal ReflectionProperty instance.
113 *
114 * @param string $name: Name of the property
115 * @return Tx_Extbase_Reflection_PropertyReflection Property reflection object of the specified property in this class
116 */
117 public function getProperty($name) {
118 return new Tx_Extbase_Reflection_PropertyReflection($this->getName(), $name);
119 }
120
121 /**
122 * Replacement for the original getInterfaces() method which makes sure
123 * that Tx_Extbase_Reflection_ClassReflection objects are returned instead of the
124 * orginal ReflectionClass instances.
125 *
126 * @return array of Tx_Extbase_Reflection_ClassReflection Class reflection objects of the properties in this class
127 */
128 public function getInterfaces() {
129 $extendedInterfaces = array();
130 $interfaces = parent::getInterfaces();
131 foreach ($interfaces as $interface) {
132 $extendedInterfaces[] = new Tx_Extbase_Reflection_ClassReflection($interface->getName());
133 }
134 return $extendedInterfaces;
135 }
136
137 /**
138 * Replacement for the original getParentClass() method which makes sure
139 * that a Tx_Extbase_Reflection_ClassReflection object is returned instead of the
140 * orginal ReflectionClass instance.
141 *
142 * @return Tx_Extbase_Reflection_ClassReflection Reflection of the parent class - if any
143 */
144 public function getParentClass() {
145 $parentClass = parent::getParentClass();
146 return ($parentClass === NULL) ? NULL : new Tx_Extbase_Reflection_ClassReflection($parentClass->getName());
147 }
148
149 /**
150 * Checks if the doc comment of this method is tagged with
151 * the specified tag
152 *
153 * @param string $tag: Tag name to check for
154 * @return boolean TRUE if such a tag has been defined, otherwise FALSE
155 */
156 public function isTaggedWith($tag) {
157 $result = $this->getDocCommentParser()->isTaggedWith($tag);
158 return $result;
159 }
160
161 /**
162 * Returns an array of tags and their values
163 *
164 * @return array Tags and values
165 */
166 public function getTagsValues() {
167 return $this->getDocCommentParser()->getTagsValues();
168 }
169
170 /**
171 * Returns the values of the specified tag
172 * @return array Values of the given tag
173 */
174 public function getTagValues($tag) {
175 return $this->getDocCommentParser()->getTagValues($tag);
176 }
177
178 /**
179 * Returns an instance of the doc comment parser and
180 * runs the parse() method.
181 *
182 * @return Tx_Extbase_Reflection_DocCommentParser
183 */
184 protected function getDocCommentParser() {
185 if (!is_object($this->docCommentParser)) {
186 $this->docCommentParser = new Tx_Extbase_Reflection_DocCommentParser;
187 $this->docCommentParser->parseDocComment($this->getDocComment());
188 }
189 return $this->docCommentParser;
190 }
191 }
192
193 ?>