1. Go to this page and download the library: Download stogon/unleash-bundle 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/ */
stogon / unleash-bundle example snippets
namespace App\Controller;
use Stogon\UnleashBundle\UnleashInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
#[Route('/', name: 'homepage')]
public function index(UnleashInterface $unleash): Response
{
if ($unleash->isFeatureEnabled('my_awesome_feature')) {
// do something awesome !
}
if ($unleash->isFeatureDisabled('my_other_feature')) {
// do something else
}
return $this->render('home/index.html.twig');
}
}
namespace App\Unleash\Strategy;
use Stogon\UnleashBundle\Strategy\StrategyInterface;
class MyCustomStrategy implements StrategyInterface
{
public function isEnabled(array $parameters = [], array $context = [], ...$args): bool
{
// TODO: Implement your custom logic here.
return false;
}
}
namespace App\EventSubscriber;
use Stogon\UnleashBundle\Event\UnleashContextEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UnleashContextSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
UnleashContextEvent::class => ['onUnleashContextEvent'],
];
}
public function onUnleashContextEvent(UnleashContextEvent $event): void
{
// Get the original payload as an array;
$payload = $event->getPayload();
// Set some custom data
$payload['awesome_data'] = 'amazing';
// Update payload
$event->setPayload($payload);
}
}