Provider.php 959 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. namespace NunoMaduro\Collision;
  4. use Whoops\Run;
  5. use Whoops\RunInterface;
  6. /**
  7. * @internal
  8. *
  9. * @see \Tests\Unit\ProviderTest
  10. */
  11. final class Provider
  12. {
  13. /**
  14. * Holds an instance of the Run.
  15. */
  16. private RunInterface $run;
  17. /**
  18. * Holds an instance of the handler.
  19. */
  20. private Handler $handler;
  21. /**
  22. * Creates a new instance of the Provider.
  23. */
  24. public function __construct(?RunInterface $run = null, ?Handler $handler = null)
  25. {
  26. $this->run = $run ?: new Run;
  27. $this->handler = $handler ?: new Handler;
  28. }
  29. /**
  30. * Registers the current Handler as Error Handler.
  31. */
  32. public function register(): self
  33. {
  34. $this->run->pushHandler($this->handler)
  35. ->register();
  36. return $this;
  37. }
  38. /**
  39. * Returns the handler.
  40. */
  41. public function getHandler(): Handler
  42. {
  43. return $this->handler;
  44. }
  45. }