|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace RabbitMqModule\Options; |
|
4
|
|
|
|
|
5
|
|
|
use Zend\Serializer\Serializer; |
|
6
|
|
|
use Zend\Stdlib\AbstractOptions; |
|
7
|
|
|
use Zend\Serializer\Adapter\AdapterInterface as SerializerInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class RpcClient |
|
11
|
|
|
* @package RabbitMqModule\Options |
|
12
|
|
|
*/ |
|
13
|
|
|
class RpcClient extends AbstractOptions |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $connection = 'default'; |
|
19
|
|
|
/** |
|
20
|
|
|
* @var SerializerInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $serializer; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return string |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function getConnection() |
|
28
|
|
|
{ |
|
29
|
2 |
|
return $this->connection; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $connection |
|
34
|
|
|
* |
|
35
|
|
|
* @return $this |
|
36
|
|
|
*/ |
|
37
|
2 |
|
public function setConnection($connection) |
|
38
|
|
|
{ |
|
39
|
2 |
|
$this->connection = $connection; |
|
40
|
|
|
|
|
41
|
2 |
|
return $this; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return mixed |
|
46
|
|
|
*/ |
|
47
|
2 |
|
public function getSerializer() |
|
48
|
|
|
{ |
|
49
|
2 |
|
return $this->serializer; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param null|string|array|SerializerInterface $serializer |
|
54
|
|
|
* |
|
55
|
|
|
* @return $this |
|
56
|
|
|
* |
|
57
|
|
|
* @throws \InvalidArgumentException |
|
58
|
|
|
*/ |
|
59
|
4 |
|
public function setSerializer($serializer = null) |
|
60
|
|
|
{ |
|
61
|
4 |
|
if (is_array($serializer)) { |
|
62
|
2 |
|
if (!array_key_exists('name', $serializer)) { |
|
63
|
1 |
|
throw new \InvalidArgumentException('A serializer name should be provided'); |
|
64
|
|
|
} |
|
65
|
1 |
|
$name = $serializer['name']; |
|
66
|
1 |
|
$options = array_key_exists('options', $serializer) ? $serializer['options'] : null; |
|
67
|
1 |
|
$serializer = Serializer::factory($name, $options); |
|
68
|
3 |
|
} elseif (is_string($serializer)) { |
|
69
|
2 |
|
$serializer = Serializer::factory($serializer); |
|
70
|
2 |
|
} |
|
71
|
3 |
|
if (null !== $serializer && !$serializer instanceof SerializerInterface) { |
|
72
|
1 |
|
throw new \InvalidArgumentException('Invalid serializer instance or options'); |
|
73
|
|
|
} |
|
74
|
2 |
|
$this->serializer = $serializer; |
|
75
|
|
|
|
|
76
|
2 |
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|