[+FEATURE] Backport CommandController Implementation
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Reflection / MethodReflection.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 ReflectionMethod
27 *
28 * @package Extbase
29 * @subpackage Reflection
30 * @version $Id$
31 */
32 class Tx_Extbase_Reflection_MethodReflection extends ReflectionMethod {
33
34 /**
35 * @var Tx_Extbase_Reflection_DocCommentParser: An instance of the doc comment parser
36 */
37 protected $docCommentParser;
38
39 /**
40 * The constructor, initializes the reflection class
41 *
42 * @param string $className Name of the method's class
43 * @param string $methodName Name of the method to reflect
44 */
45 public function __construct($className, $methodName) {
46 parent::__construct($className, $methodName);
47 }
48
49 /**
50 * Returns the declaring class
51 *
52 * @return Tx_Extbase_Reflection_ClassReflection The declaring class
53 */
54 public function getDeclaringClass() {
55 return new Tx_Extbase_Reflection_ClassReflection(parent::getDeclaringClass()->getName());
56 }
57
58 /**
59 * Replacement for the original getParameters() method which makes sure
60 * that Tx_Extbase_Reflection_ParameterReflection objects are returned instead of the
61 * orginal ReflectionParameter instances.
62 *
63 * @return array of Tx_Extbase_Reflection_ParameterReflection Parameter reflection objects of the parameters of this method
64 */
65 public function getParameters() {
66 $extendedParameters = array();
67 foreach (parent::getParameters() as $parameter) {
68 $extendedParameters[] = new Tx_Extbase_Reflection_ParameterReflection(array($this->getDeclaringClass()->getName(), $this->getName()), $parameter->getName());
69 }
70 return $extendedParameters;
71 }
72
73 /**
74 * Checks if the doc comment of this method is tagged with
75 * the specified tag
76 *
77 * @param string $tag Tag name to check for
78 * @return boolean TRUE if such a tag has been defined, otherwise FALSE
79 */
80 public function isTaggedWith($tag) {
81 $result = $this->getDocCommentParser()->isTaggedWith($tag);
82 return $result;
83 }
84
85 /**
86 * Returns an array of tags and their values
87 *
88 * @return array Tags and values
89 */
90 public function getTagsValues() {
91 return $this->getDocCommentParser()->getTagsValues();
92 }
93
94 /**
95 * Returns the values of the specified tag
96 *
97 * @param string $tag Tag name to check for
98 * @return array Values of the given tag
99 */
100 public function getTagValues($tag) {
101 return $this->getDocCommentParser()->getTagValues($tag);
102 }
103
104 /**
105 * Returns the description part of the doc comment
106 *
107 * @return string Doc comment description
108 */
109 public function getDescription() {
110 return $this->getDocCommentParser()->getDescription();
111 }
112
113 /**
114 * Returns an instance of the doc comment parser and
115 * runs the parse() method.
116 *
117 * @return Tx_Extbase_Reflection_DocCommentParser
118 */
119 protected function getDocCommentParser() {
120 if (!is_object($this->docCommentParser)) {
121 $this->docCommentParser = new Tx_Extbase_Reflection_DocCommentParser;
122 $this->docCommentParser->parseDocComment($this->getDocComment());
123 }
124 return $this->docCommentParser;
125 }
126 }
127
128 ?>