-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathRoute.php
114 lines (92 loc) · 2.35 KB
/
Route.php
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Enqueue\Client;
final class Route
{
public const TOPIC = 'enqueue.client.topic_route';
public const COMMAND = 'enqueue.client.command_route';
/**
* @var string
*/
private $source;
/**
* @var string
*/
private $sourceType;
/**
* @var string
*/
private $processor;
/**
* @var array
*/
private $options;
public function __construct(
string $source,
string $sourceType,
string $processor,
array $options = [],
) {
$this->source = $source;
$this->sourceType = $sourceType;
$this->processor = $processor;
$this->options = $options;
}
public function getSource(): string
{
return $this->source;
}
public function isCommand(): bool
{
return self::COMMAND === $this->sourceType;
}
public function isTopic(): bool
{
return self::TOPIC === $this->sourceType;
}
public function getProcessor(): string
{
return $this->processor;
}
public function isProcessorExclusive(): bool
{
return (bool) $this->getOption('exclusive', false);
}
public function isProcessorExternal(): bool
{
return (bool) $this->getOption('external', false);
}
public function getQueue(): ?string
{
return $this->getOption('queue');
}
public function isPrefixQueue(): bool
{
return (bool) $this->getOption('prefix_queue', true);
}
public function getOptions(): array
{
return $this->options;
}
public function getOption(string $name, $default = null)
{
return array_key_exists($name, $this->options) ? $this->options[$name] : $default;
}
public function toArray(): array
{
return array_replace($this->options, [
'source' => $this->source,
'source_type' => $this->sourceType,
'processor' => $this->processor,
]);
}
public static function fromArray(array $route): self
{
list(
'source' => $source,
'source_type' => $sourceType,
'processor' => $processor) = $route;
unset($route['source'], $route['source_type'], $route['processor']);
$options = $route;
return new self($source, $sourceType, $processor, $options);
}
}