1
|
|
|
<?php |
2
|
|
|
namespace rtens\domin\delivery\web\home; |
3
|
|
|
|
4
|
|
|
use rtens\domin\Action; |
5
|
|
|
use rtens\domin\ActionRegistry; |
6
|
|
|
use rtens\domin\delivery\web\ActionGroups; |
7
|
|
|
use rtens\domin\delivery\web\WebApplication; |
8
|
|
|
use rtens\domin\execution\access\AccessControl; |
9
|
|
|
use rtens\domin\Parameter; |
10
|
|
|
use rtens\domin\reflection\CommentParser; |
11
|
|
|
|
12
|
|
|
class ListActions implements Action { |
13
|
|
|
|
14
|
|
|
/** @var ActionRegistry */ |
15
|
|
|
private $actions; |
16
|
|
|
|
17
|
|
|
/** @var ActionGroups */ |
18
|
|
|
private $groups; |
19
|
|
|
|
20
|
|
|
/** @var AccessControl */ |
21
|
|
|
private $access; |
22
|
|
|
|
23
|
|
|
/** @var CommentParser */ |
24
|
|
|
private $parser; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param ActionRegistry $actions |
28
|
|
|
* @param ActionGroups $groups |
29
|
|
|
* @param AccessControl $access |
30
|
|
|
* @param CommentParser $parser |
31
|
|
|
*/ |
32
|
|
|
public function __construct(ActionRegistry $actions, ActionGroups $groups, AccessControl $access, CommentParser $parser) { |
33
|
|
|
$this->actions = $actions; |
34
|
|
|
$this->groups = $groups; |
35
|
|
|
$this->access = $access; |
36
|
|
|
$this->parser = $parser; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return string |
41
|
|
|
*/ |
42
|
|
|
public function caption() { |
43
|
|
|
return 'Actions'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string|null |
48
|
|
|
*/ |
49
|
|
|
public function description() { |
50
|
|
|
return null; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return boolean True if the action modifies the state of the application |
55
|
|
|
*/ |
56
|
|
|
public function isModifying() { |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return Parameter[] |
62
|
|
|
*/ |
63
|
|
|
public function parameters() { |
64
|
|
|
return []; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Fills out partially available parameters |
69
|
|
|
* |
70
|
|
|
* @param array $parameters Available values indexed by name |
71
|
|
|
* @return array Filled values indexed by name |
72
|
|
|
*/ |
73
|
|
|
public function fill(array $parameters) { |
74
|
|
|
return []; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param mixed[] $parameters Values indexed by name |
79
|
|
|
* @return mixed the result of the execution |
80
|
|
|
* @throws \Exception if Action cannot be executed |
81
|
|
|
*/ |
82
|
|
|
public function execute(array $parameters) { |
83
|
|
|
return new ActionList($this->groups, $this->assembleActions()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
private function assembleActions() { |
87
|
|
|
$actions = []; |
88
|
|
|
foreach ($this->actions->getAllActions() as $id => $action) { |
89
|
|
|
if ($id != WebApplication::INDEX_ACTION && $this->access->isPermitted($id)) { |
90
|
|
|
$actions[] = new ActionListItem( |
91
|
|
|
$id, |
92
|
|
|
$action->caption(), |
93
|
|
|
$this->parser->shorten($action->description()) |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
return $actions; |
98
|
|
|
} |
99
|
|
|
} |