#[AsFeature] attributes, ProviderInterface, and Symfony’s service container). While this ensures seamless integration with Symfony applications, it does not natively support Laravel or PHP standalone projects without abstraction layers (e.g., Symfony Bridge or custom adapters).ProviderInterface allows for custom backends (e.g., database, API-based, or hybrid providers), which is valuable for Laravel’s flexible architecture. However, Laravel’s event system and service container would need to be adapted to the bundle’s provider chain model.#[AsFeature] attributes to Laravel’s service bindings or annotations (e.g., using illuminate/support/Traits or custom annotations).ProviderInterface to Laravel’s service provider or container extensions (e.g., via Illuminate\Contracts\Container\Container).feature_is_enabled) with Laravel’s route middleware or service-based guards.feature_is_enabled) would need to be reimplemented as Blade directives or helper functions (e.g., feature_flag()).ProviderInterface would need to be adapted to Laravel’s DI container.HttpKernel, DependencyInjection, and Attribute components, which are not natively available in Laravel. Risk mitigation requires:
Attribute, ContainerInterface).ProviderInterface with Laravel’s ServiceProvider.#[AsFeature] attribute would need to be redefined or mapped to Laravel’s service registration (e.g., via register() in a service provider).Route::where(), middleware) does not natively support dynamic conditions like Symfony’s condition attribute. Workarounds include:
FeatureFlagMiddleware).Gate::for() or custom Closure guards).Is Symfony Interoperability Required?
Config, Cache, or Database) may be simpler.What Are the Feature Flag Use Cases?
How Will Providers Be Implemented?
.env or config files.What’s the Fallback for Unsupported Features?
Route::middleware().#[Inject] or custom annotations.How Will Testing Be Handled?
Mockery, Pest) would need to mock providers and service bindings.Laravel’s Compatibility:
Illuminate\Container can replace Symfony’s ContainerInterface with adapters (e.g., Symfony\Component\DependencyInjection\ContainerInterface polyfill).#[AsFeature] must be redefined or mapped to Laravel’s service registration (e.g., via a FeatureFlagServiceProvider).condition attribute.Key Mappings:
| Symfony Feature | Laravel Equivalent | Implementation Notes |
|---|---|---|
#[AsFeature] Attribute |
Custom annotation or trait | Use Illuminate\Support\Traits\Macroable or a service provider to register features. |
ProviderInterface |
Laravel Service Provider | Implement a FeatureFlagProvider interface and bind it to the container. |
| Routing conditions | Middleware or Route::where() |
Create FeatureFlagMiddleware or use Gate::for(). |
| Twig functions | Blade directives or helpers | Register Blade::directive() or global feature_flag() helper. |
Phase 1: Core Integration
FeatureFlagServiceProvider) to:
FeatureFlagManager).ProviderInterface to Laravel’s container.FeatureFlagProvider class that adapts Symfony’s ProviderInterface to Laravel’s DI.#[AsFeature] with a Laravel-compatible attribute or service registration macro.Phase 2: Backend Providers
feature_flags table.config/feature-flags.php.// app/Providers/FeatureFlagDatabaseProvider.php
class FeatureFlagDatabaseProvider implements FeatureFlagProvider
{
public function get(string $featureName): ?callable
{
return function () use ($featureName) {
return FeatureFlag::where('name', $featureName)->value('enabled');
};
}
}
Phase 3: Routing and Templating
// app/Http/Middleware/FeatureFlagMiddleware.php
public function handle(Request $request, Closure $next, string $feature)
{
if (!feature_flag()->isEnabled($feature)) {
abort(404); // or redirect
}
return $next($request);
}
Blade::directive('feature', function ($flag) {
return "<?php if (feature_flag()->isEnabled({$flag})): ?>";
});
Phase 4: Testing and Validation
symfony/attribute for PHP 8.0).symfony/http-foundation or symfony/dependency-injection as a composer dependency.How can I help you explore Laravel packages today?