argument registration
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Reflection / PropertyReflection.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 framework. *
5 * *
6 * It is free software; you can redistribute it and/or modify it under *
7 * the terms of the GNU Lesser General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * @package FLOW3
25 * @subpackage Reflection
26 * @version $Id: PropertyReflection.php 1811 2009-01-28 12:04:49Z robert $
27 */
28
29 /**
30 * Extended version of the ReflectionProperty
31 *
32 * @package FLOW3
33 * @subpackage Reflection
34 * @version $Id: PropertyReflection.php 1811 2009-01-28 12:04:49Z robert $
35 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
36 */
37 class Tx_ExtBase_Reflection_PropertyReflection extends ReflectionProperty {
38
39 /**
40 * @var Tx_ExtBase_Reflection_DocCommentParser: An instance of the doc comment parser
41 */
42 protected $docCommentParser;
43
44 /**
45 * The constructor, initializes the reflection class
46 *
47 * @param string $className Name of the property's class
48 * @param string $propertyName Name of the property to reflect
49 * @return void
50 * @author Robert Lemke <robert@typo3.org>
51 */
52 public function __construct($className, $propertyName) {
53 parent::__construct($className, $propertyName);
54 }
55
56 /**
57 * Checks if the doc comment of this property is tagged with
58 * the specified tag
59 *
60 * @param string $tag Tag name to check for
61 * @return boolean TRUE if such a tag has been defined, otherwise FALSE
62 */
63 public function isTaggedWith($tag) {
64 $result = $this->getDocCommentParser()->isTaggedWith($tag);
65 return $result;
66 }
67
68 /**
69 * Returns an array of tags and their values
70 *
71 * @return array Tags and values
72 * @author Robert Lemke <robert@typo3.org>
73 */
74 public function getTagsValues() {
75 return $this->getDocCommentParser()->getTagsValues();
76 }
77
78 /**
79 * Returns the values of the specified tag
80 *
81 * @return array Values of the given tag
82 * @author Robert Lemke <robert@typo3.org>
83 */
84 public function getTagValues($tag) {
85 return $this->getDocCommentParser()->getTagValues($tag);
86 }
87
88 /**
89 * Returns the value of the reflected property - even if it is protected.
90 *
91 * @param object $object Instance of the declaring class Tx_ExtBase_Reflection_to read the value from
92 * @return mixed Value of the property
93 * @throws Tx_ExtBase_Reflection_Exception
94 * @author Robert Lemke <robert@typo3.org>
95 * @author Karsten Dambekalns <karsten@typo3.org>
96 * @todo Maybe support private properties as well, as of PHP 5.3.0 we can do
97 * $obj = new Foo;
98 * $prop = new ReflectionProperty('Foo', 'y'); // y is private member
99 * $prop->setAccessible(true);
100 * var_dump($prop->getValue($obj)); // int(2)
101 */
102 public function getValue($object = NULL) {
103 if (!is_object($object)) throw new Tx_ExtBase_Reflection_Exception('$object is of type ' . gettype($object) . ', instance of class ' . $this->class . ' expected.', 1210859212);
104 if ($this->isPublic()) return parent::getValue($object);
105 if ($this->isPrivate()) throw new Tx_ExtBase_Reflection_Exception('Cannot return value of private property "' . $this->name . '.', 1210859206);
106
107 parent::setAccessible(TRUE);
108 return parent::getValue($object);
109 }
110
111 /**
112 * Returns an instance of the doc comment parser and
113 * runs the parse() method.
114 *
115 * @return Tx_ExtBase_Reflection_DocCommentParser
116 * @author Robert Lemke <robert@typo3.org>
117 */
118 protected function getDocCommentParser() {
119 if (!is_object($this->docCommentParser)) {
120 $this->docCommentParser = new Tx_ExtBase_Reflection_DocCommentParser;
121 $this->docCommentParser->parseDocComment($this->getDocComment());
122 }
123 return $this->docCommentParser;
124 }
125 }
126
127 ?>