@@ -7452,9 +7452,38 @@ public function __construct(Config $config)
7452
7452
$ this ->debug = $ config ->getDebug ();
7453
7453
}
7454
7454
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
+
7455
7477
public function handle (ServerRequestInterface $ request ): ResponseInterface
7456
7478
{
7457
7479
$ 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
+ }
7458
7487
try {
7459
7488
$ response = $ this ->router ->route ($ request );
7460
7489
} catch (\Throwable $ e ) {
@@ -7636,37 +7665,13 @@ public function getOpenApiBase(): array
7636
7665
7637
7666
class RequestFactory
7638
7667
{
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
-
7661
7668
public static function fromGlobals (): ServerRequestInterface
7662
7669
{
7663
7670
$ psr17Factory = new Psr17Factory ();
7664
7671
$ creator = new ServerRequestCreator ($ psr17Factory , $ psr17Factory , $ psr17Factory , $ psr17Factory );
7665
7672
$ 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 );
7670
7675
return $ serverRequest ;
7671
7676
}
7672
7677
@@ -7689,7 +7694,6 @@ public static function fromString(string $request): ServerRequestInterface
7689
7694
$ stream = $ psr17Factory ->createStream ($ body );
7690
7695
$ stream ->rewind ();
7691
7696
$ serverRequest = $ serverRequest ->withBody ($ stream );
7692
- $ serverRequest = $ serverRequest ->withParsedBody (self ::parseBody ($ body ));
7693
7697
}
7694
7698
return $ serverRequest ;
7695
7699
}
0 commit comments