Files
afup/sources/AppBundle/Controller/EventBaseController.php

34 lines
832 B
PHP

<?php
namespace AppBundle\Controller;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventRepository;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
abstract class EventBaseController extends Controller
{
/**
* @param $eventSlug
* @return Event
*
* @throws NotFoundHttpException
*/
protected function checkEventSlug($eventSlug)
{
/**
* @var $eventRepository EventRepository
*/
$eventRepository = $this->get('ting')->get(EventRepository::class);
$event = $eventRepository->getOneBy(['path' => $eventSlug]);
if ($event === null) {
throw $this->createNotFoundException('Event not found');
}
return $event;
}
}