src/Controller/ErrorController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Event\AppEvents;
  4. use App\Event\FormEvent;
  5. use App\Event\InvoiceEvent;
  6. use App\Helper\ErrorSendHelper;
  7. use App\Model\Form\ErrorFormType;
  8. use JetBrains\PhpStorm\NoReturn;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  10. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  15. use Symfony\Component\HttpFoundation\RedirectResponse;
  16. use Symfony\Component\Mailer\MailerInterface;
  17. class ErrorController extends AbstractController
  18. {
  19.     public function __construct(
  20.         ErrorSendHelper $errorSendHelper
  21.     ) {
  22.         $this->errorSendHelper $errorSendHelper;
  23.     }
  24.     public function show(\Throwable $exceptionRequest $request): Response
  25.     {
  26.         $statusCode method_exists($exception'getStatusCode') ? $exception->getStatusCode() : 500;
  27.         $form $this->createForm(ErrorFormType::class);
  28.         $form->handleRequest($request);
  29.         return $this->render('bundles/TwigBundle/Exception/error.html.twig', [
  30.             'exception' => $exception,
  31.             'statusCode' => $statusCode,
  32.             'form' => $form->createView(),
  33.         ]);
  34.     }
  35.     /**
  36.      * @Route("/error-submt", name="error_submt", methods={"POST"})
  37.      */
  38.     public function errorSubmt(Request $request)
  39.     {
  40.         $form $this->createForm(ErrorFormType::class);
  41.         $form->handleRequest($request);
  42.         $exception $request->get('exception_error');
  43.         $exceptionMessage $request->get('exception_message');
  44.         $exceptionCode $request->get('exception_code');
  45.         $exceptionFile $request->get('exception_file');
  46.         $url $request->request->get('request-url');
  47.         $exception = [
  48.             'message' => $exceptionMessage,
  49.             'code' => $exceptionCode,
  50.             'file' => $exceptionFile,
  51.             'exception_error' => $exception,
  52.             'exception_date' => new \DateTime('now'),
  53.             'url' => $url
  54.         ];
  55.         if ($form->isSubmitted()) {
  56.             $data $form->getData();
  57.             try {
  58.                 $this->errorSendHelper->sendErrorEmail('bundles/TwigBundle/Exception/send_mail.html.twig', [
  59.                     'form' => $data,
  60.                     'exception'     => $exception,
  61.                     'user'          => $this->getUser(),
  62.                 ], 'New support created''support@insivia.com');
  63.             } catch (\Exception $e) {
  64.             }
  65.         }
  66.         return new RedirectResponse($this->generateUrl('app_home'));
  67.     }
  68. }