@@ -53,15 +53,19 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName
53
53
*/
54
54
public function getAnnotations (): array
55
55
{
56
- $ hydraDoc = $ this ->documentationNormalizer ->normalize (new Documentation ($ this ->resourceNameCollectionFactory ->create ()));
57
- $ entrypointHydraDoc = $ this ->getResourceHydraDoc ($ hydraDoc , '#Entrypoint ' );
56
+ $ resourceNameCollection = $ this ->resourceNameCollectionFactory ->create ();
57
+ $ hydraDoc = $ this ->documentationNormalizer ->normalize (new Documentation ($ resourceNameCollection ));
58
+ if (empty ($ hydraDoc )) {
59
+ return [];
60
+ }
58
61
59
- if (empty ($ hydraDoc ) || null === $ entrypointHydraDoc ) {
62
+ $ entrypointHydraDoc = $ this ->getResourceHydraDoc ($ hydraDoc , '#Entrypoint ' );
63
+ if (null === $ entrypointHydraDoc ) {
60
64
return [];
61
65
}
62
66
63
67
$ annotations = [];
64
- foreach ($ this -> resourceNameCollectionFactory -> create () as $ resourceClass ) {
68
+ foreach ($ resourceNameCollection as $ resourceClass ) {
65
69
$ resourceMetadata = $ this ->resourceMetadataFactory ->create ($ resourceClass );
66
70
67
71
$ prefixedShortName = ($ iri = $ resourceMetadata ->getIri ()) ? $ iri : '# ' .$ resourceMetadata ->getShortName ();
@@ -112,9 +116,9 @@ private function getApiDoc(bool $collection, string $resourceClass, ResourceMeta
112
116
113
117
$ data = [
114
118
'resource ' => $ route ->getPath (),
115
- 'description ' => $ operationHydraDoc ['hydra:title ' ],
116
- 'resourceDescription ' => $ resourceHydraDoc ['hydra:title ' ],
117
- 'section ' => $ resourceHydraDoc ['hydra:title ' ],
119
+ 'description ' => $ operationHydraDoc ['hydra:title ' ] ?? '' ,
120
+ 'resourceDescription ' => $ resourceHydraDoc ['hydra:title ' ] ?? '' ,
121
+ 'section ' => $ resourceHydraDoc ['hydra:title ' ] ?? '' ,
118
122
];
119
123
120
124
if (isset ($ operationHydraDoc ['expects ' ]) && 'owl:Nothing ' !== $ operationHydraDoc ['expects ' ]) {
@@ -154,11 +158,17 @@ private function getApiDoc(bool $collection, string $resourceClass, ResourceMeta
154
158
*/
155
159
private function getResourceHydraDoc (array $ hydraApiDoc , string $ prefixedShortName )
156
160
{
161
+ if (!isset ($ hydraApiDoc ['hydra:supportedClass ' ]) || !is_array ($ hydraApiDoc ['hydra:supportedClass ' ])) {
162
+ return null ;
163
+ }
164
+
157
165
foreach ($ hydraApiDoc ['hydra:supportedClass ' ] as $ supportedClass ) {
158
- if ($ supportedClass ['@id ' ] === $ prefixedShortName ) {
166
+ if (isset ( $ supportedClass [ ' @id ' ]) && $ supportedClass ['@id ' ] === $ prefixedShortName ) {
159
167
return $ supportedClass ;
160
168
}
161
169
}
170
+
171
+ return null ;
162
172
}
163
173
164
174
/**
@@ -167,15 +177,21 @@ private function getResourceHydraDoc(array $hydraApiDoc, string $prefixedShortNa
167
177
* @param string $method
168
178
* @param array $hydraDoc
169
179
*
170
- * @return array|null
180
+ * @return array
171
181
*/
172
- private function getOperationHydraDoc (string $ method , array $ hydraDoc )
182
+ private function getOperationHydraDoc (string $ method , array $ hydraDoc ): array
173
183
{
184
+ if (!isset ($ hydraDoc ['hydra:supportedOperation ' ]) || !is_array ($ hydraDoc ['hydra:supportedOperation ' ])) {
185
+ return [];
186
+ }
187
+
174
188
foreach ($ hydraDoc ['hydra:supportedOperation ' ] as $ supportedOperation ) {
175
189
if ($ supportedOperation ['hydra:method ' ] === $ method ) {
176
190
return $ supportedOperation ;
177
191
}
178
192
}
193
+
194
+ return [];
179
195
}
180
196
181
197
/**
@@ -185,17 +201,23 @@ private function getOperationHydraDoc(string $method, array $hydraDoc)
185
201
* @param string $method
186
202
* @param array $hydraEntrypointDoc
187
203
*
188
- * @return array|null
204
+ * @return array
189
205
*/
190
- private function getCollectionOperationHydraDoc (string $ shortName , string $ method , array $ hydraEntrypointDoc )
206
+ private function getCollectionOperationHydraDoc (string $ shortName , string $ method , array $ hydraEntrypointDoc ): array
191
207
{
208
+ if (!isset ($ hydraEntrypointDoc ['hydra:supportedProperty ' ]) || !is_array ($ hydraEntrypointDoc ['hydra:supportedProperty ' ])) {
209
+ return [];
210
+ }
211
+
192
212
$ propertyName = '#Entrypoint/ ' .lcfirst ($ shortName );
193
213
194
214
foreach ($ hydraEntrypointDoc ['hydra:supportedProperty ' ] as $ supportedProperty ) {
195
- $ hydraProperty = $ supportedProperty ['hydra:property ' ];
196
- if ( $ hydraProperty ['@id ' ] === $ propertyName ) {
197
- return $ this ->getOperationHydraDoc ($ method , $ hydraProperty );
215
+ if ( isset ( $ supportedProperty ['hydra:property ' ][ ' @id ' ])
216
+ && $ supportedProperty [ ' hydra:property ' ] ['@id ' ] === $ propertyName ) {
217
+ return $ this ->getOperationHydraDoc ($ method , $ supportedProperty [ ' hydra:property ' ] );
198
218
}
199
219
}
220
+
221
+ return [];
200
222
}
201
223
}
0 commit comments