src/AdminBundle/Controller/ErrorController.php line 10

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  5. use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  6. class ErrorController extends BaseController {
  7. public function show(
  8. \Throwable $exception,
  9. ?DebugLoggerInterface $logger,
  10. Request $request
  11. ) {
  12. $msg = $exception->getMessage();
  13. if ($exception instanceof NotFoundHttpException) {
  14. $code = $exception->getStatusCode();
  15. $title = 'Page not found';
  16. $msg = "We are sorry this page does not exist.";
  17. } else {
  18. if ($_ENV['APP_ENV'] === 'dev') {
  19. throw $exception;
  20. } else {
  21. $title = 'An Error Occurred.';
  22. $msg = 'Something went wrong.';
  23. $code = 500;
  24. }
  25. }
  26. $route = 'root';
  27. if ($u = $this->getUser()) {
  28. if (
  29. $u->hasRole('ROLE_ADMIN') ||
  30. $u->hasRole('ROLE_OPERATOR') ||
  31. $u->hasRole('ROLE_OPERATOR_ADMIN')
  32. ) {
  33. $route = 'sonata_admin_dashboard';
  34. } elseif (
  35. $u->hasRole('ROLE_CLIENT') ||
  36. $u->hasRole('ROLE_COMPANY')
  37. ) {
  38. $route = 'client_bounce';
  39. } elseif ($u->hasRole('ROLE_DRIVER')) {
  40. $route = 'driver_bookings';
  41. }
  42. } else {
  43. $uri = $request->server->get('REQUEST_URI');
  44. if (strpos($uri, 'admin/') !== false) {
  45. $route = 'sonata_admin_dashboard';
  46. } else if (strpos($uri, 'client/')) {
  47. $route = 'client_bounce';
  48. } else if (strpos($uri, 'driver/')) {
  49. $route = 'driver_bookings';
  50. }
  51. }
  52. return $this->render('@Admin/Error/error.html.twig', [
  53. 'route' => $route,
  54. 'title' => $title,
  55. 'code' => $code,
  56. 'msg' => $msg,
  57. ]);
  58. }
  59. }