File tree 3 files changed +44
-0
lines changed
3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 57
57
"phpstan/extension-installer" : true
58
58
}
59
59
},
60
+ "extra" : {
61
+ "laravel" : {
62
+ "providers" : [
63
+ " DefStudio\\ EnumFeatures\\ ServiceProvider"
64
+ ]
65
+ }
66
+ },
60
67
"minimum-stability" : " dev" ,
61
68
"prefer-stable" : true
62
69
}
Original file line number Diff line number Diff line change @@ -14,4 +14,11 @@ public static function notEnabled(UnitEnum $feature): FeatureException
14
14
15
15
return new self ("Feature [ $ name] is not enabled " );
16
16
}
17
+
18
+ public static function invalid_feature_enum (UnitEnum $ feature ): FeatureException
19
+ {
20
+ $ name = $ feature instanceof BackedEnum ? $ feature ->value : $ feature ->name ;
21
+
22
+ return new self ("Enum [ $ name] does not use DefineFeatures trait " );
23
+ }
17
24
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace DefStudio \EnumFeatures ;
4
+
5
+ use DefStudio \EnumFeatures \Concerns \DefinesFeatures ;
6
+ use DefStudio \EnumFeatures \Exceptions \FeatureException ;
7
+ use Illuminate \Support \Facades \Blade ;
8
+ use Spatie \LaravelPackageTools \Package ;
9
+ use Spatie \LaravelPackageTools \PackageServiceProvider ;
10
+ use UnitEnum ;
11
+
12
+ class ServiceProvider extends PackageServiceProvider
13
+ {
14
+ public function configurePackage (Package $ package ): void
15
+ {
16
+ $ package ->name ('enum-features ' );
17
+ }
18
+
19
+ public function packageBooted (): void
20
+ {
21
+ Blade::if ('feature ' , function (UnitEnum $ feature ) {
22
+ if (! class_uses ($ feature , DefinesFeatures::class)) {
23
+ throw FeatureException::invalid_feature_enum ($ feature );
24
+ }
25
+
26
+ /** @var DefinesFeatures $feature */
27
+ return $ feature ->enabled ();
28
+ });
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments