1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Devpri\Tinre; |
4
|
|
|
|
5
|
|
|
use Illuminate\Session\SessionManager; |
6
|
|
|
|
7
|
|
|
class Tinre |
8
|
|
|
{ |
9
|
|
|
public static $config = []; |
10
|
|
|
|
11
|
|
|
public static $styles = []; |
12
|
|
|
|
13
|
|
|
public static $scripts = []; |
14
|
|
|
|
15
|
|
|
public static $translations = []; |
16
|
|
|
|
17
|
167 |
|
public static function dashboardPath(): string |
18
|
|
|
{ |
19
|
167 |
|
return config('tinre.dashboard_path', '/dashboard'); |
20
|
|
|
} |
21
|
|
|
|
22
|
167 |
|
public static function routes(): RouteRegistration |
23
|
|
|
{ |
24
|
167 |
|
return new RouteRegistration; |
25
|
|
|
} |
26
|
|
|
|
27
|
3 |
|
public static function config(): array |
28
|
|
|
{ |
29
|
3 |
|
return static::$config; |
30
|
|
|
} |
31
|
|
|
|
32
|
3 |
|
public static function addToConfig(array $variables): Tinre |
33
|
|
|
{ |
34
|
3 |
|
static::$config = array_merge(static::$config, $variables); |
35
|
|
|
|
36
|
3 |
|
return new static; |
37
|
|
|
} |
38
|
|
|
|
39
|
3 |
|
public static function addDashboardConfig() |
40
|
|
|
{ |
41
|
3 |
|
static::addToConfig([ |
42
|
3 |
|
'app_url' => rtrim(config('app.url', null), '/').'/', |
43
|
3 |
|
'dashboard_path' => static::dashboardPath(), |
44
|
3 |
|
'timezone' => config('app.timezone', 'UTC'), |
45
|
3 |
|
'date_format' => config('tinre.date_format', 'MM/DD/YYYY, h:mm:ss a'), |
46
|
3 |
|
'roles' => config('tinre.roles', []), |
47
|
|
|
]); |
48
|
|
|
|
49
|
3 |
|
return new static; |
50
|
|
|
} |
51
|
|
|
|
52
|
3 |
|
public static function addUserToConfig($request): Tinre |
53
|
|
|
{ |
54
|
3 |
|
static::addToConfig([ |
55
|
3 |
|
'user_permissions' => $request->user()->permissions(), |
56
|
3 |
|
'user_api_access' => $request->user()->hasApiAccess(), |
57
|
3 |
|
'user_api_permissions' => $request->user()->apiPermissions(), |
58
|
|
|
]); |
59
|
|
|
|
60
|
3 |
|
return new static; |
61
|
|
|
} |
62
|
|
|
|
63
|
3 |
|
public static function styles(): array |
64
|
|
|
{ |
65
|
3 |
|
return static::$styles; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public static function addStyle($name, $path): Tinre |
69
|
|
|
{ |
70
|
|
|
static::$styles[$name] = $path; |
71
|
|
|
|
72
|
|
|
return new static; |
73
|
|
|
} |
74
|
|
|
|
75
|
3 |
|
public static function scripts(): array |
76
|
|
|
{ |
77
|
3 |
|
return static::$scripts; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public static function addScript($name, $path): Tinre |
81
|
|
|
{ |
82
|
|
|
static::$scripts[$name] = $path; |
83
|
|
|
|
84
|
|
|
return new static; |
85
|
|
|
} |
86
|
|
|
|
87
|
7 |
|
public static function translations(): array |
88
|
|
|
{ |
89
|
7 |
|
$json = []; |
90
|
|
|
|
91
|
7 |
|
foreach (static::$translations as $translation) { |
92
|
7 |
|
if (is_string($translation)) { |
93
|
7 |
|
if (is_readable($translation)) { |
94
|
|
|
$translation = json_decode(file_get_contents($translation), true); |
95
|
|
|
|
96
|
|
|
$json = array_merge($json, $translation); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
7 |
|
return $json; |
102
|
|
|
} |
103
|
|
|
|
104
|
167 |
|
public static function addTranslation($path): Tinre |
105
|
|
|
{ |
106
|
167 |
|
static::$translations[] = $path; |
107
|
|
|
|
108
|
167 |
|
return new static; |
109
|
|
|
} |
110
|
|
|
|
111
|
7 |
|
public static function messages(SessionManager $session): array |
112
|
|
|
{ |
113
|
7 |
|
$messages = []; |
114
|
|
|
|
115
|
7 |
|
if ($session->has('status')) { |
116
|
1 |
|
$messages[] = [ |
117
|
1 |
|
'type' => 'success', |
118
|
1 |
|
'text' => $session->get('status'), |
119
|
|
|
]; |
120
|
|
|
} |
121
|
|
|
|
122
|
7 |
|
if ($session->has('warning')) { |
123
|
|
|
$messages[] = [ |
124
|
|
|
'type' => 'warning', |
125
|
|
|
'text' => $session->get('warning'), |
126
|
|
|
]; |
127
|
|
|
} |
128
|
|
|
|
129
|
7 |
|
return $messages; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|