PHP code example of krak / symfony-rollout-rox

1. Go to this page and download the library: Download krak/symfony-rollout-rox 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/ */

    

krak / symfony-rollout-rox example snippets




return [
  //...
  Krak\SymfonyRox\RoxBundle::class => ['all' => true],
];



namespace App\FeatureFlags;

use Krak\SymfonyRox\RoxContainer;
use Rox\Server\Flags\RoxFlag;

final class ProductContainer implements RoxContainer
{
    public $showQtyOnPDP;

    public function __construct() {
        $this->showQtyOnPDP = new RoxFlag(false);
    }
    
    // the namespace controls the prefix used in the rollout admin
    // when displaying your flags or variants. Every container MUST have a unique 
    // namespace.
    public function getNamespace(): string {
        return 'product';
    }
}



namespace App\Service;

use Krak\SymfonyRox\RoxContainerStore;

final class BuildPDPPrices
{
    private $flagsStore;

    public function __construct(RoxContainerStore $flagsStore) {
        $this->flagsStore = $flagsStore;
    }

    public function __invoke(string $productId): array {
        $container = $this->flagsStore->get(\App\FeatureFlags\ProductContainer::class);
        return [
            'qty' => $container->showQtyOnPDP->isEnabled() ? 1 : null,
            'price' => 100,
        ];
    }
}