1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sfneal\Helpers\Laravel; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Cache; |
6
|
|
|
use Sfneal\Helpers\Laravel\Support\CacheKey; |
7
|
|
|
use Sfneal\Helpers\Laravel\Support\Changelog; |
8
|
|
|
use Sfneal\Helpers\Strings\StringHelpers; |
9
|
|
|
|
10
|
|
|
class AppInfo |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Retrieve the Application's version. |
14
|
|
|
* |
15
|
|
|
* @return string |
16
|
|
|
*/ |
17
|
|
|
public static function version(): string |
18
|
|
|
{ |
19
|
|
|
return Cache::rememberForever( |
20
|
|
|
// Cache key |
21
|
|
|
(new CacheKey('version'))->execute(), |
22
|
|
|
|
23
|
|
|
// Value to cache |
24
|
|
|
function () { |
25
|
|
|
return trim(config('app-info.version')).(self::isEnvDevelopment() ? ' (dev)' : ''); |
26
|
|
|
} |
27
|
|
|
); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Retrieve an array of changes made to a particular application version. |
32
|
|
|
* |
33
|
|
|
* @param string|null $version |
34
|
|
|
* @return array|null |
35
|
|
|
*/ |
36
|
|
|
public static function versionChanges(string $version = null): ?array |
37
|
|
|
{ |
38
|
|
|
// Get current version changes if $version wasn't passed |
39
|
|
|
return (new Changelog())->versionChanges($version ?? self::version()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Retrieve the Application's changelog. |
44
|
|
|
* |
45
|
|
|
* @return array |
46
|
|
|
*/ |
47
|
|
|
public static function changelog(): array |
48
|
|
|
{ |
49
|
|
|
return (new Changelog())->changelog(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Determine if a particular Version is running. |
54
|
|
|
* |
55
|
|
|
* @param string $version |
56
|
|
|
* |
57
|
|
|
* @return mixed |
58
|
|
|
*/ |
59
|
|
|
public static function isVersion(string $version): bool |
60
|
|
|
{ |
61
|
|
|
return self::version() == $version; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Determine if a particular Version is running. |
66
|
|
|
* |
67
|
|
|
* @param string $version |
68
|
|
|
* |
69
|
|
|
* @return mixed |
70
|
|
|
*/ |
71
|
|
|
public static function isNotVersion(string $version): bool |
72
|
|
|
{ |
73
|
|
|
return ! self::isVersion($version); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Determine if a 'beta' version is running. |
78
|
|
|
* |
79
|
|
|
* @return mixed |
80
|
|
|
*/ |
81
|
|
|
public static function isVersionTagBeta(): bool |
82
|
|
|
{ |
83
|
|
|
return self::isVersionTag('beta'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Determine if a 'dev' version is running. |
88
|
|
|
* |
89
|
|
|
* @return mixed |
90
|
|
|
*/ |
91
|
|
|
public static function isVersionTagDev(): bool |
92
|
|
|
{ |
93
|
|
|
return self::isVersionTag('dev'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Determine if a particular tag version is running (beta, dev, staging, etc..). |
98
|
|
|
* |
99
|
|
|
* @param string $tag |
100
|
|
|
* |
101
|
|
|
* @return mixed |
102
|
|
|
*/ |
103
|
|
|
public static function isVersionTag(string $tag): bool |
104
|
|
|
{ |
105
|
|
|
return Cache::rememberForever( |
106
|
|
|
// Cache key |
107
|
|
|
(new CacheKey('version', "is-{$tag}"))->execute(), |
108
|
|
|
|
109
|
|
|
// Value to cache |
110
|
|
|
function () use ($tag) { |
111
|
|
|
return (new StringHelpers(self::version()))->inString($tag); |
112
|
|
|
} |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Determine if the Application is running in a 'production' environment. |
118
|
|
|
* |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
|
|
public static function isEnvProduction(): bool |
122
|
|
|
{ |
123
|
|
|
return self::isEnv('production'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Determine if the Application is running in a 'development' environment. |
128
|
|
|
* |
129
|
|
|
* @return bool |
130
|
|
|
*/ |
131
|
|
|
public static function isEnvDevelopment(): bool |
132
|
|
|
{ |
133
|
|
|
return self::isEnv('development'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Determine if the Application is running in a 'testing' environment. |
138
|
|
|
* |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public static function isEnvTesting(): bool |
142
|
|
|
{ |
143
|
|
|
return self::isEnv('testing'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Determine if the application is in a particular environment. |
148
|
|
|
* |
149
|
|
|
* @param string $env |
150
|
|
|
* @return bool |
151
|
|
|
*/ |
152
|
|
|
public static function isEnv(string $env): bool |
153
|
|
|
{ |
154
|
|
|
return self::env() == $env; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Retrieve the application's environment. |
159
|
|
|
* |
160
|
|
|
* @return string|null |
161
|
|
|
*/ |
162
|
|
|
public static function env(): ?string |
163
|
|
|
{ |
164
|
|
|
return config('app.env'); |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|