vendor/tattali/calendar-bundle/src/Controller/CalendarController.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace CalendarBundle\Controller;
  4. use CalendarBundle\CalendarEvents;
  5. use CalendarBundle\Event\CalendarEvent;
  6. use CalendarBundle\Serializer\SerializerInterface;
  7. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. class CalendarController
  11. {
  12.     public function __construct(
  13.         protected EventDispatcherInterface $eventDispatcher,
  14.         protected SerializerInterface $serializer
  15.     )
  16.     {}
  17.     /**
  18.      * @throws \Exception
  19.      */
  20.     public function loadAction(Request $request): Response
  21.     {
  22.         $start = new \DateTime($request->get('start'));
  23.         $end = new \DateTime($request->get('end'));
  24.         $filters $request->get('filters''{}');
  25.         $filters \is_array($filters) ? $filters json_decode($filterstrue);
  26.         $event $this->eventDispatcher->dispatch(
  27.             new CalendarEvent($start$end$filters),
  28.             CalendarEvents::SET_DATA
  29.         );
  30.         $content $this->serializer->serialize($event->getEvents());
  31.         $response = new Response();
  32.         $response->headers->set('Content-Type''application/json');
  33.         $response->setContent($content);
  34.         $response->setStatusCode(empty($content) ? Response::HTTP_NO_CONTENT Response::HTTP_OK);
  35.         return $response;
  36.     }
  37. }