PHP code example of exolnet / laravel-bento

1. Go to this page and download the library: Download exolnet/laravel-bento library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

exolnet / laravel-bento example snippets


App\Providers\BentoServiceProvider::class

Bento::feature('feature')->visitorPercent(10);

Bento::feature('feature')->visitorPercent(10)->hostname('example.com');



namespace App\Providers;

use Exolnet\Bento\Facades\Bento;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * @return void
     */
    public function boot(): void
    {
        Bento::feature('foo')->everyone();
        Bento::feature('bar')->everyone();
    }
}

if (Bento::launch('feature')) {
    //
}

if (Bento::await('feature')) {
    //
}

    protected $routeMiddleware = [
        // ...
        'await' => \Exolnet\Bento\Middleware\Await::class,
        'launch' => \Exolnet\Bento\Middleware\Launch::class,
        // ...
    ];

Route::middleware('launch:feature')->group(function () {
    //
});

Route::middleware('await:feature')->group(function () {
    //
});

Bento::feature('feature')->not->everyone();

use \Exolnet\Bento\Strategy\AimsStrategies;

Bento::feature('feature')->all(function (AimsStrategies $aims) {
    $aims
        ->environment('production')
        ->visitorPercent(20);
});

use \Exolnet\Bento\Strategy\AimsStrategies;

Bento::feature('feature')->any(function (AimsStrategies $aims) {
    $aims
        ->environment('staging')
        ->user([1, 2]);
});

use Illuminate\Contracts\Auth\Guard;

Bento::feature('feature')->custom(function (Guard $guard, $role) {
    return $guard->user() && $guard->user()->role === 'admin';
});

use Illuminate\Contracts\Auth\Guard;

class RoleStrategy {
    /**
     * @var \Illuminate\Contracts\Auth\Guard
     */
    protected $guard;
    
    /**
     * @var string 
     */
    protected $role;

    /**
     * @param \Illuminate\Contracts\Auth\Guard $guard
     */
    public function __construct(Guard $guard, string $role)
    {
        $this->guard = $guard;
        $this->role = $role;
    }

    /**
     * @return bool
     */
    public function launch(): bool
    {
        return $this->guard->user() && $this->guard->user()->role === $this->role;
    }
}

Bento::feature('feature')->aim(RoleStrategy::class, 'admin');
bash
php artisan vendor:publish --tag=bento-provider