|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace tomzx\PolicyEvaluator; |
|
4
|
|
|
|
|
5
|
|
|
class Statement |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @var \tomzx\PolicyEvaluator\Action |
|
9
|
|
|
*/ |
|
10
|
|
|
private $action; |
|
11
|
|
|
/** |
|
12
|
|
|
* @var \tomzx\PolicyEvaluator\Resource |
|
13
|
|
|
*/ |
|
14
|
|
|
private $resource; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var \tomzx\PolicyEvaluator\Effect |
|
18
|
|
|
*/ |
|
19
|
|
|
private $effect; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param array $statement |
|
23
|
|
|
*/ |
|
24
|
14 |
|
public function __construct(array $statement) |
|
25
|
|
|
{ |
|
26
|
14 |
|
if (!isset($statement['Action'])) { |
|
27
|
2 |
|
throw new \InvalidArgumentException('Missing required field Action.'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
12 |
|
if (!isset($statement['Resource'])) { |
|
31
|
1 |
|
throw new \InvalidArgumentException('Missing required field Resource.'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
11 |
|
if (!isset($statement['Effect'])) { |
|
35
|
1 |
|
throw new \InvalidArgumentException('Missing required field Effect.'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
10 |
|
$this->action = new Action($statement['Action']); |
|
39
|
10 |
|
$this->resource = new Resource($statement['Resource']); |
|
40
|
10 |
|
$this->effect = new Effect($statement['Effect']); |
|
41
|
10 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return \tomzx\PolicyEvaluator\Action |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getAction() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->action; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return \tomzx\PolicyEvaluator\Resource |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getResource() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->resource; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return \tomzx\PolicyEvaluator\Effect |
|
61
|
|
|
*/ |
|
62
|
6 |
|
public function getEffect() |
|
63
|
|
|
{ |
|
64
|
6 |
|
return $this->effect; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $resource |
|
69
|
|
|
* @param array $variables |
|
70
|
|
|
* @return bool |
|
71
|
|
|
*/ |
|
72
|
7 |
|
public function matchesResource($resource, array $variables = []) |
|
73
|
|
|
{ |
|
74
|
7 |
|
return $this->resource->matches($resource, $variables); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $action |
|
79
|
|
|
* @return bool |
|
80
|
|
|
*/ |
|
81
|
8 |
|
public function matchesAction($action) |
|
82
|
|
|
{ |
|
83
|
8 |
|
return $this->action->matches($action); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|