Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.41 KB

feature-flags.md

File metadata and controls

49 lines (36 loc) · 1.41 KB

Feature Flags Extractor

<?php

use OAT\Library\EnvironmentManagementClient\Http\FeatureFlagExtractorInterface;
use OAT\Library\EnvironmentManagementClient\Http\FeatureFlagHeaderExtractor;
use OAT\Library\EnvironmentManagementClient\Model\FeatureFlag;
use Psr\Http\Message\MessageInterface;

class MyService {
    /** @var FeatureFlagExtractorInterface  */
    private $featureFlagExtractor;
    
    public function __construct(FeatureFlagExtractorInterface $featureFlagExtractor)
    {
        $this->featureFlagExtractor = $featureFlagExtractor;
    }
    
    public function myMethod(): void
    {
        //...
        
        /** @var MessageInterface $message */
        $message = ...
        
        $flagCollection = $this->featureFlagExtractor->extract($message);
        
        $flagCollection->isEmpty();
        $flagCollection->has('flag-1');
        
        /** @var FeatureFlag $flag */
        $flag = $flagCollection->get('flag-1');
        $flag->getName();
        $flag->getValue();
        
        $flagCollection->all();
        
        //...
    }
}

$myService = new MyService(new FeatureFlagHeaderExtractor());
$myService->myMethod();