-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uri is not decorated #213
Comments
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:
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 !
The text was updated successfully, but these errors were encountered: