Skip to content

Commit e5fa92a

Browse files
author
Andrey Helldar
authored
Merge branch 'main' into 11-add-support-for-comparing-app-version
2 parents 052fd45 + eefb726 commit e5fa92a

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/Facades/AppVersion.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
* @method static bool is7x()
1313
* @method static bool is8x()
1414
* @method static bool is9x()
15+
* @method static int major()
16+
* @method static int minor()
17+
* @method static int patch()
18+
* @method static string version()
1519
*/
1620
class AppVersion extends Facade
1721
{

src/Support/AppVersion.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,31 @@ public function is9x(): bool
3030
return $this->major() === 9;
3131
}
3232

33-
public function is(string $version, string $comparator = '>='): bool
33+
public function major(): int
3434
{
35-
return version_compare($this->version(), $version, $comparator);
35+
return (int) Str::before($this->version(), '.');
3636
}
3737

38-
protected function major(): int
38+
public function minor(): int
3939
{
40-
return (int) Str::before($this->version(), '.');
40+
$version = $this->parse();
41+
42+
return $version[1];
4143
}
4244

43-
protected function version(): string
45+
public function patch(): int
46+
{
47+
$version = $this->parse();
48+
49+
return $version[2];
50+
}
51+
52+
public function is(string $version, string $comparator = '>='): bool
53+
{
54+
return version_compare($this->version(), $version, $comparator);
55+
}
56+
57+
public function version(): string
4458
{
4559
if (AppHelper::isLumen()) {
4660
preg_match('/.+\((\d+\.\d+\.\d+)\)/', app()->version(), $matches);
@@ -50,4 +64,9 @@ protected function version(): string
5064

5165
return Application::VERSION;
5266
}
67+
68+
protected function parse(): array
69+
{
70+
return explode('.', $this->version());
71+
}
5372
}

0 commit comments

Comments
 (0)