1 | <?php |
||
20 | class Bus implements CommandBusInterface |
||
21 | { |
||
22 | |||
23 | /** @var CommandBus */ |
||
24 | protected $bus; |
||
25 | |||
26 | /** @var CommandNameExtractor */ |
||
27 | protected $commandNameExtractor; |
||
28 | |||
29 | /** @var MethodNameInflector */ |
||
30 | protected $methodNameInflector; |
||
31 | |||
32 | /** @var LocatorInterface */ |
||
33 | protected $handlerLocator; |
||
34 | |||
35 | 7 | public function __construct( |
|
44 | |||
45 | /** |
||
46 | * Dispatch a command |
||
47 | * |
||
48 | * @param object $command Command to be dispatched |
||
49 | * @param array $input Array of input to map to the command |
||
50 | * @param array $middleware Array of middleware class name to add to the stack, they are resolved from the laravel container |
||
51 | * @throws CommandHandlerNotExists |
||
52 | * @return mixed |
||
53 | */ |
||
54 | 7 | public function dispatch($command, array $input = [], array $middleware = []) |
|
60 | |||
61 | 7 | private function bindCommandWitHisCommandHandler($command) |
|
71 | |||
72 | /** |
||
73 | * @param $command |
||
74 | * @return string |
||
75 | */ |
||
76 | 7 | private function getNameOfClass($command): string |
|
86 | |||
87 | /** |
||
88 | * Add the Command Handler |
||
89 | * |
||
90 | * @param string $command Class name of the command |
||
91 | * @param string $handler Class name of the handler to be resolved from the Laravel Container |
||
92 | * @return mixed |
||
93 | */ |
||
94 | 7 | public function addHandler($command, $handler) |
|
98 | |||
99 | /** |
||
100 | * Handle the command |
||
101 | * |
||
102 | * @param $command |
||
103 | * @param $input |
||
104 | * @param $middleware |
||
105 | * @return mixed |
||
106 | */ |
||
107 | 6 | protected function handleTheCommand($command, $input, array $middleware) |
|
118 | |||
119 | /** |
||
120 | * Resolve the middleware stack from the laravel container |
||
121 | * |
||
122 | * @param $middleware |
||
123 | * @return array |
||
124 | */ |
||
125 | 6 | protected function resolveMiddleware(array $middleware) |
|
134 | |||
135 | /** |
||
136 | * Map the input to the command |
||
137 | * |
||
138 | * @param $command |
||
139 | * @param $input |
||
140 | * @return object |
||
141 | */ |
||
142 | 6 | protected function mapInputToCommand($command, $input) |
|
168 | |||
169 | /** |
||
170 | * Returns Default Value for parameter if it exists Or Fail |
||
171 | * |
||
172 | * @ReflectionParameter $parameter |
||
173 | * @return mixed |
||
174 | */ |
||
175 | 4 | private function getDefaultValueOrFail($parameter) |
|
183 | |||
184 | } |
||
185 |