vendor/elcoag/symfony-process-bundle/src/Controller/ServerController.php line 74
<?php
namespace Elcoag\SymfonyProcessBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Elcoag\SymfonyProcessBundle\Entity\Server;
use Elcoag\SymfonyProcessBundle\Form\ServerType;
use Elcoag\SymfonyProcessBundle\Repository\ServerRepository;
#[Route('/server')]
class ServerController extends AbstractController
{
/**
* Renders a view.
*
* @param string $view The view name
* @param array $parameters An array of parameters to pass to the view
* @param Response $response A response instance
*
* @return Response A Response instance
*/
protected function render($view, array $parameters = [], Response $response = null): Response
{
$func = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,3);
$funcName = $func[1]['function'] ?? null;
$funcName = $funcName === 'renderForm' ? $func[2]['function'] : $funcName;
return parent::render($view, array_merge($parameters, [
'object_title' => basename(str_replace(['\\', 'Controller'], ['/', ''], get_class($this))),
'title' => basename(str_replace(['\\', 'Controller'], ['/', ''], get_class($this))),
//'title' => basename(str_replace('\\', '/', get_class($this))),
//'subtitle' => basename(str_replace('\\', '/', __FUNCTION__)),
'subtitle' => $funcName ?? basename(str_replace('\\', '/', __FUNCTION__)),
'app_index' => 'app_server_index',
'app_show' => 'app_server_show',
'app_new' => 'app_server_new',
'app_edit' => 'app_server_edit',
'app_delete' => 'app_server_delete',
]), $response);
}
#[Route('/', name: 'app_server_index', methods: ['GET'])]
public function index(ServerRepository $serverRepository): Response
{
return $this->render('@SymfonyProcess/crud/index.html.twig', [
'items' => $serverRepository->findAll(),
]);
}
#[Route('/new', name: 'app_server_new', methods: ['GET', 'POST'])]
public function new(Request $request, ServerRepository $serverRepository): Response
{
$server = new Server();
$form = $this->createForm(ServerType::class, $server);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$serverRepository->save($server, true);
return $this->redirectToRoute('app_server_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('@SymfonyProcess/crud/new.html.twig', [
'item' => $server,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_server_show', methods: ['GET'])]
public function show(Server $server): Response
{
return $this->render('@SymfonyProcess/crud/show.html.twig', [
'item' => $server,
]);
}
#[Route('/{id}/edit', name: 'app_server_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Server $server, ServerRepository $serverRepository): Response
{
$form = $this->createForm(ServerType::class, $server);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$serverRepository->save($server, true);
return $this->redirectToRoute('app_server_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('@SymfonyProcess/crud/edit.html.twig', [
'item' => $server,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_server_delete', methods: ['POST'])]
public function delete(Request $request, Server $server, ServerRepository $serverRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$server->getId(), $request->request->get('_token'))) {
$serverRepository->remove($server, true);
}
return $this->redirectToRoute('app_server_index', [], Response::HTTP_SEE_OTHER);
}
}