|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Transmissor\Observers; |
|
4
|
|
|
|
|
5
|
|
|
use Auth; |
|
6
|
|
|
use Event; |
|
7
|
|
|
use Illuminate\Support\Facades\Schema; |
|
8
|
|
|
use Illuminate\Support\Str; |
|
9
|
|
|
use Log; |
|
10
|
|
|
use Pedreiro\Models\Base; |
|
11
|
|
|
use Symfony\Component\Debug\Exception\FatalThrowableError; |
|
12
|
|
|
use Throwable; |
|
13
|
|
|
use Transmissor\Scopes\TransmissorScope; |
|
14
|
|
|
use Transmissor\Services\TransmissorService; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Call no-op classes on models for all event types. This just simplifies |
|
18
|
|
|
* the handling of model events for models. |
|
19
|
|
|
*/ |
|
20
|
|
|
class TransmissorCallbacks |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Handle all model events, both Eloquent and Decoy |
|
24
|
|
|
* |
|
25
|
|
|
* @param string $event |
|
26
|
|
|
* @param array $payload Contains: |
|
27
|
|
|
* - |
|
28
|
|
|
* Transmissor\Models\Base |
|
29
|
|
|
* $model |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function handle($event, $payload) |
|
|
|
|
|
|
33
|
|
|
{ |
|
34
|
|
|
// // list($model) = $payload; |
|
35
|
|
|
// dd($payload); |
|
36
|
|
|
// // // Payload |
|
37
|
|
|
// // ^ Cmgmyr\Messenger\Models\Message^ {#4332 |
|
38
|
|
|
// // #table: "messages" |
|
39
|
|
|
// // #touches: array:1 [ |
|
40
|
|
|
// // 0 => "thread" |
|
41
|
|
|
// // ] |
|
42
|
|
|
// // #fillable: array:3 [ |
|
43
|
|
|
// // 0 => "thread_id" |
|
44
|
|
|
// // 1 => "user_id" |
|
45
|
|
|
// // 2 => "body" |
|
46
|
|
|
// // ] |
|
47
|
|
|
// // #dates: array:1 [ |
|
48
|
|
|
// // 0 => "deleted_at" |
|
49
|
|
|
// // ] |
|
50
|
|
|
// // #connection: null |
|
51
|
|
|
// // #primaryKey: "id" |
|
52
|
|
|
// // #keyType: "int" |
|
53
|
|
|
// // +incrementing: true |
|
54
|
|
|
// // #with: [] |
|
55
|
|
|
// // #withCount: [] |
|
56
|
|
|
// // #perPage: 15 |
|
57
|
|
|
// // +exists: false |
|
58
|
|
|
// // +wasRecentlyCreated: false |
|
59
|
|
|
// // #attributes: [] |
|
60
|
|
|
// // #original: [] |
|
61
|
|
|
// // #changes: [] |
|
62
|
|
|
// // #casts: [] |
|
63
|
|
|
// // #dateFormat: null |
|
64
|
|
|
// // #appends: [] |
|
65
|
|
|
// // #dispatchesEvents: [] |
|
66
|
|
|
// // #observables: [] |
|
67
|
|
|
// // #relations: [] |
|
68
|
|
|
// // +timestamps: true |
|
69
|
|
|
// // #hidden: [] |
|
70
|
|
|
// // #visible: [] |
|
71
|
|
|
// // #guarded: array:1 [ |
|
72
|
|
|
// // 0 => "*" |
|
73
|
|
|
// // ] |
|
74
|
|
|
// // #forceDeleting: false |
|
75
|
|
|
// // } |
|
76
|
|
|
|
|
77
|
|
|
// // Ignore |
|
78
|
|
|
// if (!app()->bound(TransmissorService::class)) { |
|
79
|
|
|
// return true; |
|
80
|
|
|
// } |
|
81
|
|
|
|
|
82
|
|
|
// if (!Schema::hasColumn($model->getTable(), 'business_code')) { |
|
83
|
|
|
// return true; |
|
84
|
|
|
// } |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
// // Get the action from the event name |
|
88
|
|
|
// preg_match('#\.(\w+)#', $event, $matches); |
|
89
|
|
|
// $action = $matches[1]; |
|
90
|
|
|
|
|
91
|
|
|
// // If there is matching callback method on the model, call it, passing |
|
92
|
|
|
// // any additional event arguments to it |
|
93
|
|
|
// $method = 'on'.Str::studly($action); |
|
94
|
|
|
|
|
95
|
|
|
// if ($method == 'onBooting') { |
|
96
|
|
|
// $model::addGlobalScope(new TransmissorScope); |
|
97
|
|
|
// return true; |
|
98
|
|
|
// } |
|
99
|
|
|
|
|
100
|
|
|
// if ($method == 'onCreating') { |
|
101
|
|
|
// $business = app()->make(TransmissorService::class); |
|
102
|
|
|
// $model->business_code = $business->getCode(); |
|
103
|
|
|
// if (Auth::check()) { |
|
104
|
|
|
// // @todo Verifica se tem acesso |
|
105
|
|
|
// } |
|
106
|
|
|
// return true; |
|
107
|
|
|
// } |
|
108
|
|
|
|
|
109
|
|
|
// if ($method == 'onCreated') { |
|
110
|
|
|
// return true; |
|
111
|
|
|
// } |
|
112
|
|
|
|
|
113
|
|
|
// if ($method == 'onValidating' || $method == 'onValidated') { |
|
114
|
|
|
// return true; |
|
115
|
|
|
// } |
|
116
|
|
|
|
|
117
|
|
|
// return true; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.