Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit fb12f3a

Browse files
committed
Add Unleash and Feature facades
1 parent f563935 commit fb12f3a

File tree

7 files changed

+96
-5
lines changed

7 files changed

+96
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/vendor
2+
/.idea
23

34
.phpunit.result.cache
45
phpunit.xml

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Documentation for configuration can be found in [config/unleash.php](https://git
2424
## Usage
2525

2626
```php
27-
2827
use \MikeFrancis\LaravelUnleash\Unleash;
2928

3029
$unleash = app(Unleash::class);
@@ -37,9 +36,49 @@ if ($unleash->isFeatureDisabled('myAwesomeFeature')) {
3736
// Check back later for more features!
3837
}
3938

39+
$feature = $unleash->getFeature('myAwesomeFeature');
40+
4041
$allFeatures = $unleash->getFeatures();
4142
```
4243

44+
### Facades
45+
46+
You can use the `Unleash` facade:
47+
48+
```php
49+
use Unleash;
50+
51+
if (Unleash::isFeatureEnabled('myAwesomeFeature')) {
52+
// Congratulations, you can see this awesome feature!
53+
}
54+
55+
if (Unleash::isFeatureDisabled('myAwesomeFeature')) {
56+
// Check back later for more features!
57+
}
58+
59+
$feature = Unleash::getFeature('myAwesomeFeature');
60+
61+
$allFeatures = Unleash::getFeatures();
62+
```
63+
64+
or use the generically named `Feature` facade:
65+
66+
```php
67+
use Feature;
68+
69+
if (Feature::enabled('myAwesomeFeature')) {
70+
// Congratulations, you can see this awesome feature!
71+
}
72+
73+
if (Feature::disabled('myAwesomeFeature')) {
74+
// Check back later for more features!
75+
}
76+
77+
$feature = Feature::get('myAwesomeFeature');
78+
79+
$allFeatures = Feature::all();
80+
```
81+
4382
### Blade
4483

4584
Blade directive for checking if a feature is **enabled**:

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
"laravel": {
3333
"providers": [
3434
"MikeFrancis\\LaravelUnleash\\ServiceProvider"
35-
]
35+
],
36+
"aliases": {
37+
"Unleash": "MikeFrancis\\LaravelUnleash\\Facades\\Unleash",
38+
"Feature": "MikeFrancis\\LaravelUnleash\\Facades\\Feature"
39+
}
3640
}
3741
}
3842
}

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function __construct(Config $config)
1111
{
1212
parent::__construct(
1313
[
14-
'base_uri' => $config->get('unleash.url'),
14+
'base_uri' => $config->get('unleash.url'),
1515
]
1616
);
1717
}

src/Facades/Feature.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
namespace MikeFrancis\LaravelUnleash\Facades;
3+
4+
use Illuminate\Support\Facades\Facade;
5+
6+
class Feature extends Facade
7+
{
8+
public static function enabled(string $feature, ...$args): bool
9+
{
10+
return static::isFeatureEnabled($feature, ...$args);
11+
}
12+
13+
public static function disabled(string $feature, ...$args): bool
14+
{
15+
return static::isFeatureDisabled($feature, ...$args);
16+
}
17+
18+
public static function all(): array
19+
{
20+
return static::getFeatures();
21+
}
22+
23+
public static function get(string $name)
24+
{
25+
return static::getFeature($name);
26+
}
27+
28+
protected static function getFacadeAccessor()
29+
{
30+
return 'unleash';
31+
}
32+
}

src/Facades/Unleash.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace MikeFrancis\LaravelUnleash\Facades;
3+
4+
use Illuminate\Support\Facades\Facade;
5+
6+
class Unleash extends Facade
7+
{
8+
protected static function getFacadeAccessor()
9+
{
10+
return 'unleash';
11+
}
12+
}

src/ServiceProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class ServiceProvider extends IlluminateServiceProvider
1515
public function register()
1616
{
1717
$this->mergeConfigFrom($this->getConfigPath(), 'unleash');
18+
$this->app->singleton('unleash', function($app) {
19+
$client = $app->make(Client::class);
20+
return $app->make(Unleash::class, ['client' => $client]);
21+
});
1822
}
1923

2024
/**
@@ -26,11 +30,10 @@ public function boot()
2630
{
2731
$this->publishes(
2832
[
29-
$this->getConfigPath() => config_path('unleash.php'),
33+
$this->getConfigPath() => config_path('unleash.php'),
3034
]
3135
);
3236

33-
3437
Blade::if(
3538
'featureEnabled',
3639
function (string $feature) {

0 commit comments

Comments
 (0)