|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Gamer\Observers; |
|
4
|
|
|
|
|
5
|
|
|
use Event; |
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
use Log; |
|
8
|
|
|
use Symfony\Component\Debug\Exception\FatalThrowableError; |
|
9
|
|
|
use Throwable; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @todo Passar pa/ support |
|
13
|
|
|
* Call no-op classes on models for all event types. This just simplifies |
|
14
|
|
|
* the handling of model events for models. |
|
15
|
|
|
*/ |
|
16
|
|
|
class ModelCallbacks extends BaseObserver |
|
17
|
|
|
{ |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Handle all model events, both Eloquent and Decoy |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $event |
|
23
|
|
|
* @param array $payload Contains: |
|
24
|
|
|
* - |
|
25
|
|
|
* Facilitador\Models\Base |
|
26
|
|
|
* $model |
|
27
|
|
|
* @return void |
|
28
|
|
|
*/ |
|
29
|
|
|
public function handle($event, $payload) |
|
30
|
|
|
{ |
|
31
|
|
|
list($model) = $payload; |
|
32
|
|
|
if ($this->isToIgnore($model, $event)) { |
|
33
|
|
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
Log::warning($event); |
|
37
|
|
|
|
|
38
|
|
|
// // Payload |
|
39
|
|
|
// ^ Cmgmyr\Messenger\Models\Message^ {#4332 |
|
40
|
|
|
// #table: "messages" |
|
41
|
|
|
// #touches: array:1 [ |
|
42
|
|
|
// 0 => "thread" |
|
43
|
|
|
// ] |
|
44
|
|
|
// #fillable: array:3 [ |
|
45
|
|
|
// 0 => "thread_id" |
|
46
|
|
|
// 1 => "user_id" |
|
47
|
|
|
// 2 => "body" |
|
48
|
|
|
// ] |
|
49
|
|
|
// #dates: array:1 [ |
|
50
|
|
|
// 0 => "deleted_at" |
|
51
|
|
|
// ] |
|
52
|
|
|
// #connection: null |
|
53
|
|
|
// #primaryKey: "id" |
|
54
|
|
|
// #keyType: "int" |
|
55
|
|
|
// +incrementing: true |
|
56
|
|
|
// #with: [] |
|
57
|
|
|
// #withCount: [] |
|
58
|
|
|
// #perPage: 15 |
|
59
|
|
|
// +exists: false |
|
60
|
|
|
// +wasRecentlyCreated: false |
|
61
|
|
|
// #attributes: [] |
|
62
|
|
|
// #original: [] |
|
63
|
|
|
// #changes: [] |
|
64
|
|
|
// #casts: [] |
|
65
|
|
|
// #dateFormat: null |
|
66
|
|
|
// #appends: [] |
|
67
|
|
|
// #dispatchesEvents: [] |
|
68
|
|
|
// #observables: [] |
|
69
|
|
|
// #relations: [] |
|
70
|
|
|
// +timestamps: true |
|
71
|
|
|
// #hidden: [] |
|
72
|
|
|
// #visible: [] |
|
73
|
|
|
// #guarded: array:1 [ |
|
74
|
|
|
// 0 => "*" |
|
75
|
|
|
// ] |
|
76
|
|
|
// #forceDeleting: false |
|
77
|
|
|
// } |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
// // Get the action from the event name |
|
81
|
|
|
// preg_match('#\.(\w+)#', $event, $matches); |
|
82
|
|
|
// $action = $matches[1]; |
|
83
|
|
|
|
|
84
|
|
|
// // If there is matching callback method on the model, call it, passing |
|
85
|
|
|
// // any additional event arguments to it |
|
86
|
|
|
// $method = 'on'.Str::studly($action); |
|
87
|
|
|
|
|
88
|
|
|
// if ($method == 'onCreating') { |
|
89
|
|
|
// $this->runInCreating($model); |
|
90
|
|
|
// } |
|
91
|
|
|
// else if ($method == 'onCreated') { |
|
92
|
|
|
// $this->runInCreated($model); |
|
93
|
|
|
// } |
|
94
|
|
|
// else if ($method == 'onValidating' || $method == 'onValidated') { |
|
95
|
|
|
// if (empty(array_slice($payload, 1))) { |
|
96
|
|
|
// // @todo resolver dps |
|
97
|
|
|
// \Log::debug('[Facilitador] ModelCallbacks: ignorando onValidating porque nao tem parametro '.print_r([get_class($model), $method], true)); |
|
98
|
|
|
// return true; |
|
99
|
|
|
// } |
|
100
|
|
|
// } |
|
101
|
|
|
|
|
102
|
|
|
// // @todo resolver isso aqui e o de cima gambi, deu merda |
|
103
|
|
|
// if (method_exists($model, $method)) { |
|
104
|
|
|
// // if (!empty(array_slice($payload, 1))) { |
|
105
|
|
|
// // dd($model, $method, $payload, array_slice($payload, 1), 'erronoModelCallback'); |
|
106
|
|
|
// // } |
|
107
|
|
|
// try { |
|
108
|
|
|
// return call_user_func_array([$model, $method], array_slice($payload, 1)); |
|
109
|
|
|
// } catch (FatalThrowableError|Throwable $th) { |
|
110
|
|
|
// \Log::info('[Facilitador] ModelCallbacks: problema aqui'.print_r([get_class($model), $method], true)); |
|
111
|
|
|
// } |
|
112
|
|
|
|
|
113
|
|
|
// } |
|
114
|
|
|
return true; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|