Errors.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Grav\Common\Errors;
  3. use Grav\Common\Grav;
  4. use Whoops\Handler\CallbackHandler;
  5. use Whoops\Handler\HandlerInterface;
  6. use Whoops\Run;
  7. /**
  8. * Class Debugger
  9. * @package Grav\Common
  10. */
  11. class Errors extends \Whoops\Run
  12. {
  13. public function pushHandler($handler, $key = null)
  14. {
  15. if (is_callable($handler)) {
  16. $handler = new CallbackHandler($handler);
  17. }
  18. if (!$handler instanceof HandlerInterface) {
  19. throw new \InvalidArgumentException(
  20. "Argument to " . __METHOD__ . " must be a callable, or instance of"
  21. . "Whoops\\Handler\\HandlerInterface"
  22. );
  23. }
  24. // Store with key if provided
  25. if ($key) {
  26. $this->handlerStack[$key] = $handler;
  27. } else {
  28. $this->handlerStack[] = $handler;
  29. }
  30. return $this;
  31. }
  32. public function resetHandlers()
  33. {
  34. $grav = Grav::instance();
  35. $config = $grav['config']->get('system.errors');
  36. if (isset($config['display']) && !$config['display']) {
  37. unset($this->handlerStack['pretty']);
  38. $this->handlerStack = array('simple' => new SimplePageHandler()) + $this->handlerStack;
  39. }
  40. if (isset($config['log']) && !$config['log']) {
  41. unset($this->handlerStack['log']);
  42. }
  43. }
  44. }