7
7
use Psr \Http \Message \ServerRequestInterface ;
8
8
use UnexpectedValueException ;
9
9
use WebServCo \Data \Contract \Extraction \DataExtractionContainerInterface ;
10
+ use WebServCo \Http \Contract \Message \Request \RequestBodyServiceInterface ;
10
11
use WebServCo \Http \Contract \Message \Request \RequestHeaderServiceInterface ;
11
12
use WebServCo \JSONAPI \Contract \Document \JSONAPIInterface ;
12
13
use WebServCo \JSONAPI \Contract \Service \JSONAPIRequestServiceInterface ;
@@ -20,17 +21,11 @@ final class JSONAPIRequestService implements JSONAPIRequestServiceInterface
20
21
{
21
22
public function __construct (
22
23
private readonly DataExtractionContainerInterface $ dataExtractionContainer ,
24
+ private readonly RequestBodyServiceInterface $ requestBodyService ,
23
25
private readonly RequestHeaderServiceInterface $ requestHeaderService ,
24
26
) {
25
27
}
26
28
27
- public function contentTypeMatches (ServerRequestInterface $ request ): bool
28
- {
29
- $ contentTypeHeaderValue = $ this ->requestHeaderService ->getHeaderValue ('Content-Type ' , $ request );
30
-
31
- return $ contentTypeHeaderValue === JSONAPIInterface::MEDIA_TYPE ;
32
- }
33
-
34
29
/**
35
30
* @inheritDoc
36
31
*/
@@ -55,6 +50,18 @@ public function getRequestBodyAsArray(ServerRequestInterface $request): array
55
50
return $ array ;
56
51
}
57
52
53
+ public function validateContentType (ServerRequestInterface $ request ): bool
54
+ {
55
+ if (!$ this ->requestBodyService ->canHaveRequestBody ($ request )) {
56
+ // No request body, nothing to check.
57
+ return true ;
58
+ }
59
+
60
+ $ contentTypeHeaderValue = $ this ->requestHeaderService ->getHeaderValue ('Content-Type ' , $ request );
61
+
62
+ return $ contentTypeHeaderValue === JSONAPIInterface::MEDIA_TYPE ;
63
+ }
64
+
58
65
/**
59
66
* @inheritDoc
60
67
*/
0 commit comments