Completed
Push — master ( 1c2262...88c0f4 )
by Thomas
05:39
created

ActionCommandHelperTrait::guessClassname()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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
}