Skip to content

Commit 66ae89d

Browse files
author
Andrey Helldar
authored
Merge pull request #8 from TheDragonCode/3.x
Added definition of major versions of the framework
2 parents ed5f986 + a4148c9 commit 66ae89d

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

Diff for: composer.json

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"ramsey/uuid": "^3.7|^4.0",
2424
"symfony/var-dumper": "^4.0|^5.0"
2525
},
26+
"require-dev": {
27+
"laravel/framework": "^6.0|^7.0|^8.0",
28+
"laravel/lumen-framework": "^6.0|^7.0|^8.0"
29+
},
2630
"conflict": {
2731
"andrey-helldar/laravel-support": "*"
2832
},

Diff for: src/Facades/AppVersion.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelSupport\Facades;
6+
7+
use DragonCode\LaravelSupport\Support\AppVersion as Support;
8+
use Illuminate\Support\Facades\Facade;
9+
10+
/**
11+
* @method static bool is6x()
12+
* @method static bool is7x()
13+
* @method static bool is8x()
14+
*/
15+
class AppVersion extends Facade
16+
{
17+
protected static function getFacadeAccessor(): string
18+
{
19+
return Support::class;
20+
}
21+
}

Diff for: src/Support/AppVersion.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelSupport\Support;
6+
7+
use DragonCode\LaravelSupport\Facades\App as AppHelper;
8+
use Illuminate\Foundation\Application;
9+
use Illuminate\Support\Str;
10+
11+
class AppVersion
12+
{
13+
public function is6x(): bool
14+
{
15+
return $this->major() === 6;
16+
}
17+
18+
public function is7x(): bool
19+
{
20+
return $this->major() === 7;
21+
}
22+
23+
public function is8x(): bool
24+
{
25+
return $this->major() === 8;
26+
}
27+
28+
protected function major(): int
29+
{
30+
return (int) Str::before($this->version(), '.');
31+
}
32+
33+
protected function version(): string
34+
{
35+
if (AppHelper::isLumen()) {
36+
$version = app()->version();
37+
38+
$version = Str::after($version, '(');
39+
$version = Str::before($version, ')');
40+
41+
return $version;
42+
}
43+
44+
return Application::VERSION;
45+
}
46+
}

0 commit comments

Comments
 (0)