vendor/friendsofsymfony/rest-bundle/EventListener/VersionExclusionListener.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the FOSRestBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\RestBundle\EventListener;
  11. use FOS\RestBundle\FOSRestBundle;
  12. use FOS\RestBundle\View\ConfigurableViewHandlerInterface;
  13. use FOS\RestBundle\View\ViewHandlerInterface;
  14. use Symfony\Component\HttpKernel\Event\RequestEvent;
  15. /**
  16. * @internal
  17. */
  18. class VersionExclusionListener
  19. {
  20. private $viewHandler;
  21. public function __construct(ViewHandlerInterface $viewHandler)
  22. {
  23. $this->viewHandler = $viewHandler;
  24. }
  25. public function onKernelRequest(RequestEvent $event): void
  26. {
  27. $request = $event->getRequest();
  28. if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
  29. return;
  30. }
  31. if (!$request->attributes->has('version')) {
  32. return;
  33. }
  34. $version = $request->attributes->get('version');
  35. if ($this->viewHandler instanceof ConfigurableViewHandlerInterface) {
  36. $this->viewHandler->setExclusionStrategyVersion($version);
  37. }
  38. }
  39. }