| 1 | <?php |
||
| 19 | class MultiStrategy implements StrategyInterface |
||
| 20 | { |
||
| 21 | /** @var StrategyInterface[] */ |
||
| 22 | private $strategies = []; |
||
| 23 | |||
| 24 | /** @var Role[] */ |
||
| 25 | private $roles = []; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * MultiStrategy add. |
||
| 29 | * |
||
| 30 | * @param StrategyInterface $strategy strategy to be applied. |
||
| 31 | * @return void |
||
| 32 | */ |
||
| 33 | 2 | public function addStrategy(StrategyInterface $strategy) |
|
| 34 | { |
||
| 35 | 2 | $this->strategies[] = $strategy; |
|
| 36 | 2 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Applies the defined strategies on the provided request. |
||
| 40 | * |
||
| 41 | * @param Request $request request to handle |
||
| 42 | * |
||
| 43 | * @return string |
||
|
|
|||
| 44 | */ |
||
| 45 | 2 | public function apply(Request $request) |
|
| 46 | { |
||
| 47 | 2 | foreach ($this->strategies as $strategy) { |
|
| 48 | 2 | $name = $strategy->apply($request); |
|
| 49 | 2 | if ($strategy->stopPropagation()) { |
|
| 50 | 2 | $this->roles = $strategy->getRoles(); |
|
| 51 | 2 | return $name; |
|
| 52 | 1 | } |
|
| 53 | 1 | } |
|
| 54 | |||
| 55 | return false; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Decider to stop other strategies running after from being considered. |
||
| 60 | * |
||
| 61 | * @return boolean |
||
| 62 | */ |
||
| 63 | public function stopPropagation() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Provides the list of registered roles. |
||
| 70 | * |
||
| 71 | * @return Role[] |
||
| 72 | */ |
||
| 73 | 2 | public function getRoles() |
|
| 77 | } |
||
| 78 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.