截流自动化的商城平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PsrServerRequestResolver.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Symfony\Bridge\PsrHttpMessage\ArgumentValueResolver;
  3. use Psr\Http\Message\MessageInterface;
  4. use Psr\Http\Message\RequestInterface;
  5. use Psr\Http\Message\ServerRequestInterface;
  6. use Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
  9. use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
  10. /**
  11. * Injects the RequestInterface, MessageInterface or ServerRequestInterface when requested.
  12. *
  13. * @author Iltar van der Berg <kjarli@gmail.com>
  14. * @author Alexander M. Turek <me@derrabus.de>
  15. */
  16. final class PsrServerRequestResolver implements ArgumentValueResolverInterface
  17. {
  18. private const SUPPORTED_TYPES = [
  19. ServerRequestInterface::class => true,
  20. RequestInterface::class => true,
  21. MessageInterface::class => true,
  22. ];
  23. private $httpMessageFactory;
  24. public function __construct(HttpMessageFactoryInterface $httpMessageFactory)
  25. {
  26. $this->httpMessageFactory = $httpMessageFactory;
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function supports(Request $request, ArgumentMetadata $argument): bool
  32. {
  33. return self::SUPPORTED_TYPES[$argument->getType()] ?? false;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function resolve(Request $request, ArgumentMetadata $argument): \Traversable
  39. {
  40. yield $this->httpMessageFactory->createRequest($request);
  41. }
  42. }