@@ -29,6 +29,8 @@ class Ecow
29
29
30
30
public array $ modelsBeingSaved = [];
31
31
32
+ public bool $ disabled = false ;
33
+
32
34
public function modelClass (): string
33
35
{
34
36
$ modelClass = config ('ecow.model ' );
@@ -155,6 +157,14 @@ public function getAttributes(mixed $model): array
155
157
156
158
public function bootListeners (): void
157
159
{
160
+ if ($ this ->isDisabled ()) {
161
+ return ;
162
+ }
163
+
164
+ if (false === config ('ecow.enabled ' , true )) {
165
+ return ;
166
+ }
167
+
158
168
$ this ->listenForCreatingEvents ();
159
169
$ this ->listenForUpdatingEvents ();
160
170
$ this ->listenForDeletingEvents ();
@@ -211,8 +221,12 @@ public function listen(string $event, array $pipes): void
211
221
});
212
222
}
213
223
214
- protected function eventPipeline (string $ event , array $ payload , $ events ): mixed
224
+ protected function eventPipeline (string $ event , array $ payload , $ events )
215
225
{
226
+ if ($ this ->isDisabled ()) {
227
+ return ;
228
+ }
229
+
216
230
$ model = $ payload [0 ];
217
231
218
232
$ data = (object ) [
@@ -369,4 +383,24 @@ protected function info($message)
369
383
{
370
384
event ('ecow.info ' , ['payload ' => ['message ' => $ message ]]);
371
385
}
386
+
387
+ public function disable (): void
388
+ {
389
+ $ this ->disabled = true ;
390
+ }
391
+
392
+ public function enable (): void
393
+ {
394
+ $ this ->disabled = false ;
395
+ }
396
+
397
+ public function isDisabled (): bool
398
+ {
399
+ return $ this ->disabled ;
400
+ }
401
+
402
+ public function isNotDisabled (): bool
403
+ {
404
+ return ! $ this ->isDisabled ();
405
+ }
372
406
}
0 commit comments