2023-08-16 00:43:28 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Lib\Events;
|
|
|
|
|
|
|
|
use Illuminate\Broadcasting\Channel;
|
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
|
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2023-08-17 12:46:48 +02:00
|
|
|
use Ramsey\Uuid\Lazy\LazyUuidFromString;
|
|
|
|
use Ramsey\Uuid\UuidInterface;
|
2023-08-16 00:43:28 +02:00
|
|
|
|
|
|
|
class JobEvent implements ShouldBroadcastNow
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
|
|
|
|
public bool $reload = false;
|
|
|
|
public string $message = '';
|
|
|
|
|
2023-08-17 12:46:48 +02:00
|
|
|
final private function __construct(public string $channel, public UuidInterface $jobId)
|
2023-08-16 00:43:28 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-17 12:46:48 +02:00
|
|
|
public static function on(string $channel, UuidInterface $jobId): static
|
2023-08-16 00:43:28 +02:00
|
|
|
{
|
2023-08-17 12:46:48 +02:00
|
|
|
return new static($channel, $jobId);
|
2023-08-16 00:43:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function withMessage(string $message): static
|
|
|
|
{
|
|
|
|
$this->message = $message;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2023-08-17 12:46:48 +02:00
|
|
|
public function dispatch(): void
|
|
|
|
{
|
|
|
|
event($this);
|
|
|
|
}
|
|
|
|
|
2023-08-16 00:43:28 +02:00
|
|
|
/**
|
|
|
|
* Get the channels the event should broadcast on.
|
|
|
|
*
|
2023-08-17 12:46:48 +02:00
|
|
|
* @return array<int, Channel>
|
2023-08-16 00:43:28 +02:00
|
|
|
*/
|
|
|
|
public function broadcastOn()
|
|
|
|
{
|
2023-08-17 12:46:48 +02:00
|
|
|
return [
|
|
|
|
new Channel($this->channel),
|
|
|
|
new Channel('jobs'),
|
|
|
|
];
|
2023-08-16 00:43:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldReload(): static
|
|
|
|
{
|
|
|
|
$this->reload = true;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|