configcat/openfeature-provider
OpenFeature provider for PHP that connects the OpenFeature PHP SDK to ConfigCat. Configure with your ConfigCat SDK key and optional client options, then evaluate feature flags via the OpenFeature client (boolean, string, etc.). PHP 8.1+.
FeatureManager facade or custom providers).OpenFeatureAPI with ConfigCatProvider and inject the client where needed (e.g., middleware, services, or controllers).OpenFeatureAPI as a singleton).cache config).FeatureFlagMiddleware).FeatureFlagUpdated) for reactive updates.App\Exceptions\Handler) should log/fallback gracefully..env or a config service.false for non-critical features).OpenFeatureAPI as a singleton in config/app.php or a service provider:
$this->app->singleton(OpenFeatureAPI::class, function () {
$api = OpenFeatureAPI::getInstance();
$api->setProvider(new ConfigCatProvider(env('CONFIGCAT_SDK_KEY'), [
ClientOptions::CACHE_REFRESH_INTERVAL => 5, // seconds
ClientOptions::LOG_LEVEL => LogLevel::ERROR,
]));
return $api;
});
FeatureManager facade to simplify usage:
namespace App\Facades;
use OpenFeatureAPI;
class FeatureManager {
public static function getBoolean(string $flagKey, bool $default): bool {
return OpenFeatureAPI::getInstance()->getClient()->getBooleanValue($flagKey, $default);
}
}
maintenance_mode) in HandleIncomingRequest middleware:
public function handle($request, Closure $next) {
if (FeatureManager::getBoolean('maintenance_mode', false)) {
abort(503);
}
return $next($request);
}
php artisan config:cache) to reduce overhead.FeatureManager calls..env.CONFIGCAT_SDK_KEY) to Laravel’s config system.open-feature/php-sdk:^0.10) matches Laravel’s compatibility.redis for distributed setups).CONFIGCAT_SDK_KEY to .env.composer require configcat/openfeature-provider).composer why-not to test updates.composer.json to avoid surprises:
"configcat/openfeature-provider": "^1.0",
"open-feature/php-sdk": "^0.10"
config/configcat.php to avoid .env sprawl.LogLevel::DEBUG) during debugging, then revert to ERROR in production.ConfigCatProvider behind an interface (e.g., FeatureFlagProvider) to swap providers later (e.g., for LaunchDarkly).interface FeatureFlagProvider {
public function getBoolean(string $key, bool $default): bool;
}
class ConfigCatProvider implements FeatureFlagProvider { ... }
CACHE_REFRESH_INTERVAL to 5–60 seconds (trade-off between freshness and latency).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| ConfigCat API downtime | Flags return defaults | Use Laravel’s cache as a fallback; implement circuit breakers. |
| Invalid SDK key | All |
How can I help you explore Laravel packages today?