-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathServiceProvider.php
70 lines (61 loc) · 1.74 KB
/
ServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace MikeFrancis\LaravelUnleash;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
use MikeFrancis\LaravelUnleash\Unleash;
use MikeFrancis\LaravelUnleash\Client;
use GuzzleHttp\ClientInterface;
class ServiceProvider extends IlluminateServiceProvider
{
/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom($this->getConfigPath(), 'unleash');
$this->app->when(Unleash::class)->needs(ClientInterface::class)->give(Client::class);
$this->app->singleton('unleash', function ($app) {
return $app->make(Unleash::class);
});
}
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
$this->publishes(
[
$this->getConfigPath() => config_path('unleash.php'),
]
);
Blade::if(
'featureEnabled',
function (string $feature) {
$client = app(Client::class);
$unleash = app(Unleash::class, ['client' => $client]);
return $unleash->isFeatureEnabled($feature);
}
);
Blade::if(
'featureDisabled',
function (string $feature) {
$client = app(Client::class);
$unleash = app(Unleash::class, ['client' => $client]);
return !$unleash->isFeatureEnabled($feature);
}
);
}
/**
* Get the path to the config.
*
* @return string
*/
private function getConfigPath(): string
{
return __DIR__ . '/../config/unleash.php';
}
}