adrenalinkin/enum-property-bundle
Symfony bundle integrating EnumMapper: adds Twig filters/functions to convert enum DB values to human labels and back, fetch full enum maps, and provides validation support for enum properties. Install via Composer and enable the bundle in AppKernel.
AppKernel/Bundle architecture, necessitating a workaround (e.g., manual service registration or a Laravel-compatible wrapper).services.yaml) differs from Laravel’s container. The package relies on Symfony’s ParameterBag and ContainerInterface, which may not align natively.laravel/ui or spatie/laravel-twig. The bundle’s Twig filters/functions would require explicit setup.enum-mapper component is PHP-agnostic and could theoretically work in Laravel if manually integrated (e.g., via service providers). The bundle adds Symfony-specific glue.enum-mapper directly in Laravel (skip the bundle) by:
AbstractEnumMapper classes as services in AppServiceProvider.Validator facade.symfony/var-dumper or symfony/console for shared components, but this adds complexity.FrameworkBundle).enum-mapper breaking compatibility.const classes. The bundle may add unnecessary abstraction.ContainerAware traits) in a Laravel app?Validator or FormRequest?spatie/laravel-enum or myclabs/php-enum for Laravel?Kernel, DependencyInjection, and Twig components. Laravel alternatives:
AppKernel with AppServiceProvider for service registration.services.yaml with Laravel’s config/services.php.enum-mapper directly + custom Laravel services.spatie/laravel-twig for Twig support.ServiceProvider to replicate bundle logic.Phase 1: Proof of Concept (PoC)
enum-mapper standalone:
composer require adrenalinkin/enum-mapper
EnumMapper service in AppServiceProvider:
use Linkin\Component\EnumMapper\Mapper\AbstractEnumMapper;
class AppServiceProvider extends ServiceProvider {
public function register() {
$this->app->singleton(GenderMapper::class, function () {
return new GenderMapper();
});
}
}
Phase 2: Bundle Integration (If Needed)
Bundle with a ServiceProvider.services.yaml with Laravel config.{{ enum_filter(gender) }} {# Twig #}
// Blade: Create a helper in `app/Helpers/enum.php`
function enum_filter($enum) { ... }
@enum_filter($gender)
Phase 3: Validation/Twig
Validator::extend().spatie/laravel-twig if required.| Feature | Symfony Bundle | Laravel Workaround |
|---|---|---|
| Enum Mapping | ✅ Native | ✅ Manual service registration |
| Twig Filters/Functions | ✅ Built-in | ❌ Requires spatie/laravel-twig + custom code |
| Validator Integration | ✅ Symfony Validator | ✅ Laravel Validator::extend() |
| Doctrine Integration | ✅ (if used) | ⚠️ Untested |
| Kernel/Bundle System | ✅ Required | ❌ Not applicable |
enum-mapper standalone before committing to bundle integration.enum-mapper directly.Twig, Validator) increases attack surface.enum-mapper: Also minimal activity.Container misconfigurations) will be harder to diagnose in Laravel.Call to undefined method Illuminate\Container\Container::getParameterBag()
adrenalinkin packages may limit future flexibility.Bundle lifecycle, services.yaml).ServiceProvider, helpers).| Risk | Bundle Impact | Native Impact |
|---|---|---|
| Symfony Dependency Breaks | ❌ Fails in Laravel |
How can I help you explore Laravel packages today?