@@ -8,54 +8,54 @@  | 
                                                    ||
| 8 | 8 | |
| 9 | 9 | class ClosureVoter implements IVoter  | 
                                                        
| 10 | 10 |  { | 
                                                        
| 11 | - /**  | 
                                                        |
| 12 | - * @var \Closure  | 
                                                        |
| 13 | - */  | 
                                                        |
| 14 | - private $authorizationClosure;  | 
                                                        |
| 15 | -  | 
                                                        |
| 16 | -  | 
                                                        |
| 17 | - /**  | 
                                                        |
| 18 | - * ClosureVoter constructor.  | 
                                                        |
| 19 | - * @param \Closure $authorizationClosure  | 
                                                        |
| 20 | - */  | 
                                                        |
| 21 | - public function __construct(\Closure $authorizationClosure)  | 
                                                        |
| 22 | -    { | 
                                                        |
| 23 | - $this->authorizationClosure = $authorizationClosure;  | 
                                                        |
| 24 | - }  | 
                                                        |
| 25 | -  | 
                                                        |
| 26 | -  | 
                                                        |
| 27 | - /**  | 
                                                        |
| 28 | - * @param mixed $votingSubject  | 
                                                        |
| 29 | - * @param \SpareParts\Overseer\Context\IVotingContext $votingContext  | 
                                                        |
| 30 | - * @return ISingleVoterResult  | 
                                                        |
| 31 | - */  | 
                                                        |
| 32 | - public function vote($votingSubject, IVotingContext $votingContext)  | 
                                                        |
| 33 | -    { | 
                                                        |
| 34 | - $closure = $this->authorizationClosure;  | 
                                                        |
| 35 | - $result = $closure($votingSubject, $votingContext);  | 
                                                        |
| 36 | -  | 
                                                        |
| 37 | - $result = $this->prepareResult($result);  | 
                                                        |
| 38 | -  | 
                                                        |
| 39 | - return $result;  | 
                                                        |
| 40 | - }  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | -  | 
                                                        |
| 43 | - /**  | 
                                                        |
| 44 | - * @param mixed $result  | 
                                                        |
| 45 | - * @return SingleVoterResult  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | - protected function prepareResult($result)  | 
                                                        |
| 48 | -    { | 
                                                        |
| 49 | -        if ($result === true) { | 
                                                        |
| 50 | - $result = new SingleVoterResult(VotingDecisionEnum::ALLOWED());  | 
                                                        |
| 51 | - return $result;  | 
                                                        |
| 52 | -        } elseif ($result === false) { | 
                                                        |
| 53 | - $result = new SingleVoterResult(VotingDecisionEnum::DENIED());  | 
                                                        |
| 54 | - return $result;  | 
                                                        |
| 55 | -        } elseif ($result instanceof VotingDecisionEnum) { | 
                                                        |
| 56 | - $result = new SingleVoterResult($result);  | 
                                                        |
| 57 | - return $result;  | 
                                                        |
| 58 | - }  | 
                                                        |
| 59 | - return $result;  | 
                                                        |
| 60 | - }  | 
                                                        |
| 11 | + /**  | 
                                                        |
| 12 | + * @var \Closure  | 
                                                        |
| 13 | + */  | 
                                                        |
| 14 | + private $authorizationClosure;  | 
                                                        |
| 15 | +  | 
                                                        |
| 16 | +  | 
                                                        |
| 17 | + /**  | 
                                                        |
| 18 | + * ClosureVoter constructor.  | 
                                                        |
| 19 | + * @param \Closure $authorizationClosure  | 
                                                        |
| 20 | + */  | 
                                                        |
| 21 | + public function __construct(\Closure $authorizationClosure)  | 
                                                        |
| 22 | +	{ | 
                                                        |
| 23 | + $this->authorizationClosure = $authorizationClosure;  | 
                                                        |
| 24 | + }  | 
                                                        |
| 25 | +  | 
                                                        |
| 26 | +  | 
                                                        |
| 27 | + /**  | 
                                                        |
| 28 | + * @param mixed $votingSubject  | 
                                                        |
| 29 | + * @param \SpareParts\Overseer\Context\IVotingContext $votingContext  | 
                                                        |
| 30 | + * @return ISingleVoterResult  | 
                                                        |
| 31 | + */  | 
                                                        |
| 32 | + public function vote($votingSubject, IVotingContext $votingContext)  | 
                                                        |
| 33 | +	{ | 
                                                        |
| 34 | + $closure = $this->authorizationClosure;  | 
                                                        |
| 35 | + $result = $closure($votingSubject, $votingContext);  | 
                                                        |
| 36 | +  | 
                                                        |
| 37 | + $result = $this->prepareResult($result);  | 
                                                        |
| 38 | +  | 
                                                        |
| 39 | + return $result;  | 
                                                        |
| 40 | + }  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | +  | 
                                                        |
| 43 | + /**  | 
                                                        |
| 44 | + * @param mixed $result  | 
                                                        |
| 45 | + * @return SingleVoterResult  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | + protected function prepareResult($result)  | 
                                                        |
| 48 | +	{ | 
                                                        |
| 49 | +		if ($result === true) { | 
                                                        |
| 50 | + $result = new SingleVoterResult(VotingDecisionEnum::ALLOWED());  | 
                                                        |
| 51 | + return $result;  | 
                                                        |
| 52 | +		} elseif ($result === false) { | 
                                                        |
| 53 | + $result = new SingleVoterResult(VotingDecisionEnum::DENIED());  | 
                                                        |
| 54 | + return $result;  | 
                                                        |
| 55 | +		} elseif ($result instanceof VotingDecisionEnum) { | 
                                                        |
| 56 | + $result = new SingleVoterResult($result);  | 
                                                        |
| 57 | + return $result;  | 
                                                        |
| 58 | + }  | 
                                                        |
| 59 | + return $result;  | 
                                                        |
| 60 | + }  | 
                                                        |
| 61 | 61 | }  |