ActionCommandHelperTrait::getAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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