1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelFeature\Provider; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Blade; |
6
|
|
|
use Illuminate\Support\ServiceProvider; |
7
|
|
|
use LaravelFeature\Domain\Repository\FeatureRepositoryInterface; |
8
|
|
|
use LaravelFeature\Console\Command\ScanViewsForFeaturesCommand; |
9
|
|
|
|
10
|
|
|
class FeatureServiceProvider extends ServiceProvider |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Bootstrap any application services. |
14
|
|
|
* |
15
|
|
|
* @return void |
16
|
|
|
*/ |
17
|
|
|
public function boot() |
18
|
|
|
{ |
19
|
|
|
$this->loadMigrationsFrom(__DIR__.'/../Migration'); |
20
|
|
|
|
21
|
|
|
$this->publishes([ |
22
|
|
|
__DIR__.'/../Config/features.php' => config_path('features.php'), |
23
|
|
|
]); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Register any application services. |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
public function register() |
32
|
|
|
{ |
33
|
|
|
$this->mergeConfigFrom(__DIR__.'/../Config/features.php', 'features'); |
34
|
|
|
|
35
|
|
|
$config = $this->app->make('config'); |
36
|
|
|
|
37
|
|
|
$this->app->bind(FeatureRepositoryInterface::class, function () use ($config) { |
38
|
|
|
return app()->make($config->get('features.repository')); |
39
|
|
|
}); |
40
|
|
|
|
41
|
|
|
$this->registerBladeDirective(); |
42
|
|
|
$this->registerConsoleCommand(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function registerBladeDirective() |
46
|
|
|
{ |
47
|
|
|
Blade::directive('feature', function ($featureName) { |
48
|
|
|
return "<?php if (app('LaravelFeature\\Domain\\FeatureManager')->isEnabled($featureName)): ?>"; |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
Blade::directive('endfeature', function () { |
52
|
|
|
return '<?php endif; ?>'; |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function registerConsoleCommand() |
57
|
|
|
{ |
58
|
|
|
if ($this->app->runningInConsole()) { |
59
|
|
|
$this->commands([ |
60
|
|
|
ScanViewsForFeaturesCommand::class |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|