[TASK] Re-work/simplify copyright header in PHP files - Part 8
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Reflection / PropertyReflection.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 ReflectionProperty
18 */
19 class PropertyReflection extends \ReflectionProperty {
20
21 /**
22 * @var \TYPO3\CMS\Extbase\Reflection\DocCommentParser An instance of the doc comment parser
23 */
24 protected $docCommentParser;
25
26 /**
27 * The constructor, initializes the reflection class
28 *
29 * @param string $className Name of the property's class
30 * @param string $propertyName Name of the property to reflect
31 */
32 public function __construct($className, $propertyName) {
33 parent::__construct($className, $propertyName);
34 }
35
36 /**
37 * Checks if the doc comment of this property is tagged with
38 * the specified tag
39 *
40 * @param string $tag Tag name to check for
41 * @return boolean TRUE if such a tag has been defined, otherwise FALSE
42 */
43 public function isTaggedWith($tag) {
44 $result = $this->getDocCommentParser()->isTaggedWith($tag);
45 return $result;
46 }
47
48 /**
49 * Returns an array of tags and their values
50 *
51 * @return array Tags and values
52 */
53 public function getTagsValues() {
54 return $this->getDocCommentParser()->getTagsValues();
55 }
56
57 /**
58 * Returns the values of the specified tag
59 *
60 * @param string $tag
61 * @return array Values of the given tag
62 */
63 public function getTagValues($tag) {
64 return $this->getDocCommentParser()->getTagValues($tag);
65 }
66
67 /**
68 * Returns the value of the reflected property - even if it is protected.
69 *
70 * @param object $object Instance of the declaring class \TYPO3\CMS\Extbase\Reflection to read the value from
71 * @return mixed Value of the property
72 * @throws \TYPO3\CMS\Extbase\Reflection\Exception
73 * @todo Maybe support private properties as well, as of PHP 5.3.0 we can do
74 */
75 public function getValue($object = NULL) {
76 if (!is_object($object)) {
77 throw new \TYPO3\CMS\Extbase\Reflection\Exception('$object is of type ' . gettype($object) . ', instance of class ' . $this->class . ' expected.', 1210859212);
78 }
79 if ($this->isPublic()) {
80 return parent::getValue($object);
81 }
82 if ($this->isPrivate()) {
83 throw new \TYPO3\CMS\Extbase\Reflection\Exception('Cannot return value of private property "' . $this->name . '.', 1210859206);
84 }
85 parent::setAccessible(TRUE);
86 return parent::getValue($object);
87 }
88
89 /**
90 * Returns an instance of the doc comment parser and
91 * runs the parse() method.
92 *
93 * @return \TYPO3\CMS\Extbase\Reflection\DocCommentParser
94 */
95 protected function getDocCommentParser() {
96 if (!is_object($this->docCommentParser)) {
97 $this->docCommentParser = new \TYPO3\CMS\Extbase\Reflection\DocCommentParser();
98 $this->docCommentParser->parseDocComment($this->getDocComment());
99 }
100 return $this->docCommentParser;
101 }
102 }