-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.php
More file actions
47 lines (39 loc) · 1.33 KB
/
functions.php
File metadata and controls
47 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
use Illuminate\Support\Arr;
use Illuminate\Container\Container;
use RabbitEvents\Publisher\Publisher;
use RabbitEvents\Publisher\ShouldPublish;
if (!function_exists('publish')) {
function publish($event, $payload = [])
{
if (is_string($event)) {
$event = new class ($event, $payload) implements ShouldPublish {
private $event;
private $payload;
public function __construct(string $event, $payload = [])
{
$this->event = $event;
if (is_object($payload)) {
$this->payload = $payload;
} elseif (is_array($payload) && Arr::isAssoc($payload)) {
$this->payload = [$payload];
} else {
$this->payload = Arr::wrap($payload);
}
}
public function publishEventKey(): string
{
return $this->event;
}
public function toPublish(): mixed
{
return $this->payload;
}
};
}
Container::getInstance()
->make(Publisher::class)
->publish($event);
}
}