-
Notifications
You must be signed in to change notification settings - Fork 3
/
AccessRule.php
52 lines (45 loc) · 1.24 KB
/
AccessRule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* @author Weavora Team <hello@weavora.com>
* @link http://weavora.com
* @copyright Copyright (c) 2011 Weavora LLC
*/
class AccessRule extends CComponent
{
/**
* @var boolean whether this is an 'allow' rule or 'deny' rule.
*/
public $allow;
/**
* @var string the error message to be displayed when authorization is denied by this rule.
* If not set, a default error message will be displayed.
* @since 1.1.1
*/
public $message;
/**
* @var array of AccessRullesTerms
*/
public $termsList = array();
/**
* Checks whether the Web user is allowed to perform the specified action.
* @param CWebUser $user the user object
* @param CController $controller the controller currently being executed
* @param CAction $action the action to be performed
* @param string $ip the request IP address
* @param string $verb the request verb (GET, POST, etc.)
* @return integer 1 if the user is allowed, -1 if the user is denied, 0 if the rule does not apply to the user
*/
public function isUserAllowed()
{
foreach ($this->termsList as $term) {
if (!$term->match()) {
return 0;
}
}
return $this->allow ? 1 : -1;
}
public function addTerm(AccessControlTerm $term)
{
$this->termsList[] = $term;
}
}