Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor
/.idea

.phpunit.result.cache
phpunit.xml
Expand Down
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Documentation for configuration can be found in [config/unleash.php](https://git
## Usage

```php

use \MikeFrancis\LaravelUnleash\Unleash;

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

$feature = $unleash->getFeature('myAwesomeFeature');

$allFeatures = $unleash->getFeatures();
```

### Facades

You can use the `Unleash` facade:

```php
use Unleash;

if (Unleash::isFeatureEnabled('myAwesomeFeature')) {
// Congratulations, you can see this awesome feature!
}

if (Unleash::isFeatureDisabled('myAwesomeFeature')) {
// Check back later for more features!
}

$feature = Unleash::getFeature('myAwesomeFeature');

$allFeatures = Unleash::getFeatures();
```

or use the generically named `Feature` facade:

```php
use Feature;

if (Feature::enabled('myAwesomeFeature')) {
// Congratulations, you can see this awesome feature!
}

if (Feature::disabled('myAwesomeFeature')) {
// Check back later for more features!
}

$feature = Feature::get('myAwesomeFeature');

$allFeatures = Feature::all();
```

### Blade

Blade directive for checking if a feature is **enabled**:
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
"laravel": {
"providers": [
"MikeFrancis\\LaravelUnleash\\ServiceProvider"
]
],
"aliases": {
"Unleash": "MikeFrancis\\LaravelUnleash\\Facades\\Unleash",
"Feature": "MikeFrancis\\LaravelUnleash\\Facades\\Feature"
}
}
}
}
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function __construct(Config $config)
{
parent::__construct(
[
'base_uri' => $config->get('unleash.url'),
'base_uri' => $config->get('unleash.url'),
]
);
}
Expand Down
32 changes: 32 additions & 0 deletions src/Facades/Feature.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace MikeFrancis\LaravelUnleash\Facades;

use Illuminate\Support\Facades\Facade;

class Feature extends Facade
{
public static function enabled(string $feature, ...$args): bool
{
return static::isFeatureEnabled($feature, ...$args);
}

public static function disabled(string $feature, ...$args): bool
{
return static::isFeatureDisabled($feature, ...$args);
}

public static function all(): array
{
return static::getFeatures();
}

public static function get(string $name)
{
return static::getFeature($name);
}

protected static function getFacadeAccessor()
{
return 'unleash';
}
}
12 changes: 12 additions & 0 deletions src/Facades/Unleash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace MikeFrancis\LaravelUnleash\Facades;

use Illuminate\Support\Facades\Facade;

class Unleash extends Facade
{
protected static function getFacadeAccessor()
{
return 'unleash';
}
}
7 changes: 5 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class ServiceProvider extends IlluminateServiceProvider
public function register()
{
$this->mergeConfigFrom($this->getConfigPath(), 'unleash');
$this->app->singleton('unleash', function ($app) {
$client = $app->make(Client::class);
return $app->make(Unleash::class, ['client' => $client]);
});
}

/**
Expand All @@ -26,11 +30,10 @@ public function boot()
{
$this->publishes(
[
$this->getConfigPath() => config_path('unleash.php'),
$this->getConfigPath() => config_path('unleash.php'),
]
);


Blade::if(
'featureEnabled',
function (string $feature) {
Expand Down