@@ -7452,9 +7452,38 @@ public function __construct(Config $config)
74527452 $ this ->debug = $ config ->getDebug ();
74537453 }
74547454
7455+ private function parseBody (string $ body ) /*: ?object*/
7456+ {
7457+ $ first = substr ($ body , 0 , 1 );
7458+ if ($ first == '[ ' || $ first == '{ ' ) {
7459+ $ object = json_decode ($ body );
7460+ $ causeCode = json_last_error ();
7461+ if ($ causeCode !== JSON_ERROR_NONE ) {
7462+ $ object = null ;
7463+ }
7464+ } else {
7465+ parse_str ($ body , $ input );
7466+ foreach ($ input as $ key => $ value ) {
7467+ if (substr ($ key , -9 ) == '__is_null ' ) {
7468+ $ input [substr ($ key , 0 , -9 )] = null ;
7469+ unset($ input [$ key ]);
7470+ }
7471+ }
7472+ $ object = (object ) $ input ;
7473+ }
7474+ return $ object ;
7475+ }
7476+
74557477 public function handle (ServerRequestInterface $ request ): ResponseInterface
74567478 {
74577479 $ response = null ;
7480+ $ body = $ request ->getBody ();
7481+ if ($ body ->isReadable () && $ body ->isSeekable ()) {
7482+ $ contents = $ body ->getContents ();
7483+ $ body ->rewind ();
7484+ $ parsedBody = $ this ->parseBody ($ contents );
7485+ $ request = $ request ->withParsedBody ($ parsedBody );
7486+ }
74587487 try {
74597488 $ response = $ this ->router ->route ($ request );
74607489 } catch (\Throwable $ e ) {
@@ -7636,37 +7665,13 @@ public function getOpenApiBase(): array
76367665
76377666class RequestFactory
76387667{
7639- private static function parseBody (string $ body ) /*: ?object*/
7640- {
7641- $ first = substr ($ body , 0 , 1 );
7642- if ($ first == '[ ' || $ first == '{ ' ) {
7643- $ object = json_decode ($ body );
7644- $ causeCode = json_last_error ();
7645- if ($ causeCode !== JSON_ERROR_NONE ) {
7646- $ object = null ;
7647- }
7648- } else {
7649- parse_str ($ body , $ input );
7650- foreach ($ input as $ key => $ value ) {
7651- if (substr ($ key , -9 ) == '__is_null ' ) {
7652- $ input [substr ($ key , 0 , -9 )] = null ;
7653- unset($ input [$ key ]);
7654- }
7655- }
7656- $ object = (object ) $ input ;
7657- }
7658- return $ object ;
7659- }
7660-
76617668 public static function fromGlobals (): ServerRequestInterface
76627669 {
76637670 $ psr17Factory = new Psr17Factory ();
76647671 $ creator = new ServerRequestCreator ($ psr17Factory , $ psr17Factory , $ psr17Factory , $ psr17Factory );
76657672 $ serverRequest = $ creator ->fromGlobals ();
7666- $ body = file_get_contents ('php://input ' );
7667- if ($ body ) {
7668- $ serverRequest = $ serverRequest ->withParsedBody (self ::parseBody ($ body ));
7669- }
7673+ $ stream = $ psr17Factory ->createStreamFromResource ('php://input ' );
7674+ $ serverRequest = $ serverRequest ->withBody ($ stream );
76707675 return $ serverRequest ;
76717676 }
76727677
@@ -7689,7 +7694,6 @@ public static function fromString(string $request): ServerRequestInterface
76897694 $ stream = $ psr17Factory ->createStream ($ body );
76907695 $ stream ->rewind ();
76917696 $ serverRequest = $ serverRequest ->withBody ($ stream );
7692- $ serverRequest = $ serverRequest ->withParsedBody (self ::parseBody ($ body ));
76937697 }
76947698 return $ serverRequest ;
76957699 }
0 commit comments