PendingBroadcast.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Illuminate\Broadcasting;
  3. use Illuminate\Contracts\Events\Dispatcher;
  4. class PendingBroadcast
  5. {
  6. /**
  7. * The event dispatcher implementation.
  8. *
  9. * @var \Illuminate\Contracts\Events\Dispatcher
  10. */
  11. protected $events;
  12. /**
  13. * The event instance.
  14. *
  15. * @var mixed
  16. */
  17. protected $event;
  18. /**
  19. * Create a new pending broadcast instance.
  20. *
  21. * @param \Illuminate\Contracts\Events\Dispatcher $events
  22. * @param mixed $event
  23. * @return void
  24. */
  25. public function __construct(Dispatcher $events, $event)
  26. {
  27. $this->event = $event;
  28. $this->events = $events;
  29. }
  30. /**
  31. * Broadcast the event to everyone except the current user.
  32. *
  33. * @return $this
  34. */
  35. public function toOthers()
  36. {
  37. if (method_exists($this->event, 'dontBroadcastToCurrentUser')) {
  38. $this->event->dontBroadcastToCurrentUser();
  39. }
  40. return $this;
  41. }
  42. /**
  43. * Handle the object's destruction.
  44. *
  45. * @return void
  46. */
  47. public function __destruct()
  48. {
  49. $this->events->dispatch($this->event);
  50. }
  51. }