|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of NodalFlow. |
|
5
|
|
|
* (c) Fabrice de Stefanis / https://github.com/fab2s/NodalFlow |
|
6
|
|
|
* This source file is licensed under the MIT license which you will |
|
7
|
|
|
* find in the LICENSE file or at https://opensource.org/licenses/MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace fab2s\NodalFlow\Nodes; |
|
11
|
|
|
|
|
12
|
|
|
use fab2s\NodalFlow\Flows\InterrupterInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Abstract Class InterruptNodeAbstract |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class InterruptNodeAbstract extends NodeAbstract implements InterruptNodeInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Indicate if this Node is traversable |
|
21
|
|
|
* |
|
22
|
|
|
* @var bool |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $isATraversable = false; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Indicate if this Node is returning a value |
|
28
|
|
|
* |
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $isAReturningVal = false; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Indicate if this Node is a Flow (Branch) |
|
35
|
|
|
* |
|
36
|
|
|
* @var bool |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $isAFlow = false; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The interrupt's method interface is simple : |
|
42
|
|
|
* - return false to break |
|
43
|
|
|
* - return true to continue |
|
44
|
|
|
* - return void|null (whatever) to proceed with the flow |
|
45
|
|
|
* |
|
46
|
|
|
* @param mixed|null $param |
|
47
|
|
|
*/ |
|
48
|
|
|
public function exec($param = null) |
|
49
|
|
|
{ |
|
50
|
|
|
$flowInterrupt = $this->interrupt($param); |
|
51
|
|
|
if ($flowInterrupt === null) { |
|
52
|
|
|
// do nothing, let the flow proceed |
|
53
|
|
|
return; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if ($flowInterrupt instanceof InterrupterInterface) { |
|
57
|
|
|
$flowInterruptType = $flowInterrupt->getType(); |
|
58
|
|
|
} elseif ($flowInterrupt) { |
|
59
|
|
|
$flowInterruptType = InterrupterInterface::TYPE_CONTINUE; |
|
60
|
|
|
$flowInterrupt = null; |
|
61
|
|
|
} else { |
|
62
|
|
|
$flowInterruptType = InterrupterInterface::TYPE_BREAK; |
|
63
|
|
|
$flowInterrupt = null; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/* @var null|InterrupterInterface $flowInterrupt */ |
|
67
|
|
|
$this->carrier->interruptFlow($flowInterruptType, $flowInterrupt); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|