|
1
|
|
|
<?php |
|
2
|
|
|
namespace SimpleAcl; |
|
3
|
|
|
|
|
4
|
|
|
use SimpleAcl\Resource\ResourceAggregateInterface; |
|
5
|
|
|
use SimpleAcl\Role\RoleAggregateInterface; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Returned as result of Rule::isAllowed |
|
9
|
|
|
* |
|
10
|
|
|
* @package SimpleAcl |
|
11
|
|
|
*/ |
|
12
|
|
|
class RuleResult |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var Rule |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $rule; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $needRoleName; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $needResourceName; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var int |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $priority; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $id; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $action; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var bool |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $isInit = false; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param Rule $rule |
|
51
|
|
|
* @param int $priority |
|
52
|
|
|
* @param $needRoleName |
|
53
|
|
|
* @param $needResourceName |
|
54
|
|
|
*/ |
|
55
|
31 |
|
public function __construct(Rule $rule, $priority, $needRoleName, $needResourceName) |
|
56
|
|
|
{ |
|
57
|
31 |
|
static $idCountRuleResultSimpleAcl = 1; |
|
58
|
|
|
|
|
59
|
31 |
|
$this->id = $idCountRuleResultSimpleAcl++; |
|
|
|
|
|
|
60
|
31 |
|
$this->rule = $rule; |
|
61
|
31 |
|
$this->priority = $priority; |
|
62
|
31 |
|
$this->needRoleName = $needRoleName; |
|
63
|
31 |
|
$this->needResourceName = $needResourceName; |
|
64
|
31 |
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param int $priority |
|
68
|
|
|
*/ |
|
69
|
1 |
|
public function setPriority($priority) |
|
70
|
|
|
{ |
|
71
|
1 |
|
$this->priority = $priority; |
|
72
|
1 |
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
2 |
|
public function getNeedResourceName() |
|
78
|
|
|
{ |
|
79
|
2 |
|
return $this->needResourceName; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function getNeedRoleName() |
|
86
|
|
|
{ |
|
87
|
2 |
|
return $this->needRoleName; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @return Rule |
|
92
|
|
|
*/ |
|
93
|
27 |
|
public function getRule() |
|
94
|
|
|
{ |
|
95
|
27 |
|
return $this->rule; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @return bool |
|
100
|
|
|
*/ |
|
101
|
27 |
|
public function getAction() |
|
102
|
|
|
{ |
|
103
|
27 |
|
if (!$this->isInit) { |
|
104
|
27 |
|
$this->action = $this->getRule()->getAction($this); |
|
105
|
27 |
|
$this->isInit = true; |
|
106
|
27 |
|
} |
|
107
|
|
|
|
|
108
|
27 |
|
return $this->action; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return int |
|
113
|
|
|
*/ |
|
114
|
2 |
|
public function getPriority() |
|
115
|
|
|
{ |
|
116
|
2 |
|
return $this->priority; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
1 |
|
public function getId() |
|
123
|
|
|
{ |
|
124
|
1 |
|
return $this->id; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return ResourceAggregateInterface |
|
129
|
|
|
*/ |
|
130
|
2 |
|
public function getResourceAggregate() |
|
131
|
|
|
{ |
|
132
|
2 |
|
return $this->getRule()->getResourceAggregate(); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return RoleAggregateInterface |
|
137
|
|
|
*/ |
|
138
|
2 |
|
public function getRoleAggregate() |
|
139
|
|
|
{ |
|
140
|
2 |
|
return $this->getRule()->getRoleAggregate(); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.