|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the LightSAML-Core package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Milos Tomic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LightSaml\Builder\Action; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\Action\ActionInterface; |
|
15
|
|
|
use LightSaml\Action\CompositeAction; |
|
16
|
|
|
|
|
17
|
|
|
class CompositeActionBuilder implements ActionBuilderInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* int priority => ActionInterface[]. |
|
21
|
|
|
* |
|
22
|
|
|
* @var array |
|
23
|
|
|
*/ |
|
24
|
|
|
private $actions = []; |
|
25
|
|
|
|
|
26
|
|
|
/** @var int */ |
|
27
|
|
|
protected $increaseStep = 5; |
|
28
|
|
|
|
|
29
|
|
|
/** @var int */ |
|
30
|
|
|
private $biggestPriority = 0; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param int|bool $priority |
|
34
|
|
|
* |
|
35
|
|
|
* @return CompositeActionBuilder |
|
36
|
|
|
*/ |
|
37
|
|
|
public function add(ActionInterface $action, $priority = false) |
|
38
|
|
|
{ |
|
39
|
|
|
if (false === $priority) { |
|
40
|
|
|
++$this->biggestPriority; |
|
41
|
|
|
$priority = $this->biggestPriority; |
|
42
|
|
|
} elseif (false === is_int($priority)) { |
|
43
|
|
|
throw new \InvalidArgumentException('Expected integer value for priority'); |
|
44
|
|
|
} elseif ($priority > $this->biggestPriority) { |
|
45
|
|
|
$this->biggestPriority = $priority; |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if (false === isset($this->actions[$priority])) { |
|
49
|
|
|
$this->actions[$priority] = []; |
|
50
|
|
|
} |
|
51
|
|
|
$this->actions[$priority][] = $action; |
|
52
|
|
|
|
|
53
|
|
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return CompositeAction |
|
58
|
|
|
*/ |
|
59
|
|
|
public function build() |
|
60
|
|
|
{ |
|
61
|
|
|
$actions = $this->actions; |
|
62
|
|
|
ksort($actions); |
|
63
|
|
|
|
|
64
|
|
|
$result = new CompositeAction(); |
|
65
|
|
|
foreach ($actions as $arr) { |
|
66
|
|
|
foreach ($arr as $action) { |
|
67
|
|
|
$result->add($action); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $result; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
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.