vendor/friendsofsymfony/rest-bundle/EventListener/MimeTypeListener.php line 39

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 Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpKernel\Event\RequestEvent;
  14. use Symfony\Component\HttpKernel\HttpKernelInterface;
  15. /**
  16.  * This listener handles registering custom mime types.
  17.  *
  18.  * @author Lukas Kahwe Smith <smith@pooteeweet.org>
  19.  *
  20.  * @internal
  21.  */
  22. class MimeTypeListener
  23. {
  24.     private $mimeTypes;
  25.     /**
  26.      * @param array $mimeTypes An array with the format as key and
  27.      *                         the corresponding mime type as value
  28.      */
  29.     public function __construct(array $mimeTypes)
  30.     {
  31.         $this->mimeTypes $mimeTypes;
  32.     }
  33.     public function onKernelRequest(RequestEvent $event): void
  34.     {
  35.         $request $event->getRequest();
  36.         if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTEtrue)) {
  37.             return;
  38.         }
  39.         if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
  40.             foreach ($this->mimeTypes as $format => $mimeTypes) {
  41.                 $mimeTypes array_merge($mimeTypesRequest::getMimeTypes($format));
  42.                 $request->setFormat($format$mimeTypes);
  43.             }
  44.         }
  45.     }
  46. }