src/Controller/SspEndpointController.php line 49

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\SspEndpoint;
  4. use App\Form\Type\SspEndpointType;
  5. use App\Repository\SspEndpointRepository;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. /**
  13.  * Controller for SSP endpoints.
  14.  *
  15.  * @Route(path="ssp")
  16.  */
  17. class SspEndpointController extends AbstractController
  18. {
  19.     /**
  20.      * Show all projects.
  21.      *
  22.      * @Route(path="", name="ssp_index", methods={"GET"})
  23.      *
  24.      * @param SspEndpointRepository $sspEndpointRepository
  25.      * @return Response
  26.      */
  27.     public function indexAction(SspEndpointRepository $sspEndpointRepository): Response
  28.     {
  29.         $endpoints $sspEndpointRepository->findAll();
  30.         return $this->render('ssp/list.html.twig', ['endpoints' => $endpoints]);
  31.     }
  32.     /**
  33.      * Create new SSP endpoint
  34.      *
  35.      * @Route(path="/new", name="ssp_new", methods={"GET", "POST"})
  36.      *
  37.      * @param Request                $request
  38.      * @param EntityManagerInterface $entityManager
  39.      * @return Response
  40.      */
  41.     public function newAction(Request $requestEntityManagerInterface $entityManager): Response
  42.     {
  43.         $endpoint = new SspEndpoint();
  44.         $form     $this->createForm(SspEndpointType::class, $endpoint);
  45.         $form->handleRequest($request);
  46.         if ($form->isSubmitted() && $form->isValid()) {
  47.             $entityManager->persist($endpoint);
  48.             $entityManager->flush();
  49.             return $this->redirectToRoute('ssp_index');
  50.         }
  51.         return $this->renderForm('ssp/new.html.twig', ['form' => $form]);
  52.     }
  53.     /**
  54.      * Edits an existing SSP endpoint
  55.      *
  56.      * @Route(path="/edit/{id}", name="ssp_edit", methods={"GET", "POST"})
  57.      *
  58.      * @param int                    $id
  59.      * @param Request                $request
  60.      * @param EntityManagerInterface $entityManager
  61.      * @return Response
  62.      */
  63.     public function editAction(int $idRequest $requestEntityManagerInterface $entityManager): Response
  64.     {
  65.         $endpoint $entityManager->find(SspEndpoint::class, $id);
  66.         if (empty($endpoint)) {
  67.             throw new NotFoundHttpException('SSP endpoint not found!');
  68.         }
  69.         $form $this->createForm(SspEndpointType::class, $endpoint);
  70.         $form->handleRequest($request);
  71.         if ($form->isSubmitted() && $form->isValid()) {
  72.             $entityManager->persist($endpoint);
  73.             $entityManager->flush();
  74.             return $this->redirectToRoute('ssp_index');
  75.         }
  76.         return $this->renderForm('ssp/new.html.twig', ['form' => $form]);
  77.     }
  78. }