@@ -1498,6 +1498,11 @@ public function createRequest(string $method, $uri): RequestInterface
1498
1498
1499
1499
public function createResponse (int $ code = 200 , string $ reasonPhrase = '' ): ResponseInterface
1500
1500
{
1501
+ if (2 > \func_num_args ()) {
1502
+ // This will make the Response class to use a custom reasonPhrase
1503
+ $ reasonPhrase = null ;
1504
+ }
1505
+
1501
1506
return new Response ($ code , [], null , '1.1 ' , $ reasonPhrase );
1502
1507
}
1503
1508
@@ -1951,7 +1956,7 @@ public function __construct(int $status = 200, array $headers = [], $body = null
1951
1956
if (null === $ reason && isset (self ::PHRASES [$ this ->statusCode ])) {
1952
1957
$ this ->reasonPhrase = self ::PHRASES [$ status ];
1953
1958
} else {
1954
- $ this ->reasonPhrase = $ reason ;
1959
+ $ this ->reasonPhrase = $ reason ?? '' ;
1955
1960
}
1956
1961
1957
1962
$ this ->protocol = $ version ;
@@ -2226,7 +2231,7 @@ public static function create($body = ''): StreamInterface
2226
2231
$ new = new self ();
2227
2232
$ new ->stream = $ body ;
2228
2233
$ meta = \stream_get_meta_data ($ new ->stream );
2229
- $ new ->seekable = $ meta ['seekable ' ];
2234
+ $ new ->seekable = $ meta ['seekable ' ] && 0 === \fseek ( $ new -> stream , 0 , \ SEEK_CUR ) ;
2230
2235
$ new ->readable = isset (self ::READ_WRITE_HASH ['read ' ][$ meta ['mode ' ]]);
2231
2236
$ new ->writable = isset (self ::READ_WRITE_HASH ['write ' ][$ meta ['mode ' ]]);
2232
2237
$ new ->uri = $ new ->getMetadata ('uri ' );
@@ -2854,8 +2859,8 @@ private function filterPort($port) /*:?int*/
2854
2859
}
2855
2860
2856
2861
$ port = (int ) $ port ;
2857
- if (1 > $ port || 0xffff < $ port ) {
2858
- throw new \InvalidArgumentException (\sprintf ('Invalid port: %d. Must be between 1 and 65535 ' , $ port ));
2862
+ if (0 > $ port || 0xffff < $ port ) {
2863
+ throw new \InvalidArgumentException (\sprintf ('Invalid port: %d. Must be between 0 and 65535 ' , $ port ));
2859
2864
}
2860
2865
2861
2866
return self ::isNonStandardPort ($ this ->scheme , $ port ) ? $ port : null ;
@@ -10130,7 +10135,7 @@ private function addParsedBody(ServerRequestInterface $request): ServerRequestIn
10130
10135
{
10131
10136
$ parsedBody = $ request ->getParsedBody ();
10132
10137
if ($ parsedBody ) {
10133
- $ request = $ this ->applySlim3Hack ($ request );
10138
+ $ request = $ this ->applySlimHack ($ request );
10134
10139
} else {
10135
10140
$ body = $ request ->getBody ();
10136
10141
if ($ body ->isReadable ()) {
@@ -10150,9 +10155,10 @@ private function addParsedBody(ServerRequestInterface $request): ServerRequestIn
10150
10155
return $ request ;
10151
10156
}
10152
10157
10153
- private function applySlim3Hack (ServerRequestInterface $ request ): ServerRequestInterface
10158
+ private function applySlimHack (ServerRequestInterface $ request ): ServerRequestInterface
10154
10159
{
10155
- if (get_class ($ request ) == 'Slim\Http\Request ' ) {
10160
+ $ class = get_class ($ request );
10161
+ if (substr ($ class , 0 , 9 ) == 'Slim\Http ' ) {
10156
10162
$ parsedBody = $ request ->getParsedBody ();
10157
10163
$ contents = json_encode ($ parsedBody );
10158
10164
$ parsedBody = $ this ->parseBody ($ contents );
@@ -10622,6 +10628,7 @@ public static function toString(ResponseInterface $response): string
10622
10628
'username ' => 'php-crud-api ' ,
10623
10629
'password ' => 'php-crud-api ' ,
10624
10630
'database ' => 'php-crud-api ' ,
10631
+ 'controllers ' => 'records,columns '
10625
10632
]);
10626
10633
$ request = RequestFactory::fromGlobals ();
10627
10634
$ api = new Api ($ config );
0 commit comments