[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Reflection / ClassReflection.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Reflection;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 /**
17 * Extended version of the ReflectionClass
18 */
19 class ClassReflection extends \ReflectionClass {
20
21 /**
22 * @var \TYPO3\CMS\Extbase\Reflection\DocCommentParser Holds an instance of the doc comment parser for this class
23 */
24 protected $docCommentParser;
25
26 /**
27 * The constructor - initializes the class
28 *
29 * @param string $className Name of the class \TYPO3\CMS\Extbase\Reflection to reflect
30 */
31 public function __construct($className) {
32 parent::__construct($className);
33 }
34
35 /**
36 * Replacement for the original getMethods() method which makes sure
37 * that \TYPO3\CMS\Extbase\Reflection\MethodReflection objects are returned instead of the
38 * orginal ReflectionMethod instances.
39 *
40 * @param integer|NULL $filter A filter mask
41 * @return \TYPO3\CMS\Extbase\Reflection\MethodReflection Method reflection objects of the methods in this class
42 */
43 public function getMethods($filter = NULL) {
44 $extendedMethods = array();
45 $methods = $filter === NULL ? parent::getMethods() : parent::getMethods($filter);
46 foreach ($methods as $method) {
47 $extendedMethods[] = new \TYPO3\CMS\Extbase\Reflection\MethodReflection($this->getName(), $method->getName());
48 }
49 return $extendedMethods;
50 }
51
52 /**
53 * Replacement for the original getMethod() method which makes sure
54 * that \TYPO3\CMS\Extbase\Reflection\MethodReflection objects are returned instead of the
55 * orginal ReflectionMethod instances.
56 *
57 * @param string $name
58 * @return \TYPO3\CMS\Extbase\Reflection\MethodReflection Method reflection object of the named method
59 */
60 public function getMethod($name) {
61 $parentMethod = parent::getMethod($name);
62 if (!is_object($parentMethod)) {
63 return $parentMethod;
64 }
65 return new \TYPO3\CMS\Extbase\Reflection\MethodReflection($this->getName(), $parentMethod->getName());
66 }
67
68 /**
69 * Replacement for the original getConstructor() method which makes sure
70 * that \TYPO3\CMS\Extbase\Reflection\MethodReflection objects are returned instead of the
71 * orginal ReflectionMethod instances.
72 *
73 * @return \TYPO3\CMS\Extbase\Reflection\MethodReflection Method reflection object of the constructor method
74 */
75 public function getConstructor() {
76 $parentConstructor = parent::getConstructor();
77 if (!is_object($parentConstructor)) {
78 return $parentConstructor;
79 }
80 return new \TYPO3\CMS\Extbase\Reflection\MethodReflection($this->getName(), $parentConstructor->getName());
81 }
82
83 /**
84 * Replacement for the original getProperties() method which makes sure
85 * that \TYPO3\CMS\Extbase\Reflection\PropertyReflection objects are returned instead of the
86 * orginal ReflectionProperty instances.
87 *
88 * @param integer|NULL $filter A filter mask
89 * @return array of \TYPO3\CMS\Extbase\Reflection\PropertyReflection Property reflection objects of the properties in this class
90 */
91 public function getProperties($filter = NULL) {
92 $extendedProperties = array();
93 $properties = $filter === NULL ? parent::getProperties() : parent::getProperties($filter);
94 foreach ($properties as $property) {
95 $extendedProperties[] = new \TYPO3\CMS\Extbase\Reflection\PropertyReflection($this->getName(), $property->getName());
96 }
97 return $extendedProperties;
98 }
99
100 /**
101 * Replacement for the original getProperty() method which makes sure
102 * that a \TYPO3\CMS\Extbase\Reflection\PropertyReflection object is returned instead of the
103 * orginal ReflectionProperty instance.
104 *
105 * @param string $name Name of the property
106 * @return \TYPO3\CMS\Extbase\Reflection\PropertyReflection Property reflection object of the specified property in this class
107 */
108 public function getProperty($name) {
109 return new \TYPO3\CMS\Extbase\Reflection\PropertyReflection($this->getName(), $name);
110 }
111
112 /**
113 * Replacement for the original getInterfaces() method which makes sure
114 * that \TYPO3\CMS\Extbase\Reflection\ClassReflection objects are returned instead of the
115 * orginal ReflectionClass instances.
116 *
117 * @return array of \TYPO3\CMS\Extbase\Reflection\ClassReflection Class reflection objects of the properties in this class
118 */
119 public function getInterfaces() {
120 $extendedInterfaces = array();
121 $interfaces = parent::getInterfaces();
122 foreach ($interfaces as $interface) {
123 $extendedInterfaces[] = new \TYPO3\CMS\Extbase\Reflection\ClassReflection($interface->getName());
124 }
125 return $extendedInterfaces;
126 }
127
128 /**
129 * Replacement for the original getParentClass() method which makes sure
130 * that a \TYPO3\CMS\Extbase\Reflection\ClassReflection object is returned instead of the
131 * orginal ReflectionClass instance.
132 *
133 * @return \TYPO3\CMS\Extbase\Reflection\ClassReflection Reflection of the parent class - if any
134 */
135 public function getParentClass() {
136 $parentClass = parent::getParentClass();
137 return $parentClass === FALSE ? FALSE : new \TYPO3\CMS\Extbase\Reflection\ClassReflection($parentClass->getName());
138 }
139
140 /**
141 * Checks if the doc comment of this method is tagged with
142 * the specified tag
143 *
144 * @param string $tag Tag name to check for
145 * @return boolean TRUE if such a tag has been defined, otherwise FALSE
146 */
147 public function isTaggedWith($tag) {
148 $result = $this->getDocCommentParser()->isTaggedWith($tag);
149 return $result;
150 }
151
152 /**
153 * Returns an array of tags and their values
154 *
155 * @return array Tags and values
156 */
157 public function getTagsValues() {
158 return $this->getDocCommentParser()->getTagsValues();
159 }
160
161 /**
162 * Returns the values of the specified tag
163 *
164 * @param string $tag
165 * @return array Values of the given tag
166 */
167 public function getTagValues($tag) {
168 return $this->getDocCommentParser()->getTagValues($tag);
169 }
170
171 /**
172 * Returns an instance of the doc comment parser and
173 * runs the parse() method.
174 *
175 * @return \TYPO3\CMS\Extbase\Reflection\DocCommentParser
176 */
177 protected function getDocCommentParser() {
178 if (!is_object($this->docCommentParser)) {
179 $this->docCommentParser = new \TYPO3\CMS\Extbase\Reflection\DocCommentParser();
180 $this->docCommentParser->parseDocComment($this->getDocComment());
181 }
182 return $this->docCommentParser;
183 }
184 }