1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 Configuration Object project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\ConfigurationObject\Reflection; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Core\Core; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* This class is used to handle the common array annotation: `\Some\Class[]`. |
20
|
|
|
* |
21
|
|
|
* Indeed, TYPO3 does only support annotations like: `\ArrayObject<\Some\Class>` |
22
|
|
|
* but this is not well supported by IDEs. |
23
|
|
|
*/ |
24
|
|
|
class ReflectionService extends \TYPO3\CMS\Extbase\Reflection\ReflectionService |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Will transform the annotation: |
28
|
|
|
* `\Some\Class[]` -> `\ArrayObject<\Some\Class> |
29
|
|
|
* |
30
|
|
|
* The last one is supported by TYPO3. See class description for more |
31
|
|
|
* information. |
32
|
|
|
* |
33
|
|
|
* @param array $varTags |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
protected function handleArrayAnnotation(array $varTags) |
37
|
|
|
{ |
38
|
|
|
foreach ($varTags as $key => $tag) { |
39
|
|
|
if ('[]' === substr($tag, -2)) { |
40
|
|
|
$class = substr($tag, 0, -2); |
41
|
|
|
|
42
|
|
|
if (Core::get()->classExists($class)) { |
43
|
|
|
$varTags[$key] = "\\ArrayObject<$class>"; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $varTags; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @inheritdoc |
53
|
|
|
*/ |
54
|
|
|
public function getPropertyTagsValues($className, $propertyName) |
55
|
|
|
{ |
56
|
|
|
$result = parent::getPropertyTagsValues($className, $propertyName); |
57
|
|
|
|
58
|
|
|
if (isset($result['var'])) { |
59
|
|
|
$result['var'] = $this->handleArrayAnnotation($result['var']); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $result; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @inheritdoc |
67
|
|
|
*/ |
68
|
|
|
public function getPropertyTagValues($className, $propertyName, $tag) |
69
|
|
|
{ |
70
|
|
|
$result = parent::getPropertyTagValues($className, $propertyName, $tag); |
71
|
|
|
|
72
|
|
|
if (isset($result['var'])) { |
73
|
|
|
$result['var'] = $this->handleArrayAnnotation($result['var']); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $result; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|