@@ -82,19 +82,8 @@ public function getResourceContext(string $resourceClass, int $referenceType = U
8282 {
8383 /** @var HttpOperation $operation */
8484 $ operation = $ this ->resourceMetadataFactory ->create ($ resourceClass )->getOperation (null , false , true );
85- if (null === $ shortName = $ operation ->getShortName ()) {
86- return [];
87- }
88-
89- $ context = $ operation ->getNormalizationContext ();
90- if ($ context ['iri_only ' ] ?? false ) {
91- $ context = $ this ->getBaseContext ($ referenceType );
92- $ context [$ this ->getHydraPrefix ($ context ).'member ' ]['@type ' ] = '@id ' ;
93-
94- return $ context ;
95- }
9685
97- return $ this ->getResourceContextWithShortname ( $ resourceClass , $ referenceType , $ shortName , $ operation );
86+ return $ this ->getResourceContextFromOperation ( $ operation , $ resourceClass , $ referenceType );
9887 }
9988
10089 /**
@@ -103,11 +92,8 @@ public function getResourceContext(string $resourceClass, int $referenceType = U
10392 public function getResourceContextUri (string $ resourceClass , ?int $ referenceType = null ): string
10493 {
10594 $ resourceMetadata = $ this ->resourceMetadataFactory ->create ($ resourceClass )[0 ];
106- if (null === $ referenceType ) {
107- $ referenceType = $ resourceMetadata ->getUrlGenerationStrategy ();
108- }
10995
110- return $ this ->urlGenerator -> generate ( ' api_jsonld_context ' , [ ' shortName ' => $ resourceMetadata ->getShortName ()] , $ referenceType ?? UrlGeneratorInterface:: ABS_PATH );
96+ return $ this ->generateContextUri ( $ resourceMetadata ->getShortName (), $ referenceType ?? $ resourceMetadata -> getUrlGenerationStrategy () );
11197 }
11298
11399 /**
@@ -155,12 +141,6 @@ public function getAnonymousResourceContext(object $object, array $context = [],
155141 unset($ jsonLdContext ['@context ' ]);
156142 }
157143
158- // here the object can be different from the resource given by the $context['api_resource'] value
159- // TODO: this is probably not used anymore and is slow we get that @type way earlier, remove this
160- if (isset ($ context ['api_resource ' ])) {
161- $ jsonLdContext ['@type ' ] = $ this ->resourceMetadataFactory ->create ($ this ->getObjectClass ($ context ['api_resource ' ]))[0 ]->getShortName ();
162- }
163-
164144 return $ jsonLdContext ;
165145 }
166146
@@ -169,11 +149,7 @@ public function getAnonymousResourceContext(object $object, array $context = [],
169149 */
170150 public function getResourceContextUriFromOperation (HttpOperation $ operation , ?int $ referenceType = null ): string
171151 {
172- if (null === $ referenceType ) {
173- $ referenceType = $ operation ->getUrlGenerationStrategy ();
174- }
175-
176- return $ this ->urlGenerator ->generate ('api_jsonld_context ' , ['shortName ' => $ operation ->getShortName ()], $ referenceType ?? UrlGeneratorInterface::ABS_PATH );
152+ return $ this ->generateContextUri ($ operation ->getShortName (), $ referenceType ?? $ operation ->getUrlGenerationStrategy ());
177153 }
178154
179155 /**
@@ -196,6 +172,11 @@ public function getResourceContextFromOperation(HttpOperation $operation, string
196172 return $ this ->getResourceContextWithShortname ($ resourceClass , $ referenceType , $ shortName , $ operation );
197173 }
198174
175+ private function generateContextUri (?string $ shortName , ?int $ referenceType ): string
176+ {
177+ return $ this ->urlGenerator ->generate ('api_jsonld_context ' , ['shortName ' => $ shortName ], $ referenceType ?? UrlGeneratorInterface::ABS_PATH );
178+ }
179+
199180 private function getResourceContextWithShortname (string $ resourceClass , int $ referenceType , string $ shortName , ?HttpOperation $ operation = null ): array
200181 {
201182 $ context = $ this ->getBaseContext ($ referenceType );
0 commit comments