12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver;
- use Psr\Http\Message\MessageInterface;
- use Psr\Http\Message\RequestInterface;
- use Psr\Http\Message\ServerRequestInterface;
- use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
- use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
- final class PsrServerRequestResolver implements ArgumentValueResolverInterface
- {
- private const SUPPORTED_TYPES = [
- ServerRequestInterface::class => true,
- RequestInterface::class => true,
- MessageInterface::class => true,
- ];
- private $httpMessageFactory;
- public function __construct(HttpMessageFactoryInterface $httpMessageFactory)
- {
- $this->httpMessageFactory = $httpMessageFactory;
- }
-
- public function supports(Request $request, ArgumentMetadata $argument): bool
- {
- return self::SUPPORTED_TYPES[$argument->getType()] ?? false;
- }
-
- public function resolve(Request $request, ArgumentMetadata $argument): \Traversable
- {
- yield $this->httpMessageFactory->createRequest($request);
- }
- }
|