-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTactician.php
73 lines (55 loc) · 1.34 KB
/
Tactician.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace cherif\tactician;
use Yii;
use yii\base\Component;
use League\Tactician\Handler\CommandHandlerMiddleware;
use League\Tactician\CommandBus;
class Tactician extends Component
{
public $inflector;
public $extractor;
public $commandHandlerMap = [];
protected $tactician;
protected $middlewares = [];
public function init()
{
$this->buildTactician();
}
protected function buildTactician()
{
$extractor = Yii::createObject($this->extractor);
$containerLocator = Yii::createObject('cherif\tactician\ContainerLocator',[
$this->commandHandlerMap
]
);
$inflector = Yii::createObject($this->inflector);
$handlerMiddleware = Yii::createObject('League\Tactician\Handler\CommandHandlerMiddleware',[
$extractor,
$containerLocator,
$inflector
]
);
$this->registerMiddleware($handlerMiddleware);
}
public function registerMiddleware($middleware)
{
array_push($this->middlewares,$middleware);
}
public function handle( $command )
{
Yii::trace(sprintf('Handle command class for %s', get_class( $command ) ) );
$tactician = Yii::createObject('League\Tactician\CommandBus',[
$this->middlewares
]
);
return $tactician->handle( $command );
}
public function getMiddlewares()
{
return $this->middlewares;
}
public function getTactician()
{
return $this->tactician;
}
}