[CLEANUP] Adjust code to coding guidelines
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Reflection / PropertyReflection.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Reflection;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Extended version of the ReflectionProperty
28 */
29 class PropertyReflection extends \ReflectionProperty {
30
31 /**
32 * @var \TYPO3\CMS\Extbase\Reflection\DocCommentParser An instance of the doc comment parser
33 */
34 protected $docCommentParser;
35
36 /**
37 * The constructor, initializes the reflection class
38 *
39 * @param string $className Name of the property's class
40 * @param string $propertyName Name of the property to reflect
41 */
42 public function __construct($className, $propertyName) {
43 parent::__construct($className, $propertyName);
44 }
45
46 /**
47 * Checks if the doc comment of this property is tagged with
48 * the specified tag
49 *
50 * @param string $tag Tag name to check for
51 * @return boolean TRUE if such a tag has been defined, otherwise FALSE
52 */
53 public function isTaggedWith($tag) {
54 $result = $this->getDocCommentParser()->isTaggedWith($tag);
55 return $result;
56 }
57
58 /**
59 * Returns an array of tags and their values
60 *
61 * @return array Tags and values
62 */
63 public function getTagsValues() {
64 return $this->getDocCommentParser()->getTagsValues();
65 }
66
67 /**
68 * Returns the values of the specified tag
69 *
70 * @param string $tag
71 * @return array Values of the given tag
72 */
73 public function getTagValues($tag) {
74 return $this->getDocCommentParser()->getTagValues($tag);
75 }
76
77 /**
78 * Returns the value of the reflected property - even if it is protected.
79 *
80 * @param object $object Instance of the declaring class \TYPO3\CMS\Extbase\Reflection to read the value from
81 * @return mixed Value of the property
82 * @throws \TYPO3\CMS\Extbase\Reflection\Exception
83 * @todo Maybe support private properties as well, as of PHP 5.3.0 we can do
84 */
85 public function getValue($object = NULL) {
86 if (!is_object($object)) {
87 throw new \TYPO3\CMS\Extbase\Reflection\Exception('$object is of type ' . gettype($object) . ', instance of class ' . $this->class . ' expected.', 1210859212);
88 }
89 if ($this->isPublic()) {
90 return parent::getValue($object);
91 }
92 if ($this->isPrivate()) {
93 throw new \TYPO3\CMS\Extbase\Reflection\Exception('Cannot return value of private property "' . $this->name . '.', 1210859206);
94 }
95 parent::setAccessible(TRUE);
96 return parent::getValue($object);
97 }
98
99 /**
100 * Returns an instance of the doc comment parser and
101 * runs the parse() method.
102 *
103 * @return \TYPO3\CMS\Extbase\Reflection\DocCommentParser
104 */
105 protected function getDocCommentParser() {
106 if (!is_object($this->docCommentParser)) {
107 $this->docCommentParser = new \TYPO3\CMS\Extbase\Reflection\DocCommentParser();
108 $this->docCommentParser->parseDocComment($this->getDocComment());
109 }
110 return $this->docCommentParser;
111 }
112 }
113
114 ?>