Provider.php 1.2 KB

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