1 | <?php |
||
16 | class CallbackHandler |
||
17 | { |
||
18 | /** |
||
19 | * @deprecated To be removed in 2.0 |
||
20 | */ |
||
21 | const ALL = 'all'; |
||
22 | |||
23 | /** |
||
24 | * @var StateMachineDispatcher |
||
25 | */ |
||
26 | protected $dispatcher; |
||
27 | |||
28 | /** |
||
29 | * @var OptionsResolver |
||
30 | */ |
||
31 | protected $specResolver; |
||
32 | |||
33 | /** |
||
34 | * @param StateMachineDispatcher $dispatcher |
||
35 | */ |
||
36 | 35 | public function __construct(StateMachineDispatcher $dispatcher) |
|
37 | { |
||
38 | 35 | $this->dispatcher = $dispatcher; |
|
39 | 35 | $this->specResolver = new OptionsResolver(); |
|
40 | 35 | $this->specResolver->setDefaults( |
|
41 | array( |
||
42 | 35 | 'on' => self::ALL, |
|
43 | 35 | 'from' => self::ALL, |
|
44 | 35 | 'to' => self::ALL, |
|
45 | ) |
||
46 | 21 | ); |
|
47 | |||
48 | 35 | $this->specResolver->setAllowedTypes('on', array('string', 'array')); |
|
49 | 35 | $this->specResolver->setAllowedTypes('from', array('string', 'array')); |
|
50 | 35 | $this->specResolver->setAllowedTypes('to', array('string', 'array')); |
|
51 | |||
52 | 35 | $toArrayNormalizer = function (Options $options, $value) { |
|
53 | return (array) $value; |
||
54 | 35 | }; |
|
55 | |||
56 | 35 | $this->specResolver->setNormalizer('on', $toArrayNormalizer); |
|
57 | 35 | $this->specResolver->setNormalizer('from', $toArrayNormalizer); |
|
58 | 35 | $this->specResolver->setNormalizer('to', $toArrayNormalizer); |
|
59 | 35 | } |
|
60 | |||
61 | /** |
||
62 | * @param StateMachineInterface|Callback $smOrCallback |
||
63 | * @param callable $callback |
||
64 | * @param array $spec |
||
65 | * |
||
66 | * @return CallbackHandler |
||
67 | */ |
||
68 | 30 | public function addBefore($smOrCallback, $callback = null, array $spec = array()) |
|
74 | |||
75 | /** |
||
76 | * @param StateMachineInterface|Callback $smOrCallback |
||
77 | * @param callable $callback |
||
78 | * @param array $spec |
||
79 | * |
||
80 | * @return CallbackHandler |
||
81 | */ |
||
82 | 5 | public function addAfter($smOrCallback, $callback = null, array $spec = array()) |
|
88 | |||
89 | /** |
||
90 | * @param StateMachineInterface|Callback $smOrCallback |
||
91 | * @param string $event |
||
92 | * @param callable $callable |
||
93 | * @param array $specs |
||
94 | * |
||
95 | * @return CallbackHandler |
||
96 | */ |
||
97 | 35 | protected function add($smOrCallback, $event, $callable = null, array $specs = array()) |
|
117 | } |
||
118 |