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
|
|
|
public function setCommandBus(BusInterface $commandBus): BusHelper |
26
|
|
|
{ |
27
|
|
|
$this->commandBus = $commandBus; |
28
|
|
|
|
29
|
|
|
return $this; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function setQueryBus(BusInterface $queryBus): BusHelper |
33
|
|
|
{ |
34
|
|
|
$this->queryBus = $queryBus; |
35
|
|
|
|
36
|
|
|
return $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
6 |
|
public function setHelperSet(HelperSet $helperSet = null) |
40
|
|
|
{ |
41
|
6 |
|
$this->helperSet = $helperSet; |
42
|
|
|
|
43
|
6 |
|
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
|
6 |
|
public function getName() |
62
|
|
|
{ |
63
|
6 |
|
return 'bus'; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function postCommand($message) |
67
|
|
|
{ |
68
|
|
|
if (!$this->commandBus) { |
69
|
|
|
throw new \RuntimeException( |
70
|
|
|
'Command bus is not configured' |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$this->commandBus->post($message); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function postQuery($message) |
78
|
|
|
{ |
79
|
|
|
if (!$this->commandBus) { |
80
|
|
|
throw new \RuntimeException( |
81
|
|
|
'Command bus is not configured' |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->queryBus->post($message); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|