1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) 2018 Douglas Reith. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace Reith\ToyRobot\Console; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Helper\HelperInterface; |
14
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
15
|
|
|
use Reith\ToyRobot\Messaging\BusInterface; |
16
|
|
|
|
17
|
|
|
class BusHelper implements HelperInterface |
18
|
|
|
{ |
19
|
|
|
private $helperSet; |
20
|
|
|
|
21
|
|
|
private $commandBus; |
22
|
|
|
|
23
|
|
|
private $queryBus; |
24
|
|
|
|
25
|
7 |
|
public function setCommandBus(BusInterface $commandBus): BusHelper |
26
|
|
|
{ |
27
|
7 |
|
$this->commandBus = $commandBus; |
28
|
|
|
|
29
|
7 |
|
return $this; |
30
|
|
|
} |
31
|
|
|
|
32
|
7 |
|
public function setQueryBus(BusInterface $queryBus): BusHelper |
33
|
|
|
{ |
34
|
7 |
|
$this->queryBus = $queryBus; |
35
|
|
|
|
36
|
7 |
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
13 |
|
public function setHelperSet(HelperSet $helperSet = null) |
40
|
|
|
{ |
41
|
13 |
|
$this->helperSet = $helperSet; |
42
|
|
|
|
43
|
13 |
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Gets the helper set associated with this helper. |
48
|
|
|
* |
49
|
|
|
* @return HelperSet A HelperSet instance |
50
|
|
|
*/ |
51
|
|
|
public function getHelperSet() |
52
|
|
|
{ |
53
|
|
|
return $this->helperSet; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Returns the canonical name of this helper. |
58
|
|
|
* |
59
|
|
|
* @return string The canonical name |
60
|
|
|
*/ |
61
|
13 |
|
public function getName() |
62
|
|
|
{ |
63
|
13 |
|
return 'bus'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param mixed $message |
68
|
|
|
* |
69
|
|
|
* @throws \RuntimeException |
70
|
|
|
*/ |
71
|
5 |
|
public function postCommand($message): void |
72
|
|
|
{ |
73
|
5 |
|
if (!$this->commandBus) { |
74
|
|
|
throw new \RuntimeException( |
75
|
|
|
'Command bus is not configured' |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
5 |
|
$this->commandBus->post($message); |
80
|
5 |
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param mixed $message |
84
|
|
|
* @param ?callable $callback To get response data |
|
|
|
|
85
|
|
|
* |
86
|
|
|
* @throws \RuntimeException |
87
|
|
|
*/ |
88
|
5 |
|
public function postQuery($message, ?callable $callback = null): void |
89
|
|
|
{ |
90
|
5 |
|
if (!$this->queryBus) { |
91
|
|
|
throw new \RuntimeException( |
92
|
|
|
'Query bus is not configured' |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
|
96
|
5 |
|
$this->queryBus->post($message, $callback); |
|
|
|
|
97
|
5 |
|
} |
98
|
|
|
} |
99
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.