vendor/elcoag/symfony-process-bundle/src/Controller/ServerController.php line 47

  1. <?php
  2. namespace Elcoag\SymfonyProcessBundle\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Elcoag\SymfonyProcessBundle\Entity\Server;
  9. use Elcoag\SymfonyProcessBundle\Form\ServerType;
  10. use Elcoag\SymfonyProcessBundle\Repository\ServerRepository;
  11. #[Route('/server')]
  12. class ServerController extends AbstractController
  13. {
  14.     /**
  15.      * Renders a view.
  16.      *
  17.      * @param string   $view       The view name
  18.      * @param array    $parameters An array of parameters to pass to the view
  19.      * @param Response $response   A response instance
  20.      *
  21.      * @return Response A Response instance
  22.      */
  23.     protected function render($view, array $parameters = [], Response $response null): Response
  24.     {
  25.         $func debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,3);
  26.         $funcName $func[1]['function'] ?? null;
  27.         $funcName $funcName === 'renderForm' $func[2]['function'] : $funcName;
  28.         return parent::render($viewarray_merge($parameters, [
  29.             'object_title' => basename(str_replace(['\\''Controller'], ['/'''], get_class($this))),
  30.             'title' => basename(str_replace(['\\''Controller'], ['/'''], get_class($this))),
  31.             //'title' => basename(str_replace('\\', '/', get_class($this))),
  32.             //'subtitle' => basename(str_replace('\\', '/', __FUNCTION__)),
  33.             'subtitle' => $funcName ?? basename(str_replace('\\''/'__FUNCTION__)),
  34.             'app_index' => 'app_server_index',
  35.             'app_show' => 'app_server_show',
  36.             'app_new' => 'app_server_new',
  37.             'app_edit' => 'app_server_edit',
  38.             'app_delete' => 'app_server_delete',
  39.         ]), $response);
  40.     }
  41.     #[Route('/'name'app_server_index'methods: ['GET'])]
  42.     public function index(ServerRepository $serverRepository): Response
  43.     {
  44.         return $this->render('@SymfonyProcess/crud/index.html.twig', [
  45.             'items' => $serverRepository->findAll(),
  46.         ]);
  47.     }
  48.     #[Route('/new'name'app_server_new'methods: ['GET''POST'])]
  49.     public function new(Request $requestServerRepository $serverRepository): Response
  50.     {
  51.         $server = new Server();
  52.         $form $this->createForm(ServerType::class, $server);
  53.         $form->handleRequest($request);
  54.         if ($form->isSubmitted() && $form->isValid()) {
  55.             $serverRepository->save($servertrue);
  56.             return $this->redirectToRoute('app_server_index', [], Response::HTTP_SEE_OTHER);
  57.         }
  58.         return $this->renderForm('@SymfonyProcess/crud/new.html.twig', [
  59.             'item' => $server,
  60.             'form' => $form,
  61.         ]);
  62.     }
  63.     #[Route('/{id}'name'app_server_show'methods: ['GET'])]
  64.     public function show(Server $server): Response
  65.     {
  66.         return $this->render('@SymfonyProcess/crud/show.html.twig', [
  67.             'item' => $server,
  68.         ]);
  69.     }
  70.     #[Route('/{id}/edit'name'app_server_edit'methods: ['GET''POST'])]
  71.     public function edit(Request $requestServer $serverServerRepository $serverRepository): Response
  72.     {
  73.         $form $this->createForm(ServerType::class, $server);
  74.         $form->handleRequest($request);
  75.         if ($form->isSubmitted() && $form->isValid()) {
  76.             $serverRepository->save($servertrue);
  77.             return $this->redirectToRoute('app_server_index', [], Response::HTTP_SEE_OTHER);
  78.         }
  79.         return $this->renderForm('@SymfonyProcess/crud/edit.html.twig', [
  80.             'item' => $server,
  81.             'form' => $form,
  82.         ]);
  83.     }
  84.     #[Route('/{id}'name'app_server_delete'methods: ['POST'])]
  85.     public function delete(Request $requestServer $serverServerRepository $serverRepository): Response
  86.     {
  87.         if ($this->isCsrfTokenValid('delete'.$server->getId(), $request->request->get('_token'))) {
  88.             $serverRepository->remove($servertrue);
  89.         }
  90.         return $this->redirectToRoute('app_server_index', [], Response::HTTP_SEE_OTHER);
  91.     }
  92. }