|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of amqp |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace Slick\Amqp\Producer; |
|
13
|
|
|
|
|
14
|
|
|
use Slick\Amqp\Producer; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* ProducerMethods |
|
18
|
|
|
* |
|
19
|
|
|
* @package Slick\Amqp\Producer |
|
20
|
|
|
*/ |
|
21
|
|
|
trait ProducerMethods |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var array<string, mixed> |
|
25
|
|
|
*/ |
|
26
|
|
|
protected array $options = []; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var array<string, mixed> |
|
30
|
|
|
*/ |
|
31
|
|
|
protected static array $defaultOptions = [ |
|
32
|
|
|
Producer::OPT_PASSIVE => false, |
|
33
|
|
|
Producer::OPT_DURABLE => false, |
|
34
|
|
|
Producer::OPT_AUTO_DELETE => true, |
|
35
|
|
|
Producer::OPT_INTERNAL => false, |
|
36
|
|
|
Producer::OPT_NOWAIT => false, |
|
37
|
|
|
Producer::OPT_ARGUMENTS => [], |
|
38
|
|
|
Producer::OPT_TICKET => null |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Merges provided options |
|
43
|
|
|
* |
|
44
|
|
|
* @param array<string, mixed>|null $options |
|
45
|
|
|
* @return self |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function mergeOptions(?array $options = []): self |
|
48
|
|
|
{ |
|
49
|
|
|
$this->options = array_merge(self::$defaultOptions, $this->options, $options ?? []); |
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @inheritDoc |
|
55
|
|
|
*/ |
|
56
|
|
|
public function isPassive(): bool |
|
57
|
|
|
{ |
|
58
|
|
|
return (bool) $this->options[Producer::OPT_PASSIVE]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @inheritDoc |
|
63
|
|
|
*/ |
|
64
|
|
|
public function isDurable(): bool |
|
65
|
|
|
{ |
|
66
|
|
|
return (bool) $this->options[Producer::OPT_DURABLE]; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @inheritDoc |
|
71
|
|
|
*/ |
|
72
|
|
|
public function isAutoDelete(): bool |
|
73
|
|
|
{ |
|
74
|
|
|
return (bool) $this->options[Producer::OPT_AUTO_DELETE]; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Exchange/Producer options |
|
79
|
|
|
* |
|
80
|
|
|
* @return array<string, mixed> |
|
81
|
|
|
*/ |
|
82
|
|
|
public function options(): array |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->options; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|