Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.7 KB

File metadata and controls

39 lines (29 loc) · 1.7 KB

Getting started

This guide assumes you have already installed and registered the bundle (see the README Quick start) and added a minimal open_feature.yaml with a few flags.

Your first controller

Two PHP attributes cover most use cases: #[FeatureGate] to guard access, #[FeatureFlag] to inject resolved values.

use Aubes\OpenFeatureBundle\Attribute\FeatureFlag;
use Aubes\OpenFeatureBundle\Attribute\FeatureGate;
use Symfony\Component\HttpFoundation\Response;

class CheckoutController
{
    #[FeatureGate('new_checkout')]
    public function checkout(
        #[FeatureFlag('dark_mode')] bool $darkMode,
        #[FeatureFlag('max_items')] int $maxItems,
    ): Response {
        // $darkMode and $maxItems are resolved from the active provider
    }
}

What happens here:

  • #[FeatureGate('new_checkout')] : the method is unreachable when new_checkout evaluates to false. A 403 is thrown (configurable, see Configuration).
  • #[FeatureFlag('dark_mode')] bool $darkMode : the flag is resolved as a boolean based on the parameter type hint.
  • #[FeatureFlag('max_items')] int $maxItems : same, resolved as an integer via getIntegerValue().

Type dispatch is automatic for bool, string, int, float, and array. See #[FeatureFlag] for the full table.

Next steps