PHP code example of halloverden / symfony-feature-flag-bundle

1. Go to this page and download the library: Download halloverden/symfony-feature-flag-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/ */

    

halloverden / symfony-feature-flag-bundle example snippets


// config/bundles.php

return [
    // ...
    HalloVerden\FeatureFlagBundle\HalloVerdenFeatureFlagBundle::class => ['all' => true],
];



namespace App\Entity\FeatureFlag;

use Doctrine\ORM\Mapping as ORM;
use HalloVerden\FeatureFlagBundle\Entity\FeatureFlag;

/**
 * Class TestFeatureFlag
 *
 * @package App\Entity\FeatureFlag
 *
 * @ORM\Entity()
 */
class TestFeatureFlag extends FeatureFlag {

  /* If you add additonal properties, override setFromConsole */

  /**
   * @inheritDoc
   */
  public static function getType(): string {
    return 'TEST';
  }

}



namespace App\Services;

use App\Entity\FeatureFlag\TestFeatureFlag;
use HalloVerden\FeatureFlagBundle\Services\FeatureFlagServiceInterface;

class SomeService {
  private FeatureFlagServiceInterface $featureFlagService;

  public function __construct(FeatureFlagServiceInterface $featureFlagService) {
    $this->featureFlagService = $featureFlagService;
  }
  
  public function test(): void {
    if (!$this->featureFlagService->isActive(TestFeatureFlag::class)) {
      return; // or throw an exception
    }
    
    // Do the thing that