Completed
Push — master ( 6a1952...4296cb )
by Fabrice
02:35
created

CallbackWrapper::fail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Events;
11
12
use fab2s\NodalFlow\Callbacks\CallbackInterface;
13
use fab2s\NodalFlow\NodalFlow;
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
16
/**
17
 * Class CallbackWrapper
18
 */
19
class CallbackWrapper implements EventSubscriberInterface
20
{
21
    /**
22
     * The registered Callback class
23
     *
24
     * @var CallbackInterface
25
     */
26
    protected $callBack;
27
28
    /**
29
     * CallbackWrapper constructor.
30
     *
31
     * @param CallbackInterface $callBack
32
     */
33
    public function __construct(CallbackInterface $callBack)
34
    {
35
        $this->callBack = $callBack;
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public static function getSubscribedEvents()
42
    {
43
        return [
44
            FlowEvent::FLOW_START    => ['start', 0],
45
            FlowEvent::FLOW_PROGRESS => ['progress', 0],
46
            FlowEvent::FLOW_SUCCESS  => ['success', 0],
47
            FlowEvent::FLOW_FAIL     => ['fail', 0],
48
        ];
49
    }
50
51
    /**
52
     * Triggered when a Flow starts
53
     *
54
     * @param FlowEventInterface $event
55
     */
56
    public function start(FlowEventInterface $event)
57
    {
58
        $this->callBack->start($event->getFlow());
59
    }
60
61
    /**
62
     * Triggered when a Flow progresses,
63
     * eg exec once or generates once
64
     *
65
     * @param FlowEventInterface $event
66
     */
67
    public function progress(FlowEventInterface $event)
68
    {
69
        $this->callBack->progress($event->getFlow(), $event->getNode());
70
    }
71
72
    /**
73
     * Triggered when a Flow completes without exceptions
74
     *
75
     * @param FlowEventInterface $event
76
     */
77
    public function success(FlowEventInterface $event)
78
    {
79
        $this->callBack->success($event->getFlow());
80
    }
81
82
    /**
83
     * Triggered when a Flow fails
84
     *
85
     * @param FlowEventInterface $event
86
     */
87
    public function fail(FlowEventInterface $event)
88
    {
89
        $this->callBack->fail($event->getFlow());
90
    }
91
}
92