PHP code example of check24 / feature-flag-bundle

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

    

check24 / feature-flag-bundle example snippets


use Shopping\FeatureFlagBundle\Annotation\IsActive;

/**
 * @Route("test")
 * @IsActive("foobar")
 * @return Response
 */
public function test(): Response
{
    return new Response('I can see you.');
}

use Shopping\FeatureFlagBundle\Service\FeatureFlagInterface;

class SomeService
{
    private $featureFlag;

    public function __construct(FeatureFlagInterface $featureFlag)
    {
        $this->featureFlag = $featureFlag;
    }

    public function getNumber(): int
    {
        if ($this->featureFlag->isActive('foobar')) {
            return 2;
        }

        return 1;
    }
}

//src/FeatureFlagProvider/MorningProvider.php

namespace App\FeatureFlagProvider;

class MorningProvider implements FeatureFlagInterface
{
    /**
     * @param string $featureFlag
     *
     * @return bool
     */
    public function isActive(string $featureFlag): bool
    {
        if ($featureFlag !== 'morningShow') {
            return false;
        }

        $hour = (new \DateTime())->format('G');

        return $hour >= 8 && $hour <= 10;
    }
}