1
|
|
|
<?php |
2
|
|
|
namespace Romm\ConfigurationObject\Legacy\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
|
|
|
/** |
18
|
|
|
* Extended version of the ReflectionProperty |
19
|
|
|
*/ |
20
|
|
|
class PropertyReflection extends \ReflectionProperty |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var DocCommentParser An instance of the doc comment parser |
24
|
|
|
*/ |
25
|
|
|
protected $docCommentParser; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Checks if the doc comment of this property is tagged with |
29
|
|
|
* the specified tag |
30
|
|
|
* |
31
|
|
|
* @param string $tag Tag name to check for |
32
|
|
|
* @return bool TRUE if such a tag has been defined, otherwise FALSE |
33
|
|
|
*/ |
34
|
|
|
public function isTaggedWith($tag) |
35
|
|
|
{ |
36
|
|
|
$result = $this->getDocCommentParser()->isTaggedWith($tag); |
37
|
|
|
return $result; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns an array of tags and their values |
42
|
|
|
* |
43
|
|
|
* @return array Tags and values |
44
|
|
|
*/ |
45
|
|
|
public function getTagsValues() |
46
|
|
|
{ |
47
|
|
|
return $this->getDocCommentParser()->getTagsValues(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns the values of the specified tag |
52
|
|
|
* |
53
|
|
|
* @param string $tag |
54
|
|
|
* @return array Values of the given tag |
55
|
|
|
*/ |
56
|
|
|
public function getTagValues($tag) |
57
|
|
|
{ |
58
|
|
|
return $this->getDocCommentParser()->getTagValues($tag); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the value of the reflected property - even if it is protected. |
63
|
|
|
* |
64
|
|
|
* @param object $object Instance of the declaring class \TYPO3\CMS\Extbase\Reflection to read the value from |
65
|
|
|
* @return mixed Value of the property |
66
|
|
|
* @throws Exception |
67
|
|
|
* @todo Maybe support private properties as well, as of PHP 5.3.0 we can do |
68
|
|
|
*/ |
69
|
|
|
public function getValue($object = null) |
70
|
|
|
{ |
71
|
|
|
if (!is_object($object)) { |
72
|
|
|
throw new Exception('$object is of type ' . gettype($object) . ', instance of class ' . $this->class . ' expected.', 1210859212); |
73
|
|
|
} |
74
|
|
|
if ($this->isPublic()) { |
75
|
|
|
return parent::getValue($object); |
76
|
|
|
} |
77
|
|
|
if ($this->isPrivate()) { |
78
|
|
|
throw new Exception('Cannot return value of private property "' . $this->name . '.', 1210859206); |
79
|
|
|
} |
80
|
|
|
parent::setAccessible(true); |
|
|
|
|
81
|
|
|
return parent::getValue($object); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns an instance of the doc comment parser and |
86
|
|
|
* runs the parse() method. |
87
|
|
|
* |
88
|
|
|
* @return DocCommentParser |
89
|
|
|
*/ |
90
|
|
|
protected function getDocCommentParser() |
91
|
|
|
{ |
92
|
|
|
if (!is_object($this->docCommentParser)) { |
93
|
|
|
$this->docCommentParser = new DocCommentParser(); |
94
|
|
|
$this->docCommentParser->parseDocComment($this->getDocComment()); |
95
|
|
|
} |
96
|
|
|
return $this->docCommentParser; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.