1 | <?php |
||
5 | class Command { |
||
6 | |||
7 | /** |
||
8 | * Execute a command |
||
9 | * @param \DeGraciaMathieu\Clike\Contracts\Command $command |
||
10 | * @return array |
||
11 | */ |
||
12 | 3 | public function execute(Contracts\Command $command) :array |
|
13 | { |
||
14 | 3 | if ($command->authorized()) { |
|
15 | 2 | return $this->launch($command); |
|
16 | } |
||
17 | |||
18 | 1 | return $this->unauthorize($command); |
|
19 | } |
||
20 | |||
21 | /** |
||
22 | * Launch an authorized command |
||
23 | * @param \DeGraciaMathieu\Clike\Contracts\Command $command |
||
24 | * @return array |
||
25 | */ |
||
26 | 2 | protected function launch(Contracts\Command $command) :array |
|
34 | |||
35 | /** |
||
36 | * Response for a unauthorized command |
||
37 | * @param \DeGraciaMathieu\Clike\Contracts\Command $command |
||
38 | * @return array |
||
39 | */ |
||
40 | 1 | protected function unauthorize(Contracts\Command $command) :array |
|
41 | { |
||
42 | 1 | $output = new Outputs\Unauthorize($command); |
|
43 | |||
44 | 1 | return $this->interpretOutput($output); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * return command response |
||
49 | * @param \DeGraciaMathieu\Clike\Contracts\Output $output |
||
50 | * @return array |
||
51 | */ |
||
52 | 3 | protected function interpretOutput(Contracts\Output $output) :array |
|
56 | } |
||
57 |