Completed
Push — master ( dd800d...af5658 )
by Thomas
07:26
created

ActionCommandHelperTrait::getAcl()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

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