f5ce9f39a1a77cacd3ac555872d85f9c3deb28a3
[yaffs-website] / web / core / lib / Drupal / Core / Controller / ArgumentResolver / Psr7RequestValueResolver.php
1 <?php
2
3 namespace Drupal\Core\Controller\ArgumentResolver;
4
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 /**
12  * Yields a PSR7 request object based on the request object passed along.
13  */
14 final class Psr7RequestValueResolver implements ArgumentValueResolverInterface {
15
16   /**
17    * The PSR-7 converter.
18    *
19    * @var \Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface
20    */
21   protected $httpMessageFactory;
22
23   /**
24    * Constructs a new ControllerResolver.
25    *
26    * @param \Symfony\Bridge\PsrHttpMessage\HttpMessageFactoryInterface $http_message_factory
27    *   The PSR-7 converter.
28    */
29   public function __construct(HttpMessageFactoryInterface $http_message_factory) {
30     $this->httpMessageFactory = $http_message_factory;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function supports(Request $request, ArgumentMetadata $argument) {
37     return $argument->getType() == ServerRequestInterface::class;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function resolve(Request $request, ArgumentMetadata $argument) {
44     yield $this->httpMessageFactory->createRequest($request);
45   }
46
47 }