2
2
3
3
namespace LaraZeus \Rain ;
4
4
5
+ use Closure ;
6
+
5
7
trait Configuration
6
8
{
7
9
/**
8
10
* set the default path for the layout page.
9
11
*/
10
- protected string $ rainPrefix = 'rain ' ;
12
+ protected Closure | string $ rainPrefix = 'rain ' ;
11
13
12
14
/**
13
15
* the middleware you want to apply on the layout page routes
14
16
*/
15
17
protected array $ rainMiddleware = ['web ' ];
16
18
17
19
/**
18
- * customize the models
20
+ * you can overwrite any model and use your own
19
21
*/
20
- protected string $ layoutModel = \LaraZeus \Rain \Models \Layout::class;
21
-
22
- protected string $ columnsModel = \LaraZeus \Rain \Models \Columns::class;
22
+ protected array $ rainModels = [
23
+ 'Layout ' => \LaraZeus \Rain \Models \Layout::class,
24
+ 'Columns ' => \LaraZeus \Rain \Models \Columns::class,
25
+ ];
23
26
24
27
/**
25
28
* set the default upload options.
26
29
*/
27
- protected string $ uploadDisk = 'public ' ;
30
+ protected Closure | string $ uploadDisk = 'public ' ;
28
31
29
- protected string $ uploadDirectory = 'layouts ' ;
32
+ protected Closure | string $ uploadDirectory = 'layouts ' ;
30
33
31
- protected string $ navigationGroupLabel = 'Rain ' ;
34
+ protected Closure | string $ navigationGroupLabel = 'Rain ' ;
32
35
33
- protected string $ defaultLayout = 'new-page ' ;
36
+ protected Closure | string $ defaultLayout = 'new-page ' ;
34
37
35
- public function rainPrefix (string $ prefix ): static
38
+ public function rainPrefix (Closure | string $ prefix ): static
36
39
{
37
40
$ this ->rainPrefix = $ prefix ;
38
41
39
42
return $ this ;
40
43
}
41
44
42
- public function getRainPrefix (): string
45
+ public function getRainPrefix (): Closure | string
43
46
{
44
- return $ this ->rainPrefix ;
47
+ return $ this ->evaluate ( $ this -> rainPrefix ) ;
45
48
}
46
49
47
50
public function rainMiddleware (array $ middleware ): static
@@ -56,75 +59,71 @@ public function getMiddleware(): array
56
59
return $ this ->rainMiddleware ;
57
60
}
58
61
59
- public function layoutModel ( string $ model ): static
62
+ public function rainModels ( array $ models ): static
60
63
{
61
- $ this ->layoutModel = $ model ;
64
+ $ this ->rainModels = $ models ;
62
65
63
66
return $ this ;
64
67
}
65
68
66
- public function getLayoutModel (): string
69
+ public function getRainModels (): array
67
70
{
68
- return $ this ->layoutModel ;
69
- }
70
-
71
- public function columnsModel (string $ model ): static
72
- {
73
- $ this ->columnsModel = $ model ;
74
-
75
- return $ this ;
71
+ return $ this ->rainModels ;
76
72
}
77
73
78
- public function getColumnsModel ( ): string
74
+ public static function getModel ( string $ model ): string
79
75
{
80
- return $ this ->columnsModel ;
76
+ return array_merge (
77
+ (new static ())->rainModels ,
78
+ (new static ())::get ()->getRainModels ()
79
+ )[$ model ];
81
80
}
82
81
83
- public function uploadDisk (string $ disk ): static
82
+ public function uploadDisk (Closure | string $ disk ): static
84
83
{
85
84
$ this ->uploadDisk = $ disk ;
86
85
87
86
return $ this ;
88
87
}
89
88
90
- public function getUploadDisk (): string
89
+ public function getUploadDisk (): Closure | string
91
90
{
92
- return $ this ->uploadDisk ;
91
+ return $ this ->evaluate ( $ this -> uploadDisk ) ;
93
92
}
94
93
95
- public function uploadDirectory (string $ dir ): static
94
+ public function uploadDirectory (Closure | string $ dir ): static
96
95
{
97
96
$ this ->uploadDirectory = $ dir ;
98
97
99
98
return $ this ;
100
99
}
101
100
102
- public function getUploadDirectory (): string
101
+ public function getUploadDirectory (): Closure | string
103
102
{
104
- return $ this ->uploadDirectory ;
103
+ return $ this ->evaluate ( $ this -> uploadDirectory ) ;
105
104
}
106
105
107
- public function navigationGroupLabel (string $ lable ): static
106
+ public function navigationGroupLabel (Closure | string $ lable ): static
108
107
{
109
108
$ this ->navigationGroupLabel = $ lable ;
110
109
111
110
return $ this ;
112
111
}
113
112
114
- public function getNavigationGroupLabel (): string
113
+ public function getNavigationGroupLabel (): Closure | string
115
114
{
116
- return $ this ->navigationGroupLabel ;
115
+ return $ this ->evaluate ( $ this -> navigationGroupLabel ) ;
117
116
}
118
117
119
- public function defaultLayout (string $ layout ): static
118
+ public function defaultLayout (Closure | string $ layout ): static
120
119
{
121
120
$ this ->defaultLayout = $ layout ;
122
121
123
122
return $ this ;
124
123
}
125
124
126
- public function getDefaultLayout (): string
125
+ public function getDefaultLayout (): Closure | string
127
126
{
128
- return $ this ->defaultLayout ;
127
+ return $ this ->evaluate ( $ this -> defaultLayout ) ;
129
128
}
130
129
}
0 commit comments