AbstractCommand   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 3
cbo 0
dl 0
loc 77
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A onExecute() 0 4 1
A onComplete() 0 4 1
A onRollBack() 0 4 1
A execute() 0 6 2
A complete() 0 6 2
A rollBack() 0 6 2
1
<?php
2
/**
3
 * Spiral, Core Components
4
 *
5
 * @author Wolfy-J
6
 */
7
8
namespace Spiral\ORM\Commands;
9
10
use Spiral\ORM\CommandInterface;
11
12
/**
13
 * Provides support for command events.
14
 */
15
abstract class AbstractCommand implements CommandInterface
16
{
17
    /**
18
     * @var \Closure[]
19
     */
20
    private $onExecute = [];
21
22
    /**
23
     * @var \Closure[]
24
     */
25
    private $onComplete = [];
26
27
    /**
28
     * @var \Closure[]
29
     */
30
    private $onRollBack = [];
31
32
    /**
33
     * Closure to be called after command executing.
34
     *
35
     * @param \Closure $closure
36
     */
37
    final public function onExecute(\Closure $closure)
38
    {
39
        $this->onExecute[] = $closure;
40
    }
41
42
    /**
43
     * To be called after parent transaction been commited.
44
     *
45
     * @param \Closure $closure
46
     */
47
    final public function onComplete(\Closure $closure)
48
    {
49
        $this->onComplete[] = $closure;
50
    }
51
52
    /**
53
     * To be called after parent transaction been rolled back.
54
     *
55
     * @param \Closure $closure
56
     */
57
    final public function onRollBack(\Closure $closure)
58
    {
59
        $this->onRollBack[] = $closure;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function execute()
66
    {
67
        foreach ($this->onExecute as $closure) {
68
            call_user_func($closure, $this);
69
        }
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function complete()
76
    {
77
        foreach ($this->onComplete as $closure) {
78
            call_user_func($closure, $this);
79
        }
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function rollBack()
86
    {
87
        foreach ($this->onRollBack as $closure) {
88
            call_user_func($closure, $this);
89
        }
90
    }
91
}