container.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. use App\Services\View;
  4. use Slim\Container;
  5. /**
  6. * Container Builder
  7. *
  8. * @return Container
  9. */
  10. $configuration = [
  11. 'settings' => [
  12. 'debug' => $_ENV['debug'],
  13. 'whoops.editor' => 'sublime',
  14. 'displayErrorDetails' => $_ENV['debug'],
  15. ],
  16. ];
  17. $container = new Container($configuration);
  18. $container['notFoundHandler'] = static function ($c) {
  19. return static function ($request, $response) {
  20. $view = View::getSmarty();
  21. return $response->withStatus(404)->write($view->fetch('404.tpl'));
  22. };
  23. };
  24. $container['notAllowedHandler'] = static function ($c) {
  25. return static function ($request, $response, $methods) {
  26. $view = View::getSmarty();
  27. return $response->withStatus(405)->write($view->fetch('405.tpl'));
  28. };
  29. };
  30. if ($_ENV['debug'] === false) {
  31. $container['errorHandler'] = function ($c) {
  32. return function ($request, $response, $exception) {
  33. $view = View::getSmarty();
  34. $exceptionId = empty($_ENV['sentry_dsn']) ? null : Sentry\captureException($exception);
  35. return $response->withStatus(500)
  36. ->write($view->assign('exceptionId', $exceptionId)->fetch('500.tpl'));
  37. };
  38. };
  39. $container['phpErrorHandler'] = function ($c) {
  40. return function ($request, $response, $exception) {
  41. $view = View::getSmarty();
  42. $exceptionId = empty($_ENV['sentry_dsn']) ? null : Sentry\captureException($exception);
  43. return $response->withStatus(500)
  44. ->write($view->assign('exceptionId', $exceptionId)->fetch('500.tpl'));
  45. };
  46. };
  47. }
  48. return $container;