1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace mcorten87\rabbitmq_api\objects; |
4
|
|
|
|
5
|
|
|
class QueueArgument extends BaseObject |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var integer |
9
|
|
|
* How long a message published to a queue can live before it is discarded (milliseconds). |
10
|
|
|
*/ |
11
|
|
|
const MESSAGE_TTL = 'message-ttl'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var integer |
15
|
|
|
* How long a queue can be unused for before it is automatically deleted (milliseconds). |
16
|
|
|
*/ |
17
|
|
|
const EXPIRES = 'expires'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var integer |
21
|
|
|
* How many (ready) messages a queue can contain before it starts to drop them from its head. |
22
|
|
|
*/ |
23
|
|
|
const MAX_LENGTH = 'max-length'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var integer |
27
|
|
|
* Total body size for ready messages a queue can contain before it starts to drop them from its head. |
28
|
|
|
*/ |
29
|
|
|
const MAX_BYTES = 'max-length-bytes'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
* Name of an exchange to which messages will be republished if they are rejected or expire. |
34
|
|
|
*/ |
35
|
|
|
const MAX_DEAD_LETTER_EXCHAGE = 'dead-letter-exchange'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
* Replacement routing key to use when a message is dead-lettered. If this is not set, the message's original routing key will be used. |
40
|
|
|
*/ |
41
|
|
|
const MAX_DEAD_LETTER_ROUTING_KEY = 'dead-letter-routing-key'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var integer |
45
|
|
|
* Maximum number of priority levels for the queue to support; if not set, the queue will not support message priorities. |
46
|
|
|
*/ |
47
|
|
|
const MAX_PRIORITY = 'max-priority'; |
48
|
|
|
|
49
|
|
|
private $argumentName; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return String |
53
|
|
|
*/ |
54
|
|
|
public function getArgumentName() |
55
|
|
|
{ |
56
|
|
|
return $this->argumentName; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function __construct(String $argument, string $value) |
60
|
|
|
{ |
61
|
|
|
$this->argumentName = $argument; |
62
|
|
|
|
63
|
|
|
parent::__construct($value); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function validate($value) : bool |
67
|
|
|
{ |
68
|
|
|
if (empty($this->getArgumentName())) { |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
switch ($this->argumentName) { |
74
|
|
|
case self::MESSAGE_TTL: |
75
|
|
|
case self::EXPIRES: |
76
|
|
|
case self::MAX_LENGTH: |
77
|
|
|
case self::MAX_BYTES: |
78
|
|
|
case self::MAX_PRIORITY: |
79
|
|
|
return is_numeric($this->getValue()); |
80
|
|
|
|
81
|
|
|
case self::MAX_DEAD_LETTER_EXCHAGE: |
82
|
|
|
case self::MAX_DEAD_LETTER_ROUTING_KEY: |
83
|
|
|
return true; |
84
|
|
|
|
85
|
|
|
default : |
|
|
|
|
86
|
|
|
throw new \RuntimeException('Argument not supported'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
As per the PSR-2 coding standard, there must not be a space in front of the colon in the default statement.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.