1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the API Platform project. |
5
|
|
|
* |
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace ApiPlatform\Core\Annotation; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Exception\InvalidArgumentException; |
17
|
|
|
use Doctrine\Common\Util\Inflector; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* ApiResource annotation. |
21
|
|
|
* |
22
|
|
|
* @author Kévin Dunglas <[email protected]> |
23
|
|
|
* |
24
|
|
|
* @Annotation |
25
|
|
|
* @Target({"CLASS"}) |
26
|
|
|
* @Attributes( |
27
|
|
|
* @Attribute("accessControl", type="string"), |
28
|
|
|
* @Attribute("accessControlMessage", type="string"), |
29
|
|
|
* @Attribute("attributes", type="array"), |
30
|
|
|
* @Attribute("collectionOperations", type="array"), |
31
|
|
|
* @Attribute("denormalizationContext", type="array"), |
32
|
|
|
* @Attribute("description", type="string"), |
33
|
|
|
* @Attribute("fetchPartial", type="bool"), |
34
|
|
|
* @Attribute("forceEager", type="bool"), |
35
|
|
|
* @Attribute("filters", type="string[]"), |
36
|
|
|
* @Attribute("graphql", type="array"), |
37
|
|
|
* @Attribute("iri", type="string"), |
38
|
|
|
* @Attribute("itemOperations", type="array"), |
39
|
|
|
* @Attribute("maximumItemsPerPage", type="int"), |
40
|
|
|
* @Attribute("normalizationContext", type="array"), |
41
|
|
|
* @Attribute("order", type="array"), |
42
|
|
|
* @Attribute("paginationClientEnabled", type="bool"), |
43
|
|
|
* @Attribute("paginationClientItemsPerPage", type="bool"), |
44
|
|
|
* @Attribute("paginationClientPartial", type="bool"), |
45
|
|
|
* @Attribute("paginationEnabled", type="bool"), |
46
|
|
|
* @Attribute("paginationFetchJoinCollection", type="bool"), |
47
|
|
|
* @Attribute("paginationItemsPerPage", type="int"), |
48
|
|
|
* @Attribute("paginationPartial", type="bool"), |
49
|
|
|
* @Attribute("routePrefix", type="string"), |
50
|
|
|
* @Attribute("shortName", type="string"), |
51
|
|
|
* @Attribute("subresourceOperations", type="array"), |
52
|
|
|
* @Attribute("validationGroups", type="mixed") |
53
|
|
|
* ) |
54
|
|
|
*/ |
55
|
|
|
final class ApiResource |
56
|
|
|
{ |
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
public $shortName; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
public $description; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
public $iri; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var array |
74
|
|
|
*/ |
75
|
|
|
public $itemOperations; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var array |
79
|
|
|
*/ |
80
|
|
|
public $collectionOperations; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var array |
84
|
|
|
*/ |
85
|
|
|
public $subresourceOperations; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var array |
89
|
|
|
*/ |
90
|
|
|
public $graphql; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var array |
94
|
|
|
*/ |
95
|
|
|
public $attributes = []; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
99
|
|
|
* |
100
|
|
|
* @var string |
101
|
|
|
*/ |
102
|
|
|
private $accessControl; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
106
|
|
|
* |
107
|
|
|
* @var string |
108
|
|
|
*/ |
109
|
|
|
private $accessControlMessage; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
113
|
|
|
* |
114
|
|
|
* @var array |
115
|
|
|
*/ |
116
|
|
|
private $denormalizationContext; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
120
|
|
|
* |
121
|
|
|
* @var bool |
122
|
|
|
*/ |
123
|
|
|
private $fetchPartial; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
127
|
|
|
* |
128
|
|
|
* @var bool |
129
|
|
|
*/ |
130
|
|
|
private $forceEager; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
134
|
|
|
* |
135
|
|
|
* @var string[] |
136
|
|
|
*/ |
137
|
|
|
private $filters; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
141
|
|
|
* |
142
|
|
|
* @var int |
143
|
|
|
*/ |
144
|
|
|
private $maximumItemsPerPage; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
148
|
|
|
* |
149
|
|
|
* @var array |
150
|
|
|
*/ |
151
|
|
|
private $normalizationContext; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
155
|
|
|
* |
156
|
|
|
* @var array |
157
|
|
|
*/ |
158
|
|
|
private $order; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
162
|
|
|
* |
163
|
|
|
* @var bool |
164
|
|
|
*/ |
165
|
|
|
private $paginationClientEnabled; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
169
|
|
|
* |
170
|
|
|
* @var bool |
171
|
|
|
*/ |
172
|
|
|
private $paginationClientItemsPerPage; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
176
|
|
|
* |
177
|
|
|
* @var bool |
178
|
|
|
*/ |
179
|
|
|
private $paginationClientPartial; |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
183
|
|
|
* |
184
|
|
|
* @var bool |
185
|
|
|
*/ |
186
|
|
|
private $paginationEnabled; |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
190
|
|
|
* |
191
|
|
|
* @var bool |
192
|
|
|
*/ |
193
|
|
|
private $paginationFetchJoinCollection; |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
197
|
|
|
* |
198
|
|
|
* @var int |
199
|
|
|
*/ |
200
|
|
|
private $paginationItemsPerPage; |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
204
|
|
|
* |
205
|
|
|
* @var int |
206
|
|
|
*/ |
207
|
|
|
private $paginationPartial; |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
211
|
|
|
* |
212
|
|
|
* @var string |
213
|
|
|
*/ |
214
|
|
|
private $routePrefix; |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @see https://github.com/Haehnchen/idea-php-annotation-plugin/issues/112 |
218
|
|
|
* |
219
|
|
|
* @var mixed |
220
|
|
|
*/ |
221
|
|
|
private $validationGroups; |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @throws InvalidArgumentException |
225
|
|
|
*/ |
226
|
|
|
public function __construct(array $values = []) |
227
|
|
|
{ |
228
|
|
|
if (isset($values['attributes'])) { |
229
|
|
|
$this->attributes = $values['attributes']; |
230
|
|
|
unset($values['attributes']); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
foreach ($values as $key => $value) { |
234
|
|
|
if (!property_exists($this, $key)) { |
235
|
|
|
throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, self::class)); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
$property = new \ReflectionProperty($this, $key); |
239
|
|
|
|
240
|
|
|
if ($property->isPublic()) { |
241
|
|
|
$this->$key = $value; |
242
|
|
|
} else { |
243
|
|
|
$this->attributes += [Inflector::tableize($key) => $value]; |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
} |
247
|
|
|
} |
248
|
|
|
|