Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Openfeature Configcat Bundle Laravel Package

aubes/openfeature-configcat-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the bundle:

    composer require aubes/openfeature-configcat-bundle
    

    Manually register the bundle in config/bundles.php if Symfony Flex isn't used:

    Aubes\OpenFeatureConfigCatBundle\OpenFeatureConfigCatBundle::class => ['all' => true],
    
  2. Configure the bundle in config/packages/open_feature_configcat.yaml:

    open_feature_config_cat:
        sdk_key: '%env(CONFIGCAT_SDK_KEY)%'
    

    Ensure CONFIGCAT_SDK_KEY is set in your .env file.

  3. First use case: Fetch a feature flag in a service:

    use ConfigCat\OpenFeature\ConfigCatProvider;
    use OpenFeature\OpenFeatureAPI;
    
    class FeatureService {
        public function __construct(private ConfigCatProvider $provider) {}
    
        public function toggleDarkMode(): bool {
            return OpenFeatureAPI::getInstance()
                ->setProvider($this->provider)
                ->getClient()
                ->getBooleanValue('dark_mode', false);
        }
    }
    

Implementation Patterns

Dependency Injection

  • Inject ConfigCatProvider directly into services for OpenFeature API access.
  • Leverage Symfony’s container to manage provider lifecycle (e.g., caching, logging).

Integration with OpenFeature Bundle (Optional)

If using aubes/openfeature-bundle, configure it to use this provider:

# config/packages/open_feature.yaml
open_feature:
    provider: ConfigCat\OpenFeature\ConfigCatProvider

This unlocks:

  • Attributes (#[FeatureFlag], #[FeatureGate]).
  • Twig helpers (e.g., feature_flag()).
  • Request-scoped evaluation (e.g., user-specific flags).

Flag Overrides

Use local overrides for development/testing:

open_feature_config_cat:
    flag_overrides:
        type: file
        path: '%kernel.project_dir%/config/feature_flags.json'
        behaviour: local_over_remote  # Overrides remote flags

HTTP Client Customization

Replace Guzzle with Symfony’s HttpClient (PSR-18):

# config/services.yaml
services:
    Aubes\OpenFeatureConfigCatBundle\Http\Psr18FetchClient:
        arguments:
            $client: '@psr18.http_client'
            $requestFactory: '@Psr\Http\Message\RequestFactoryInterface'

# config/packages/open_feature_configcat.yaml
open_feature_config_cat:
    fetch_client: Aubes\OpenFeatureConfigCatBundle\Http\Psr18FetchClient

Gotchas and Tips

Pitfalls

  1. Missing SDK Key:

    • If sdk_key is omitted, the provider will fail silently. Validate in config/validator.yaml:
      services:
          _defaults:
              autowire: true
              bind:
                  ConfigCat\OpenFeature\ConfigCatProvider::class: '@open_feature_config_cat.provider'
      
    • Add a runtime check:
      if (empty($provider->getSdkKey())) {
          throw new \RuntimeException('ConfigCat SDK key not configured.');
      }
      
  2. Caching Conflicts:

    • Avoid mixing cache and cache_pool in config. They are mutually exclusive.
  3. Offline Mode:

    • Set offline: true for development, but ensure flag_overrides are configured to avoid empty flag evaluations.

Debugging

  • Enable Logging:

    open_feature_config_cat:
        logger: '@monolog.logger.configcat'
    

    Logs will include flag evaluation details and fetch errors.

  • Check Cache: If flags aren’t updating, verify the cache_refresh_interval (default: 60s) and clear the cache:

    php bin/console cache:clear
    

Extension Points

  1. Custom Fetch Client: Implement ConfigCat\Http\FetchClientInterface for custom HTTP logic (e.g., retries, proxies).

  2. Override Data Sources: For dynamic overrides, inject a service:

    open_feature_config_cat:
        flag_overrides:
            type: service
            id: 'app.feature_flag_override_service'
    
  3. Data Governance: Use data_governance: eu_only to comply with GDPR by hosting data in the EU.

Performance Tips

  • Batch Evaluations: Use getBooleanValues(), getStringValues(), etc., to fetch multiple flags in one request.
  • Lazy Initialization: Defer provider setup until first use to avoid blocking bootstrapping:
    OpenFeatureAPI::getInstance()->setProvider($provider);
    

Testing

  • Mock the Provider:
    $provider = $this->createMock(ConfigCatProvider::class);
    $provider->method('getBooleanValue')->willReturn(true);
    OpenFeatureAPI::getInstance()->setProvider($provider);
    
  • Use Offline Mode: Test locally with offline: true and flag_overrides to avoid network calls.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
amashukov/lnd-client-php
althinect/enum-permission
andydefer/laravel-actions
aimeos/prisma
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky