|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mosaic\CommandBus\Adapters\Tactician; |
|
4
|
|
|
|
|
5
|
|
|
use ArrayAccess; |
|
6
|
|
|
use League\Tactician\CommandBus as TacticianCommandBus; |
|
7
|
|
|
use Mosaic\CommandBus\AbstractBus; |
|
8
|
|
|
use Mosaic\CommandBus\CommandBus; |
|
9
|
|
|
use Mosaic\Common\ArrayObject; |
|
10
|
|
|
use Mosaic\Container\Container; |
|
11
|
|
|
|
|
12
|
|
|
class TacticianBus extends AbstractBus implements CommandBus |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Container |
|
16
|
|
|
*/ |
|
17
|
|
|
private $container; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
private $middleware; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* TacticianBus constructor. |
|
26
|
|
|
* @param Container $container |
|
27
|
|
|
* @param array $middleware |
|
28
|
|
|
*/ |
|
29
|
6 |
|
public function __construct(Container $container, array $middleware = []) |
|
30
|
|
|
{ |
|
31
|
6 |
|
$this->container = $container; |
|
32
|
6 |
|
$this->middleware = $middleware; |
|
33
|
6 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param object $command |
|
37
|
|
|
* @param array $middleware |
|
38
|
|
|
* @return mixed |
|
39
|
|
|
*/ |
|
40
|
6 |
|
public function dispatch($command, array $middleware = []) |
|
41
|
|
|
{ |
|
42
|
6 |
|
return (new TacticianCommandBus( |
|
43
|
|
|
array_merge( |
|
44
|
6 |
|
$this->resolveMiddleware($middleware, $this->container), |
|
45
|
6 |
|
$this->middleware |
|
46
|
|
|
) |
|
47
|
6 |
|
))->handle($command); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string $command |
|
52
|
|
|
* @param ArrayAccess $input |
|
53
|
|
|
* @param array $extra |
|
54
|
|
|
* @param array $middleware |
|
55
|
|
|
* @return mixed |
|
56
|
|
|
*/ |
|
57
|
2 |
|
public function dispatchFrom($command, ArrayAccess $input, array $extra = [], array $middleware = []) |
|
58
|
|
|
{ |
|
59
|
2 |
|
return $this->dispatch( |
|
60
|
2 |
|
$this->marshal($command, $input, $extra), |
|
61
|
|
|
$middleware |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $command |
|
67
|
|
|
* @param array $input |
|
68
|
|
|
* @param array $middleware |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public function dispatchFromArray($command, array $input = [], array $middleware = []) |
|
72
|
|
|
{ |
|
73
|
2 |
|
return $this->dispatch( |
|
74
|
2 |
|
$this->marshal($command, new ArrayObject(), $input), |
|
75
|
|
|
$middleware |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|