File tree Expand file tree Collapse file tree 5 files changed +100
-0
lines changed Expand file tree Collapse file tree 5 files changed +100
-0
lines changed Original file line number Diff line number Diff line change @@ -80,4 +80,9 @@ public static function notifyUsing(?callable $notificator)
8080 {
8181 Slack::$ notifyUsing = $ notificator ;
8282 }
83+
84+ public static function log ()
85+ {
86+
87+ }
8388}
Original file line number Diff line number Diff line change 55use Binarcode \LaravelDeveloper \LaravelDeveloper ;
66use Binarcode \LaravelDeveloper \Models \Concerns \WithCreator ;
77use Binarcode \LaravelDeveloper \Models \Concerns \WithUuid ;
8+ use Binarcode \LaravelDeveloper \Notifications \DevLog ;
89use DateTimeInterface ;
910use Illuminate \Database \Eloquent \Factories \HasFactory ;
1011use Illuminate \Database \Eloquent \Model ;
@@ -51,6 +52,14 @@ public function getKeyName()
5152 return 'uuid ' ;
5253 }
5354
55+ public static function makeFromDevLog (DevLog $ log ): self
56+ {
57+ return new static ([
58+ 'name ' => $ log ->name ,
59+ 'payload ' => $ log ->payload
60+ ]);
61+ }
62+
5463 public static function makeFromException (Throwable $ throwable , JsonSerializable $ payload = null ): self
5564 {
5665 return new static ([
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Binarcode \LaravelDeveloper \Notifications ;
4+
5+ use Binarcode \LaravelDeveloper \Models \ExceptionLog ;
6+
7+ class DevLog
8+ {
9+ public array $ payload ;
10+
11+ public string $ name ;
12+
13+ public function __construct (string $ name = 'Dev Log ' , array $ payload = [])
14+ {
15+ $ this ->payload = $ payload ;
16+ $ this ->name = $ name ;
17+ }
18+
19+ public function setPayload (array $ payload ): self
20+ {
21+ $ this ->payload = $ payload ;
22+
23+ return $ this ;
24+ }
25+
26+ public function setName (string $ name ): self
27+ {
28+ $ this ->name = $ name ;
29+
30+ return $ this ;
31+ }
32+
33+ public static function make (string $ name = 'Dev Log ' , array $ payload = null ): self
34+ {
35+ return new static ($ name , $ payload );
36+ }
37+
38+ public function getPayload (): array
39+ {
40+ return $ this ->payload ;
41+ }
42+
43+ public function __destruct ()
44+ {
45+ ExceptionLog::makeFromDevLog ($ this )->save ();
46+ }
47+
48+ }
Original file line number Diff line number Diff line change 11<?php
22
3+ use Binarcode \LaravelDeveloper \Notifications \DevLog ;
34use Binarcode \LaravelDeveloper \Notifications \Slack ;
45use Binarcode \LaravelDeveloper \Profiling \ServerMemory ;
56use Binarcode \LaravelDeveloper \Profiling \ServerTiming ;
@@ -46,3 +47,10 @@ function slack(...$args)
4647 return Slack::make ($ args );
4748 }
4849}
50+
51+ if (! function_exists ('devLog ' )) {
52+ function devLog (...$ args ): DevLog
53+ {
54+ return DevLog::make (...$ args );
55+ }
56+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Binarcode \LaravelDeveloper \Tests \Helpers ;
4+
5+ use Binarcode \LaravelDeveloper \Models \ExceptionLog ;
6+ use Binarcode \LaravelDeveloper \Notifications \DevLog ;
7+ use Binarcode \LaravelDeveloper \Tests \TestCase ;
8+
9+ class DevLogHelperTest extends TestCase
10+ {
11+ public function test_dev_log_can_store_payload (): void
12+ {
13+ $ payload = ['a ' => 'b ' ];
14+
15+ $ this ->assertInstanceOf (DevLog::class, $ log = devLog ('Dev Log ' , $ payload ));
16+
17+ $ log ->__destruct ();
18+
19+ $ this ->assertDatabaseHas ('exception_logs ' , [
20+ 'name ' => 'Dev Log ' ,
21+ ]);
22+
23+ $ exceptionLog = ExceptionLog::first ();
24+
25+ $ this ->assertSame (
26+ $ payload ,
27+ $ exceptionLog ->payload
28+ );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments