1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ronanchilvers\Orm\Features; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Feature trait for model hooks |
7
|
|
|
* |
8
|
|
|
* @author Ronan Chilvers <[email protected]> |
9
|
|
|
*/ |
10
|
|
|
trait HasHooks |
11
|
|
|
{ |
12
|
|
|
/************************************/ |
13
|
|
|
/** Model Hooks *********************/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* This hook fires immediately before model data is persisted to the db |
17
|
|
|
* |
18
|
|
|
* @author Ronan Chilvers <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
protected function beforePersist() |
21
|
|
|
{} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Model hook for the 'loaded' event |
25
|
|
|
* |
26
|
|
|
* @author Ronan Chilvers <[email protected]> |
27
|
|
|
*/ |
28
|
1 |
|
protected function afterLoad() |
29
|
1 |
|
{} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Model hook for the 'saving' event |
33
|
|
|
* |
34
|
|
|
* Returning boolean false from this method cancels the event |
35
|
|
|
* |
36
|
|
|
* @return boolean |
37
|
|
|
* @author Ronan Chilvers <[email protected]> |
38
|
|
|
*/ |
39
|
|
|
protected function beforeSave() |
40
|
|
|
{} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Model hook for the 'saved' event |
44
|
|
|
* |
45
|
|
|
* @author Ronan Chilvers <[email protected]> |
46
|
|
|
*/ |
47
|
|
|
protected function afterSave() |
48
|
|
|
{} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Model hook for the 'creating' event |
52
|
|
|
* |
53
|
|
|
* Returning boolean false from this method cancels the event |
54
|
|
|
* |
55
|
|
|
* @return boolean |
56
|
|
|
* @author Ronan Chilvers <[email protected]> |
57
|
|
|
*/ |
58
|
|
|
protected function beforeCreate() |
59
|
|
|
{} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Model hook for the 'created' event |
63
|
|
|
* |
64
|
|
|
* @author Ronan Chilvers <[email protected]> |
65
|
|
|
*/ |
66
|
|
|
protected function afterCreate() |
67
|
|
|
{} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Model hook for the 'updating' event |
71
|
|
|
* |
72
|
|
|
* Returning boolean false from this method cancels the event |
73
|
|
|
* |
74
|
|
|
* @return boolean |
75
|
|
|
* @author Ronan Chilvers <[email protected]> |
76
|
|
|
*/ |
77
|
|
|
protected function beforeUpdate() |
78
|
|
|
{} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Model hook for the 'updated' event |
82
|
|
|
* |
83
|
|
|
* @author Ronan Chilvers <[email protected]> |
84
|
|
|
*/ |
85
|
|
|
protected function afterUpdate() |
86
|
|
|
{} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Model hook for the 'deleting' event |
90
|
|
|
* |
91
|
|
|
* Returning boolean false from this method cancels the event |
92
|
|
|
* |
93
|
|
|
* @return boolean |
94
|
|
|
* @author Ronan Chilvers <[email protected]> |
95
|
|
|
*/ |
96
|
|
|
protected function beforeDelete() |
97
|
|
|
{} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Model hook for the 'deleted' event |
101
|
|
|
* |
102
|
|
|
* @author Ronan Chilvers <[email protected]> |
103
|
|
|
*/ |
104
|
|
|
protected function afterDelete() |
105
|
|
|
{} |
106
|
|
|
|
107
|
|
|
/** Model Hooks *********************/ |
108
|
|
|
/************************************/ |
109
|
|
|
} |
110
|
|
|
|