EventDispatcherBase.php 810 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * This file is part of the Carbon package.
  5. *
  6. * (c) Brian Nesbitt <brian@nesbot.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Tests\Laravel;
  12. class EventDispatcherBase
  13. {
  14. /**
  15. * @var array
  16. */
  17. protected $listeners;
  18. public function listen($name, $listener)
  19. {
  20. if (!isset($this->listeners[$name])) {
  21. $this->listeners[$name] = [];
  22. }
  23. $this->listeners[$name][] = $listener;
  24. }
  25. public function dispatch($name, $event = null)
  26. {
  27. if (isset($this->listeners[$name])) {
  28. foreach ($this->listeners[$name] as $listener) {
  29. $listener($event);
  30. }
  31. }
  32. }
  33. }