Fast Forward PSR-11 Container utility classes
    • Fastforward-Container
      • Getting Started
        • Installation
        • Quickstart
        • Basic Usage
      • Service Providers
        • Built-in Factories
        • Built-in Providers
        • Writing Your Own Provider
        • Using Factories in Providers
      • Examples
        • Basic Usage
        • Registering Providers
        • Testing with Providers
        • Using Factories
        • Runtime Feature Toggle
        • Integrating with Laravel
        • Integrating with Slim Framework
      • Advanced Topics
        • Integrations
        • Autowire
        • Error Reporting
        • Container Helper Function
        • Built-in Containers
        • Special Patterns and Advanced Behaviors
      • API Reference
        • Core API
        • Factories API
        • Providers API
        • Exceptions API
      • Links
        • Dependencies
      • FAQ
      • Compatibility
    • Namespaces
      • FastForward
        • Container
          • Exception
          • Factory
          • ServiceProvider
    • Packages
      • FastForward
        • Container
    • Reports
      • Deprecated
      • Errors
      • Markers
    • Indices
      • Files

    Runtime Feature Toggle

    This example demonstrates how to use providers to enable or disable features at runtime.

    use FastForward\Container\ServiceProvider\ArrayServiceProvider;
    use function FastForward\Container\container;
    
    $featureEnabled = true;
    
    $provider = new ArrayServiceProvider([
        'feature' => fn() => $featureEnabled ? new RealFeature() : new NullFeature(),
    ]);
    
    $container = container($provider);
    $feature = $container->get('feature');
    $feature->run();
    Search results