event = $event; } /** * Handle the queued job. * * @param \Illuminate\Contracts\Broadcasting\Broadcaster $broadcaster * @return void */ public function handle(Broadcaster $broadcaster) { $name = method_exists($this->event, 'broadcastAs') ? $this->event->broadcastAs() : get_class($this->event); $broadcaster->broadcast( Arr::wrap($this->event->broadcastOn()), $name, $this->getPayloadFromEvent($this->event) ); } /** * Get the payload for the given event. * * @param mixed $event * @return array */ protected function getPayloadFromEvent($event) { if (method_exists($event, 'broadcastWith')) { return array_merge( $event->broadcastWith(), ['socket' => data_get($event, 'socket')] ); } $payload = []; foreach ((new ReflectionClass($event))->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { $payload[$property->getName()] = $this->formatProperty($property->getValue($event)); } unset($payload['broadcastQueue']); return $payload; } /** * Format the given value for a property. * * @param mixed $value * @return mixed */ protected function formatProperty($value) { if ($value instanceof Arrayable) { return $value->toArray(); } return $value; } /** * Get the display name for the queued job. * * @return string */ public function displayName() { return get_class($this->event); } /** * Prepare the instance for cloning. * * @return void */ public function __clone() { $this->event = clone $this->event; } }