diff --git a/Slim/Middleware/MethodOverrideMiddleware.php b/Slim/Middleware/MethodOverrideMiddleware.php index a298bc495..c00a8748f 100644 --- a/Slim/Middleware/MethodOverrideMiddleware.php +++ b/Slim/Middleware/MethodOverrideMiddleware.php @@ -39,7 +39,7 @@ public function __invoke( } elseif (strtoupper($request->getMethod()) == 'POST') { $body = $request->getParsedBody(); - if (!empty($body['_METHOD'])) { + if ((is_array($body) || $body instanceof \ArrayAccess) && !empty($body['_METHOD'])) { $request = $request->withMethod($body['_METHOD']); } diff --git a/Slim/Router.php b/Slim/Router.php index 89e58fc44..83ba66540 100644 --- a/Slim/Router.php +++ b/Slim/Router.php @@ -419,7 +419,10 @@ public function relativePathFor(string $name, array $data = [], array $queryPara } if (empty($segments)) { - throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName); + if (isset($segmentName)) { + throw new InvalidArgumentException('Missing data for URL segment: ' . $segmentName); + } + throw new InvalidArgumentException(sprintf('Missing RouteData for URL with name: "%s"', $name)); } $url = implode('', $segments); diff --git a/tests/Middleware/ContentLengthMiddlewareTest.php b/tests/Middleware/ContentLengthMiddlewareTest.php index d2237c644..d31b9c3c8 100644 --- a/tests/Middleware/ContentLengthMiddlewareTest.php +++ b/tests/Middleware/ContentLengthMiddlewareTest.php @@ -22,7 +22,7 @@ class ContentLengthMiddlewareTest extends TestCase { public function testAddsContentLenght() { - $mw = new ContentLengthMiddleware('append'); + $mw = new ContentLengthMiddleware(); $uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123'); $headers = new Headers(); @@ -33,8 +33,9 @@ public function testAddsContentLenght() $response = new Response(); $next = function (ServerRequestInterface $req, ResponseInterface $res) { - $res->write('Body'); - return $res; + $body = $res->getBody(); + $body->write('Body'); + return $res->withBody($body); }; $newResponse = $mw($request, $response, $next); diff --git a/tests/Middleware/OutputBufferingMiddlewareTest.php b/tests/Middleware/OutputBufferingMiddlewareTest.php index b9b204c82..eedcf1ee5 100644 --- a/tests/Middleware/OutputBufferingMiddlewareTest.php +++ b/tests/Middleware/OutputBufferingMiddlewareTest.php @@ -55,10 +55,10 @@ public function testAppend() $response = new Response(); $next = function (ServerRequestInterface $req, ResponseInterface $res) { - $res->write('Body'); + $body = $res->getBody(); + $body->write('Body'); echo 'Test'; - - return $res; + return $res->withBody($body); }; $result = $mw($request, $response, $next); @@ -78,10 +78,10 @@ public function testPrepend() $response = new Response(); $next = function (ServerRequestInterface $req, ResponseInterface $res) { - $res->write('Body'); + $body = $res->getBody(); + $body->write('Body'); echo 'Test'; - - return $res; + return $res->withBody($body); }; $result = $mw($request, $response, $next);