AclControllerTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
eloc 11
c 4
b 0
f 2
dl 0
loc 34
ccs 9
cts 11
cp 0.8182
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValidRole() 0 14 4
A isValid() 0 2 1
1
<?php
2
3
namespace Ubiquity\security\acl\controllers;
4
5
use Ubiquity\security\acl\AclManager;
6
use Ubiquity\exceptions\AclException;
7
use Ubiquity\log\Logger;
8
9
/**
10
 * To use with a controller with acls.
11
 * Ubiquity\security\acl\controllers$AclControllerTrait
12
 * This class is part of Ubiquity
13
 *
14
 * @author jc
15
 * @version 1.0.1
16
 *
17
 */
18
trait AclControllerTrait {
19
	public abstract function _getRole();
20
	
21
	/**
22
	 * Returns True if access to the controller is allowed for $role.
23
	 *
24
	 * @param string $action
25
	 * @param string $role
26
	 * @return boolean
27
	 */
28 1
	protected function isValidRole($action,$role) {
29 1
		$controller=\get_class($this);
30 1
		$resourceController = AclManager::getPermissionMap ()->getRessourcePermission ( $controller, $action );
31 1
		if (isset ( $resourceController )) {
32
			try{
33 1
				if (AclManager::isAllowed ( $role, $resourceController ['resource'], $resourceController ['permission'] )) {
34 1
					return true;
35
				}
36
			}
37
			catch(AclException $e){
38
				Logger::alert('Router', $role.' is not allowed for this resource','Acls',[$controller,$action]);
39
			}
40
		}
41 1
		return false;
42
	}
43
	/**
44
	 * Returns True if access to the controller is allowed for the role returned by _getRole method.
45
	 * To be override in sub classes
46
	 *
47
	 * @param string $action
48
	 * @return boolean
49
	 */
50 1
	public function isValid($action) {
51 1
		return $this->isValidRole($action, $this->_getRole());
52
	}
53
}
54
55