Completed
Push — master ( 5c3876...859b6d )
by Thierry
01:35
created

Callback   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 5
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 117
rs 10
c 0
b 0
f 0
wmc 10
lcom 5
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 0 8 2
A after() 0 8 2
A invalid() 0 8 2
A error() 0 8 2
A init() 0 8 2
1
<?php
2
3
/**
4
 * Callbacks.php - Jaxon request callbacks
5
 *
6
 * @package jaxon-core
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2017 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-core
11
 */
12
13
namespace Jaxon\Request\Handler;
14
15
class Callback
16
{
17
    /**
18
     * The callback to run before processing the request
19
     *
20
     * @var Callable
21
     */
22
    protected $xBeforeCallback = null;
23
24
    /**
25
     * The callback to run afteer processing the request
26
     *
27
     * @var Callable
28
     */
29
    protected $xAfterCallback = null;
30
31
    /**
32
     * The callback to run in case of invalid request
33
     *
34
     * @var Callable
35
     */
36
    protected $xInvalidCallback = null;
37
38
    /**
39
     * The callback to run in case of error
40
     *
41
     * @var Callable
42
     */
43
    protected $xErrorCallback = null;
44
45
    /**
46
     * The callback to run when a class is instanciated
47
     *
48
     * @var Callable
49
     */
50
    protected $xInitCallback = null;
51
52
    /**
53
     * Get or set the pre-request processing callback.
54
     *
55
     * @param Callable|null  $xCallable               The callback function
56
     *
57
     * @return void
58
     */
59
    public function before($xCallable = null)
60
    {
61
        if($xCallable === null)
62
        {
63
            return $this->xBeforeCallback;
64
        }
65
        $this->xBeforeCallback = $xCallable;
66
    }
67
68
    /**
69
     * Get or set the post-request processing callback.
70
     *
71
     * @param Callable|null  $xCallable               The callback function
72
     *
73
     * @return void
74
     */
75
    public function after($xCallable = null)
76
    {
77
        if($xCallable === null)
78
        {
79
            return $this->xAfterCallback;
80
        }
81
        $this->xAfterCallback = $xCallable;
82
    }
83
84
    /**
85
     * Get or set the invalid request callback.
86
     *
87
     * @param Callable|null  $xCallable               The callback function
88
     *
89
     * @return void
90
     */
91
    public function invalid($xCallable = null)
92
    {
93
        if($xCallable === null)
94
        {
95
            return $this->xInvalidCallback;
96
        }
97
        $this->xInvalidCallback = $xCallable;
98
    }
99
100
    /**
101
     * Get or set the processing error callback.
102
     *
103
     * @param Callable|null  $xCallable               The callback function
104
     *
105
     * @return void
106
     */
107
    public function error($xCallable = null)
108
    {
109
        if($xCallable === null)
110
        {
111
            return $this->xErrorCallback;
112
        }
113
        $this->xErrorCallback = $xCallable;
114
    }
115
116
    /**
117
     * Get or set the class initialisation callback.
118
     *
119
     * @param Callable|null  $xCallable               The callback function
120
     *
121
     * @return void
122
     */
123
    public function init($xCallable = null)
124
    {
125
        if($xCallable === null)
126
        {
127
            return $this->xInitCallback;
128
        }
129
        $this->xInitCallback = $xCallable;
130
    }
131
}
132