1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\controller_annotations\Configuration; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* The ParamConverter class handles the ParamConverter annotation parts. |
7
|
|
|
* |
8
|
|
|
* @author Fabien Potencier <[email protected]> |
9
|
|
|
* @Annotation |
10
|
|
|
*/ |
11
|
|
|
class ParamConverter extends ConfigurationAnnotation |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The parameter name. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $name; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The parameter class. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $class; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* An array of options. |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $options = []; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Whether or not the parameter is optional. |
37
|
|
|
* |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
protected $optional = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Use explicitly named converter instead of iterating by priorities. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
protected $converter; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Returns the parameter name. |
51
|
|
|
* |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
7 |
|
public function getName() |
55
|
|
|
{ |
56
|
7 |
|
return $this->name; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Sets the parameter name. |
61
|
|
|
* |
62
|
|
|
* @param string $name The parameter name |
63
|
|
|
*/ |
64
|
7 |
|
public function setValue($name) |
65
|
|
|
{ |
66
|
7 |
|
$this->setName($name); |
67
|
7 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Sets the parameter name. |
71
|
|
|
* |
72
|
|
|
* @param string $name The parameter name |
73
|
|
|
*/ |
74
|
15 |
|
public function setName($name) |
75
|
|
|
{ |
76
|
15 |
|
$this->name = $name; |
77
|
15 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the parameter class name. |
81
|
|
|
* |
82
|
|
|
* @return string $name |
83
|
|
|
*/ |
84
|
9 |
|
public function getClass() |
85
|
|
|
{ |
86
|
9 |
|
return $this->class; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Sets the parameter class name. |
91
|
|
|
* |
92
|
|
|
* @param string $class The parameter class name |
93
|
|
|
*/ |
94
|
7 |
|
public function setClass($class) |
95
|
|
|
{ |
96
|
7 |
|
$this->class = $class; |
97
|
7 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Returns an array of options. |
101
|
|
|
* |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
1 |
|
public function getOptions() |
105
|
|
|
{ |
106
|
1 |
|
return $this->options; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Sets an array of options. |
111
|
|
|
* |
112
|
|
|
* @param array $options An array of options |
113
|
|
|
*/ |
114
|
7 |
|
public function setOptions($options) |
115
|
|
|
{ |
116
|
7 |
|
$this->options = $options; |
117
|
7 |
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Sets whether or not the parameter is optional. |
121
|
|
|
* |
122
|
|
|
* @param bool $optional Whether the parameter is optional |
123
|
|
|
*/ |
124
|
3 |
|
public function setIsOptional($optional) |
125
|
|
|
{ |
126
|
3 |
|
$this->optional = (bool)$optional; |
127
|
3 |
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Returns whether or not the parameter is optional. |
131
|
|
|
* |
132
|
|
|
* @return bool |
133
|
|
|
*/ |
134
|
|
|
public function isOptional() |
135
|
|
|
{ |
136
|
|
|
return $this->optional; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Get explicit converter name. |
141
|
|
|
* |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
6 |
|
public function getConverter() |
145
|
|
|
{ |
146
|
6 |
|
return $this->converter; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Set explicit converter name. |
151
|
|
|
* |
152
|
|
|
* @param string $converter |
153
|
|
|
*/ |
154
|
3 |
|
public function setConverter($converter) |
155
|
|
|
{ |
156
|
3 |
|
$this->converter = $converter; |
157
|
3 |
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Returns the annotation alias name. |
161
|
|
|
* |
162
|
|
|
* @return string |
163
|
|
|
* |
164
|
|
|
* @see ConfigurationInterface |
165
|
|
|
*/ |
166
|
1 |
|
public function getAliasName() |
167
|
|
|
{ |
168
|
1 |
|
return 'converters'; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Multiple ParamConverters are allowed. |
173
|
|
|
* |
174
|
|
|
* @return bool |
175
|
|
|
* |
176
|
|
|
* @see ConfigurationInterface |
177
|
|
|
*/ |
178
|
1 |
|
public function allowArray() |
179
|
|
|
{ |
180
|
1 |
|
return true; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|