File tree Expand file tree Collapse file tree 4 files changed +65
-59
lines changed Expand file tree Collapse file tree 4 files changed +65
-59
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bekwoh \LaravelDbDoc \Contracts ;
4
+
5
+ interface Presenter {
6
+ public function getDisk ();
7
+ public function getFilename ();
8
+ public function getContents ();
9
+ public function getStub ();
10
+ public function write ();
11
+ public function read ();
12
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Bekwoh \LaravelDbDoc \Presentation ;
4
+
5
+ use Bekwoh \LaravelDbDoc \Contracts \Presenter ;
6
+ use Bekwoh \LaravelDbDoc \Facades \LaravelDbDoc ;
7
+ use Illuminate \Support \Facades \Storage ;
8
+ use Illuminate \Support \Str ;
9
+
10
+ abstract class AbstractPresenter implements Presenter
11
+ {
12
+ abstract public function getContents ();
13
+
14
+ public function __construct (protected array $ contents )
15
+ {
16
+ }
17
+
18
+ public function getDisk ()
19
+ {
20
+ return LaravelDbDoc::disk (strtolower (basename (__CLASS__ ));
21
+ }
22
+
23
+ public function getFilename ()
24
+ {
25
+ return LaravelDbDoc::filename (strtolower (basename (__CLASS__ ));
26
+ }
27
+
28
+ public function getStub ()
29
+ {
30
+ return file_get_contents (
31
+ base_path ('stubs/db-doc.stub ' )
32
+ );
33
+ }
34
+
35
+ public function write ()
36
+ {
37
+ Storage::disk ($ this ->getDisk ())
38
+ ->put (
39
+ $ this ->getFilename (),
40
+ $ this ->getContents ()
41
+ );
42
+ }
43
+
44
+ public function read ()
45
+ {
46
+ return Storage::disk ($ this ->getDisk ())
47
+ ->get ($ this ->getFilename ());
48
+ }
49
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace Bekwoh \LaravelDbDoc \Presentation ;
4
4
5
- use Illuminate \ Support \ Facades \ Storage ;
5
+ use Bekwoh \ LaravelDbDoc \ Contracts \ Presenter ;
6
6
7
- class Json
7
+ class Json extends AbstractPresenter implements Presenter
8
8
{
9
- public function __construct (protected array $ contents )
10
- {
11
- }
12
-
13
- public function getDisk ()
14
- {
15
- return config ('db-doc.presentations.json.disk ' );
16
- }
17
-
18
9
public function getContents ()
19
10
{
20
11
return json_encode ($ this ->contents , JSON_PRETTY_PRINT );
21
12
}
22
-
23
- public function write ()
24
- {
25
- Storage::disk ($ this ->getDisk ())
26
- ->put (
27
- config ('app.name ' ).' Database Schema.json ' ,
28
- $ this ->getContents (),
29
- );
30
- }
31
13
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Bekwoh \LaravelDbDoc \Presentation ;
4
4
5
- use Bekwoh \LaravelDbDoc \Facades \LaravelDbDoc ;
6
- use Illuminate \Support \Facades \Storage ;
5
+ use Bekwoh \LaravelDbDoc \Contracts \Presenter ;
7
6
use Illuminate \Support \Str ;
8
7
9
- class Markdown
8
+ class Markdown extends AbstractPresenter implements Presenter
10
9
{
11
- public function __construct (protected array $ contents )
12
- {
13
- }
14
-
15
- public function getDisk ()
16
- {
17
- return LaravelDbDoc::disk ('markdown ' );
18
- }
19
-
20
- public function getFilename ()
21
- {
22
- return LaravelDbDoc::filename ('markdown ' );
23
- }
24
-
25
10
public function getContents ()
26
11
{
27
12
$ contents = $ this ->contents ;
@@ -57,26 +42,4 @@ public function getContents()
57
42
$ schema ,
58
43
], $ stub );
59
44
}
60
-
61
- private function getStub ()
62
- {
63
- return file_get_contents (
64
- base_path ('stubs/db-doc.stub ' )
65
- );
66
- }
67
-
68
- public function write ()
69
- {
70
- Storage::disk ($ this ->getDisk ())
71
- ->put (
72
- $ this ->getFilename (),
73
- $ this ->getContents ()
74
- );
75
- }
76
-
77
- public function read ()
78
- {
79
- return Storage::disk ($ this ->getDisk ())
80
- ->get ($ this ->getFilename ());
81
- }
82
45
}
You can’t perform that action at this time.
0 commit comments