您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

57 行
2.3KB

  1. <?php
  2. namespace Lc\SovBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\Mailer\MailerInterface;
  5. use Throwable;
  6. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  7. use Symfony\Component\Mime\Email;
  8. class ErrorController extends AbstractController
  9. {
  10. public function show($exception, DebugLoggerInterface $logger = null, MailerInterface $mailer)
  11. {
  12. //Si != de 404 on envoit un mail de debug
  13. if ($exception->getStatusCode() != 404) {
  14. $mailDebug = $this->getParameter('app.mail_debug');
  15. if ($mailDebug) {
  16. $message = "Code : " . $exception->getStatusCode() . "<br>";
  17. $message .= "Message : " . $exception->getMessage() . "<br>";
  18. $message .= "File : " . $exception->getFile() . "<br>";
  19. $message .= "Line : " . $exception->getLine() . "<br><br>";
  20. $message .= "Trace : <br>" . str_replace("\n", "<br>", $exception->getTraceAsString());
  21. $siteName = $this->getParameter('app.site_name');
  22. $email = (new Email())
  23. ->from('nepasrepondre@laclic.fr')
  24. ->to($mailDebug)
  25. ->subject(
  26. '[' . $siteName . '] [ERREUR ' . $exception->getStatusCode() . '] ' . $exception->getMessage() . ''
  27. )
  28. ->text(strip_tags($message))
  29. ->html($message);
  30. $mailer->send($email);
  31. }
  32. }
  33. if ($exception->getStatusCode() == 404) {
  34. return $this->render('bundles/TwigBundle/Exception/error404.html.twig', [
  35. "code" => $exception->getStatusCode(),
  36. "message" => $exception->getMessage()
  37. ]);
  38. }
  39. if (str_contains($this->getRequestStack()->getCurrentRequest(), "/admin")) {
  40. return $this->render('@LcSov/exception/error.html.twig', [
  41. "code" => $exception->getStatusCode(),
  42. "message" => $exception->getMessage()
  43. ]);
  44. } else {
  45. return $this->render('bundles/TwigBundle/Exception/error.html.twig', [
  46. "code" => $exception->getStatusCode(),
  47. "message" => $exception->getMessage()
  48. ]);
  49. }
  50. }
  51. }