1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Codeburner Framework. |
5
|
|
|
* |
6
|
|
|
* @author Alex Rohleder <[email protected]> |
7
|
|
|
* @copyright 2016 Alex Rohleder |
8
|
|
|
* @license http://opensource.org/licenses/MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Codeburner\Annotator; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* The annotation representation. |
15
|
|
|
* |
16
|
|
|
* @author Alex Rohleder <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class Annotation |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The annotation token. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
protected $name; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Formmated arguments, but not casted. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
|
36
|
|
|
protected $arguments; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param string $name |
40
|
|
|
* @param string $arguments |
41
|
|
|
*/ |
42
|
|
|
|
43
|
|
|
public function __construct($name, $arguments) |
44
|
|
|
{ |
45
|
|
|
$this->name = $name; |
46
|
|
|
|
47
|
|
|
if (strpos($arguments, "{") === 0) { |
48
|
|
|
$this->arguments = json_decode($arguments, true); |
|
|
|
|
49
|
|
|
} else $this->arguments = (array) trim($arguments); |
50
|
|
|
|
51
|
|
|
$this->filter(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
|
58
|
|
|
public function getName() |
59
|
|
|
{ |
60
|
|
|
return $this->name; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
|
67
|
|
|
public function getArguments() |
68
|
|
|
{ |
69
|
|
|
return $this->arguments; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
|
76
|
|
|
public function getArgument($name) |
77
|
|
|
{ |
78
|
|
|
return isset($this->arguments[$name]) ? $this->arguments[$name] : null; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
|
85
|
|
|
public function getArgumentCount() |
86
|
|
|
{ |
87
|
|
|
return count($this->arguments); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return boolean |
92
|
|
|
*/ |
93
|
|
|
|
94
|
|
|
public function hasArgument($name) |
95
|
|
|
{ |
96
|
|
|
return isset($this->arguments[$name]); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Overwrite this method to parse and validate the arguments in a |
101
|
|
|
* new Annotation definition. |
102
|
|
|
* |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
|
106
|
|
|
protected function filter() |
107
|
|
|
{ |
108
|
|
|
// void |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function __toString() |
112
|
|
|
{ |
113
|
|
|
if (count($this->arguments) === 1) { |
114
|
|
|
return (string) $this->arguments[0]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
throw new Exceptions\AnnotationException("The annotation cannot be converted to string."); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..