1 | <?php |
||
14 | class CallbackSpecification implements CallbackSpecificationInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | private $specs = array(); |
||
20 | |||
21 | /** |
||
22 | * @var StateMachineInterface |
||
23 | */ |
||
24 | private $stateMachine; |
||
25 | |||
26 | /** |
||
27 | * @param StateMachineInterface $sm |
||
28 | * @param array $from |
||
29 | * @param array $to |
||
30 | * @param array $on |
||
31 | */ |
||
32 | 60 | public function __construct(StateMachineInterface $sm, array $from, array $to, array $on) |
|
33 | { |
||
34 | 60 | $this->stateMachine = $sm; |
|
35 | |||
36 | $isExclusion = function ($str) { return 0 === strpos($str, '-'); }; |
||
37 | $removeDash = function ($str) { return substr($str, 1); }; |
||
38 | |||
39 | 60 | foreach (array('from', 'to', 'on') as $clause) { |
|
40 | 60 | $excludedClause = 'excluded_'.$clause; |
|
41 | |||
42 | 60 | $this->specs[$excludedClause] = array_filter(${$clause}, $isExclusion); |
|
43 | 60 | $this->specs[$clause] = array_diff(${$clause}, $this->specs[$excludedClause]); |
|
44 | 60 | $this->specs[$excludedClause] = array_map($removeDash, $this->specs[$excludedClause]); |
|
45 | |||
46 | // For compatibility with old CallbackHandler. |
||
47 | // To be removed in 2.0 |
||
48 | 60 | if (in_array(CallbackHandler::ALL, $this->specs[$clause])) { |
|
49 | 36 | $this->specs[$clause] = array(); |
|
50 | } |
||
51 | } |
||
52 | 60 | } |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 39 | public function isSatisfiedBy(TransitionEvent $event) |
|
65 | |||
66 | /** |
||
67 | * @param string $clause |
||
68 | * @param string $property |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 39 | private function supportsClause($clause, $property) |
|
80 | } |
||
81 |