File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1313 namespace Embryo \Http \Factory ;
1414
1515 use Embryo \Http \Message \ServerRequest ;
16- use Embryo \Http \Factory \{UploadedFileFactory , UriFactory };
16+ use Embryo \Http \Factory \{StreamFactory , UploadedFileFactory , UriFactory };
1717 use Psr \Http \Message \{ServerRequestFactoryInterface , ServerRequestInterface , UriInterface };
1818
1919 class ServerRequestFactory implements ServerRequestFactoryInterface
@@ -47,6 +47,22 @@ public function createServerRequestFromServer(): ServerRequestInterface
4747 $ request = $ request ->withParsedBody ($ _POST );
4848 $ request = $ request ->withCookieParams ($ _COOKIE );
4949 $ request = $ request ->withUploadedFiles ($ files );
50+
51+ $ contentType = $ request ->getHeaderLine ('Content-Type ' );
52+ if ($ contentType !== '' && strpos ($ contentType , 'application/json ' ) !== false ) {
53+
54+ $ streamWrite = fopen ('php://temp ' , 'w+ ' );
55+ $ streamRead = fopen ('php://input ' , 'r ' );
56+ if ($ streamWrite && $ streamRead ) {
57+ stream_copy_to_stream ($ streamRead , $ streamWrite );
58+ rewind ($ streamWrite );
59+ $ body = (new StreamFactory )->createStreamFromResource ($ streamWrite );
60+ $ params = json_decode ($ body ->getContents (), true );
61+ $ request = $ request ->withBody ($ body )->withParsedBody ($ params );
62+ }
63+ return $ request ;
64+
65+ }
5066 return $ request ;
5167 }
5268 }
You can’t perform that action at this time.
0 commit comments