@@ -4,67 +4,67 @@ |
||
4 | 4 | |
5 | 5 | class StrategyEnum |
6 | 6 | { |
7 | - /** |
|
8 | - * @var string |
|
9 | - */ |
|
10 | - private $value; |
|
7 | + /** |
|
8 | + * @var string |
|
9 | + */ |
|
10 | + private $value; |
|
11 | 11 | |
12 | - /** |
|
13 | - * @var self[] |
|
14 | - */ |
|
15 | - static private $registry = []; |
|
12 | + /** |
|
13 | + * @var self[] |
|
14 | + */ |
|
15 | + static private $registry = []; |
|
16 | 16 | |
17 | - private function __construct($value) |
|
18 | - { |
|
19 | - $this->value = $value; |
|
20 | - } |
|
17 | + private function __construct($value) |
|
18 | + { |
|
19 | + $this->value = $value; |
|
20 | + } |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @return self |
|
25 | - */ |
|
26 | - public static function FIRST_VOTE_DECIDES() |
|
27 | - { |
|
28 | - return static::instance('first_vote_decides'); |
|
29 | - } |
|
23 | + /** |
|
24 | + * @return self |
|
25 | + */ |
|
26 | + public static function FIRST_VOTE_DECIDES() |
|
27 | + { |
|
28 | + return static::instance('first_vote_decides'); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @return self |
|
34 | - */ |
|
35 | - public static function ALLOW_UNLESS_DENIED() |
|
36 | - { |
|
37 | - return static::instance('allow_unless_denied'); |
|
38 | - } |
|
32 | + /** |
|
33 | + * @return self |
|
34 | + */ |
|
35 | + public static function ALLOW_UNLESS_DENIED() |
|
36 | + { |
|
37 | + return static::instance('allow_unless_denied'); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @return self |
|
43 | - */ |
|
44 | - public static function DENY_UNLESS_ALLOWED() |
|
45 | - { |
|
46 | - return static::instance('deny_unless_allowed'); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @return self |
|
43 | + */ |
|
44 | + public static function DENY_UNLESS_ALLOWED() |
|
45 | + { |
|
46 | + return static::instance('deny_unless_allowed'); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @param $string |
|
52 | - * @return self |
|
53 | - */ |
|
54 | - private static function instance($string) |
|
55 | - { |
|
56 | - if (!isset(static::$registry[$string])) { |
|
57 | - static::$registry[$string] = new static($string); |
|
58 | - } |
|
59 | - return static::$registry[$string]; |
|
60 | - } |
|
50 | + /** |
|
51 | + * @param $string |
|
52 | + * @return self |
|
53 | + */ |
|
54 | + private static function instance($string) |
|
55 | + { |
|
56 | + if (!isset(static::$registry[$string])) { |
|
57 | + static::$registry[$string] = new static($string); |
|
58 | + } |
|
59 | + return static::$registry[$string]; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public function __toString() |
|
67 | - { |
|
68 | - return $this->value; |
|
69 | - } |
|
63 | + /** |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function __toString() |
|
67 | + { |
|
68 | + return $this->value; |
|
69 | + } |
|
70 | 70 | } |
@@ -5,43 +5,43 @@ |
||
5 | 5 | |
6 | 6 | class VotingResult implements IVotingResult |
7 | 7 | { |
8 | - /** |
|
9 | - * @var VotingDecisionEnum |
|
10 | - */ |
|
11 | - private $decision; |
|
12 | - |
|
13 | - /** |
|
14 | - * @var ISingleVoterResult[] |
|
15 | - */ |
|
16 | - private $partialResults; |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * VotingResult constructor. |
|
21 | - * @param VotingDecisionEnum $decision |
|
22 | - * @param ISingleVoterResult[] $partialResults |
|
23 | - */ |
|
24 | - public function __construct(VotingDecisionEnum $decision, $partialResults) |
|
8 | + /** |
|
9 | + * @var VotingDecisionEnum |
|
10 | + */ |
|
11 | + private $decision; |
|
12 | + |
|
13 | + /** |
|
14 | + * @var ISingleVoterResult[] |
|
15 | + */ |
|
16 | + private $partialResults; |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * VotingResult constructor. |
|
21 | + * @param VotingDecisionEnum $decision |
|
22 | + * @param ISingleVoterResult[] $partialResults |
|
23 | + */ |
|
24 | + public function __construct(VotingDecisionEnum $decision, $partialResults) |
|
25 | 25 | { |
26 | - $this->decision = $decision; |
|
27 | - $this->partialResults = $partialResults; |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * @return VotingDecisionEnum |
|
33 | - */ |
|
34 | - public function getDecision() |
|
35 | - { |
|
36 | - return $this->decision; |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * @return ISingleVoterResult[] |
|
42 | - */ |
|
43 | - public function getPartialResults() |
|
44 | - { |
|
45 | - return $this->partialResults; |
|
46 | - } |
|
26 | + $this->decision = $decision; |
|
27 | + $this->partialResults = $partialResults; |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * @return VotingDecisionEnum |
|
33 | + */ |
|
34 | + public function getDecision() |
|
35 | + { |
|
36 | + return $this->decision; |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * @return ISingleVoterResult[] |
|
42 | + */ |
|
43 | + public function getPartialResults() |
|
44 | + { |
|
45 | + return $this->partialResults; |
|
46 | + } |
|
47 | 47 | } |
@@ -25,10 +25,10 @@ |
||
25 | 25 | */ |
26 | 26 | public function vote($action, $votingSubject, IVotingContext $votingContext) |
27 | 27 | { |
28 | - if (!($votingSubject instanceof IVotingSubject)) { |
|
29 | - $votingSubject = new VotingSubject($votingSubject); |
|
30 | - } |
|
28 | + if (!($votingSubject instanceof IVotingSubject)) { |
|
29 | + $votingSubject = new VotingSubject($votingSubject); |
|
30 | + } |
|
31 | 31 | |
32 | - return $this->innerVote($action, $votingSubject, $votingContext); |
|
32 | + return $this->innerVote($action, $votingSubject, $votingContext); |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | interface IResult |
6 | 6 | { |
7 | - /** |
|
8 | - * @return VotingDecisionEnum |
|
9 | - */ |
|
10 | - public function getDecision(); |
|
7 | + /** |
|
8 | + * @return VotingDecisionEnum |
|
9 | + */ |
|
10 | + public function getDecision(); |
|
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -12,28 +12,28 @@ |
||
12 | 12 | private $allowedRoles; |
13 | 13 | |
14 | 14 | /** |
15 | - * @var VotingDecisionEnum |
|
16 | - */ |
|
17 | - private $resultDecision; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var mixed|null |
|
21 | - */ |
|
22 | - private $reason; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * RoleVoter constructor. |
|
27 | - * @param VotingDecisionEnum $resultDecision |
|
28 | - * @param string|string[] $allowedRoles |
|
29 | - * @param mixed $reason |
|
30 | - */ |
|
15 | + * @var VotingDecisionEnum |
|
16 | + */ |
|
17 | + private $resultDecision; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var mixed|null |
|
21 | + */ |
|
22 | + private $reason; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * RoleVoter constructor. |
|
27 | + * @param VotingDecisionEnum $resultDecision |
|
28 | + * @param string|string[] $allowedRoles |
|
29 | + * @param mixed $reason |
|
30 | + */ |
|
31 | 31 | public function __construct(VotingDecisionEnum $resultDecision, $allowedRoles, $reason = null) |
32 | 32 | { |
33 | 33 | $this->allowedRoles = (array) $allowedRoles; |
34 | - $this->resultDecision = $resultDecision; |
|
35 | - $this->reason = $reason; |
|
36 | - } |
|
34 | + $this->resultDecision = $resultDecision; |
|
35 | + $this->reason = $reason; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | 39 | /** |
@@ -27,12 +27,12 @@ |
||
27 | 27 | */ |
28 | 28 | public function getVotingSubjectName() |
29 | 29 | { |
30 | - if (is_string($this->subject)) { |
|
31 | - return $this->subject; |
|
32 | - } |
|
33 | - if (is_object($this->subject)) { |
|
34 | - return get_class($this->subject); |
|
35 | - } |
|
30 | + if (is_string($this->subject)) { |
|
31 | + return $this->subject; |
|
32 | + } |
|
33 | + if (is_object($this->subject)) { |
|
34 | + return get_class($this->subject); |
|
35 | + } |
|
36 | 36 | return (string) $this->subject; |
37 | 37 | } |
38 | 38 | } |
@@ -5,8 +5,8 @@ |
||
5 | 5 | |
6 | 6 | interface ISingleVoterResult extends IResult |
7 | 7 | { |
8 | - /** |
|
9 | - * @return mixed |
|
10 | - */ |
|
11 | - public function getReason(); |
|
8 | + /** |
|
9 | + * @return mixed |
|
10 | + */ |
|
11 | + public function getReason(); |
|
12 | 12 | } |
13 | 13 | \ No newline at end of file |
@@ -6,42 +6,42 @@ |
||
6 | 6 | class SingleVoterResult implements ISingleVoterResult |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @var VotingDecisionEnum |
|
11 | - */ |
|
12 | - private $decision; |
|
13 | - |
|
14 | - /** |
|
15 | - * @var mixed |
|
16 | - */ |
|
17 | - private $reason; |
|
18 | - |
|
19 | - |
|
20 | - /** |
|
21 | - * SingleVoterResult constructor. |
|
22 | - * @param VotingDecisionEnum $decision |
|
23 | - * @param mixed $reason |
|
24 | - */ |
|
25 | - public function __construct(VotingDecisionEnum $decision, $reason = null) |
|
26 | - { |
|
27 | - $this->decision = $decision; |
|
28 | - $this->reason = $reason; |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return VotingDecisionEnum |
|
34 | - */ |
|
35 | - public function getDecision() |
|
36 | - { |
|
37 | - return $this->decision; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return mixed |
|
42 | - */ |
|
43 | - public function getReason() |
|
44 | - { |
|
45 | - return $this->reason; |
|
46 | - } |
|
9 | + /** |
|
10 | + * @var VotingDecisionEnum |
|
11 | + */ |
|
12 | + private $decision; |
|
13 | + |
|
14 | + /** |
|
15 | + * @var mixed |
|
16 | + */ |
|
17 | + private $reason; |
|
18 | + |
|
19 | + |
|
20 | + /** |
|
21 | + * SingleVoterResult constructor. |
|
22 | + * @param VotingDecisionEnum $decision |
|
23 | + * @param mixed $reason |
|
24 | + */ |
|
25 | + public function __construct(VotingDecisionEnum $decision, $reason = null) |
|
26 | + { |
|
27 | + $this->decision = $decision; |
|
28 | + $this->reason = $reason; |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return VotingDecisionEnum |
|
34 | + */ |
|
35 | + public function getDecision() |
|
36 | + { |
|
37 | + return $this->decision; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return mixed |
|
42 | + */ |
|
43 | + public function getReason() |
|
44 | + { |
|
45 | + return $this->reason; |
|
46 | + } |
|
47 | 47 | } |
48 | 48 | \ No newline at end of file |
@@ -35,28 +35,28 @@ |
||
35 | 35 | $closure = $this->authorizationClosure; |
36 | 36 | $result = $closure($votingSubject, $votingContext); |
37 | 37 | |
38 | - $result = $this->prepareResult($result); |
|
38 | + $result = $this->prepareResult($result); |
|
39 | 39 | |
40 | - return $result; |
|
40 | + return $result; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | |
44 | 44 | /** |
45 | - * @param mixed $result |
|
46 | - * @return SingleVoterResult |
|
47 | - */ |
|
48 | - public function prepareResult($result) |
|
49 | - { |
|
50 | - if ($result === true) { |
|
51 | - $result = new SingleVoterResult(VotingDecisionEnum::ALLOWED()); |
|
52 | - return $result; |
|
53 | - } elseif ($result === false) { |
|
54 | - $result = new SingleVoterResult(VotingDecisionEnum::DENIED()); |
|
55 | - return $result; |
|
56 | - } elseif ($result instanceof VotingDecisionEnum) { |
|
57 | - $result = new SingleVoterResult($result); |
|
58 | - return $result; |
|
59 | - } |
|
60 | - return $result; |
|
61 | - } |
|
45 | + * @param mixed $result |
|
46 | + * @return SingleVoterResult |
|
47 | + */ |
|
48 | + public function prepareResult($result) |
|
49 | + { |
|
50 | + if ($result === true) { |
|
51 | + $result = new SingleVoterResult(VotingDecisionEnum::ALLOWED()); |
|
52 | + return $result; |
|
53 | + } elseif ($result === false) { |
|
54 | + $result = new SingleVoterResult(VotingDecisionEnum::DENIED()); |
|
55 | + return $result; |
|
56 | + } elseif ($result instanceof VotingDecisionEnum) { |
|
57 | + $result = new SingleVoterResult($result); |
|
58 | + return $result; |
|
59 | + } |
|
60 | + return $result; |
|
61 | + } |
|
62 | 62 | } |