@@ -61,7 +61,7 @@ public function normalize($object, $format = null, array $context = [])
61
61
foreach ($ object ->getResourceNameCollection () as $ resourceClass ) {
62
62
$ resourceMetadata = $ this ->resourceMetadataFactory ->create ($ resourceClass );
63
63
$ shortName = $ resourceMetadata ->getShortName ();
64
- $ prefixedShortName = ( null === $ iri = $ resourceMetadata ->getIri ()) ? ' # ' . $ shortName : $ iri ;
64
+ $ prefixedShortName = $ resourceMetadata ->getIri () ?? " # $ shortName" ;
65
65
66
66
$ this ->populateEntrypointProperties ($ resourceClass , $ resourceMetadata , $ shortName , $ prefixedShortName , $ entrypointProperties );
67
67
$ classes [] = $ this ->getClass ($ resourceClass , $ resourceMetadata , $ shortName , $ prefixedShortName );
@@ -92,11 +92,11 @@ private function populateEntrypointProperties(string $resourceClass, ResourceMet
92
92
'@id ' => sprintf ('#Entrypoint/%s ' , lcfirst ($ shortName )),
93
93
'@type ' => 'hydra:Link ' ,
94
94
'domain ' => '#Entrypoint ' ,
95
- 'rdfs:label ' => sprintf ( ' The collection of %s resources ' , $ shortName) ,
95
+ 'rdfs:label ' => " The collection of $ shortName resources " ,
96
96
'range ' => 'hydra:PagedCollection ' ,
97
97
'hydra:supportedOperation ' => $ hydraCollectionOperations ,
98
98
],
99
- 'hydra:title ' => sprintf ( ' The collection of %s resources ' , $ shortName) ,
99
+ 'hydra:title ' => " The collection of $ shortName resources " ,
100
100
'hydra:readable ' => true ,
101
101
'hydra:writable ' => false ,
102
102
];
@@ -231,31 +231,31 @@ private function getHydraOperation(string $resourceClass, ResourceMetadata $reso
231
231
232
232
if ('GET ' === $ method && $ collection ) {
233
233
$ hydraOperation = [
234
- 'hydra:title ' => sprintf ( ' Retrieves the collection of %s resources. ' , $ shortName ) ,
234
+ 'hydra:title ' => " Retrieves the collection of $ shortName resources. " ,
235
235
'returns ' => 'hydra:PagedCollection ' ,
236
236
] + $ hydraOperation ;
237
237
} elseif ('GET ' === $ method ) {
238
238
$ hydraOperation = [
239
- 'hydra:title ' => sprintf ( ' Retrieves %s resource. ' , $ shortName ) ,
239
+ 'hydra:title ' => " Retrieves $ shortName resource. " ,
240
240
'returns ' => $ prefixedShortName ,
241
241
] + $ hydraOperation ;
242
242
} elseif ('POST ' === $ method ) {
243
243
$ hydraOperation = [
244
244
'@type ' => 'hydra:CreateResourceOperation ' ,
245
- 'hydra:title ' => sprintf ( ' Creates a %s resource. ' , $ shortName ) ,
245
+ 'hydra:title ' => " Creates a $ shortName resource. " ,
246
246
'returns ' => $ prefixedShortName ,
247
247
'expects ' => $ prefixedShortName ,
248
248
] + $ hydraOperation ;
249
249
} elseif ('PUT ' === $ method ) {
250
250
$ hydraOperation = [
251
251
'@type ' => 'hydra:ReplaceResourceOperation ' ,
252
- 'hydra:title ' => sprintf ( ' Replaces the %s resource. ' , $ shortName ) ,
252
+ 'hydra:title ' => " Replaces the $ shortName resource. " ,
253
253
'returns ' => $ prefixedShortName ,
254
254
'expects ' => $ prefixedShortName ,
255
255
] + $ hydraOperation ;
256
256
} elseif ('DELETE ' === $ method ) {
257
257
$ hydraOperation = [
258
- 'hydra:title ' => sprintf ( ' Deletes the %s resource. ' , $ shortName ) ,
258
+ 'hydra:title ' => " Deletes the $ shortName resource. " ,
259
259
'returns ' => 'owl:Nothing ' ,
260
260
] + $ hydraOperation ;
261
261
}
@@ -318,7 +318,9 @@ private function getRange(PropertyMetadata $propertyMetadata)
318
318
}
319
319
320
320
if ($ this ->resourceClassResolver ->isResourceClass ($ className )) {
321
- return sprintf ('#%s ' , $ this ->resourceMetadataFactory ->create ($ className )->getShortName ());
321
+ $ resourceMetadata = $ this ->resourceMetadataFactory ->create ($ className );
322
+
323
+ return $ resourceMetadata ->getIri () ?? "# {$ resourceMetadata ->getShortName ()}" ;
322
324
}
323
325
break ;
324
326
}
@@ -423,12 +425,11 @@ private function getClasses(array $entrypointProperties, array $classes): array
423
425
*/
424
426
private function getProperty (PropertyMetadata $ propertyMetadata , string $ propertyName , string $ prefixedShortName , string $ shortName ): array
425
427
{
426
- $ type = $ propertyMetadata ->isReadableLink () ? 'rdf:Property ' : 'hydra:Link ' ;
427
428
$ property = [
428
429
'@type ' => 'hydra:SupportedProperty ' ,
429
430
'hydra:property ' => [
430
- '@id ' => ( $ iri = $ propertyMetadata ->getIri ()) ? $ iri : sprintf ( ' #%s/%s ' , $ shortName, $ propertyName) ,
431
- '@type ' => $ type ,
431
+ '@id ' => $ propertyMetadata ->getIri () ?? " # $ shortName/ $ propertyName" ,
432
+ '@type ' => $ propertyMetadata -> isReadableLink () ? ' rdf:Property ' : ' hydra:Link ' ,
432
433
'rdfs:label ' => $ propertyName ,
433
434
'domain ' => $ prefixedShortName ,
434
435
],
0 commit comments