Open MrPropre opened 1 year ago
Please show a reproducible example of this with code with a minimal app setup.
I can confirm that issue. Here is a minimal app:
<?php
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\UriInterface;
use Slim\Factory\AppFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
$app->get('/', function (ServerRequestInterface $request, ResponseInterface $response) {
$response->getBody()->write('Hello world!');
return $response;
});
$app->add(ExampleMiddleware::class);
final class ExampleMiddleware implements MiddlewareInterface
{
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
$response = $handler->handle($request);
// Fatal error: Uncaught Error: Call to undefined method Slim\Psr7\Uri::getBaseUrl()
return $response->withJson(['url' => $request->getUri()->getBaseUrl()]);
}
}
$app->run();
Error message:
Fatal error: Uncaught Error: Call to undefined method Slim\Psr7\Uri::getBaseUrl()
The request and the response object is decorated, but the Uri is not decorated.
var_dump($request); // Slim\Http\ServerRequest
$response = $handler->handle($request);
var_dump($response); // Slim\Http\Response
$uri = $request->getUri();
var_dump($uri); // Slim\Psr7\Uri
Hello,
I wanted to use
Uri::getBaseUrl
from the decorated UriInterface but it is not defined. When I use$request->getUri()
, the returned object is an instance ofSlim/Psr7/Uri
, I think it should beSlim/Http/Uri
instead.Thank you in advance !