1
|
|
|
<?php |
2
|
|
|
namespace keeko\tools\helpers; |
3
|
|
|
|
4
|
|
|
use keeko\framework\schema\ActionSchema; |
5
|
|
|
use keeko\tools\services\CommandService; |
6
|
|
|
use keeko\tools\utils\NamespaceResolver; |
7
|
|
|
use keeko\framework\utils\NameUtils; |
8
|
|
|
|
9
|
|
|
trait ActionCommandHelperTrait { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @return CommandService |
13
|
|
|
*/ |
14
|
|
|
abstract protected function getService(); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* |
18
|
|
|
* @param string $actionName |
19
|
|
|
* @return ActionSchema |
20
|
|
|
*/ |
21
|
|
|
private function getAction($actionName) { |
22
|
|
|
$packageService = $this->getService()->getPackageService(); |
23
|
|
|
$action = $packageService->getAction($actionName); |
24
|
|
|
if ($action === null) { |
25
|
|
|
$action = new ActionSchema($actionName); |
26
|
|
|
$module = $packageService->getModule(); |
27
|
|
|
$module->addAction($action); |
28
|
|
|
} |
29
|
|
|
return $action; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
private function getAcl(ActionSchema $action) { |
33
|
|
|
$input = $this->getService()->getIOService()->getInput(); |
34
|
|
|
$acls = []; |
35
|
|
|
$acl = $input->getOption('acl'); |
36
|
|
|
if ($acl !== null && count($acl) > 0) { |
37
|
|
|
if (!is_array($acl)) { |
38
|
|
|
$acl = [$acl]; |
39
|
|
|
} |
40
|
|
|
foreach ($acl as $group) { |
41
|
|
|
if (strpos($group, ',') !== false) { |
42
|
|
|
$groups = explode(',', $group); |
43
|
|
|
foreach ($groups as $g) { |
44
|
|
|
$acls[] = trim($g); |
45
|
|
|
} |
46
|
|
|
} else { |
47
|
|
|
$acls[] = $group; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $acls; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// read default from package |
55
|
|
|
if (!$action->getAcl()->isEmpty()) { |
56
|
|
|
return $action->getAcl()->toArray(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $acls; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function guessClassname($name) { |
63
|
|
|
$package = $this->getService()->getPackageService()->getPackage(); |
64
|
|
|
$namespace = NamespaceResolver::getNamespace('src/action', $package); |
65
|
|
|
return $namespace . '\\' . NameUtils::toStudlyCase($name) . 'Action'; |
66
|
|
|
} |
67
|
|
|
} |