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

Enum Property Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony/Laravel Compatibility: The package is explicitly designed for Symfony, not Laravel. While Laravel shares some PHP/Symfony ecosystem components (e.g., Doctrine, Twig), direct integration requires:
    • Kernel/Bundle System: Laravel lacks Symfony’s AppKernel/Bundle architecture, necessitating a workaround (e.g., manual service registration or a Laravel-compatible wrapper).
    • Dependency Injection (DI): Symfony’s DI container (e.g., services.yaml) differs from Laravel’s container. The package relies on Symfony’s ParameterBag and ContainerInterface, which may not align natively.
    • Twig Integration: Laravel uses Blade by default, though Twig can be added via laravel/ui or spatie/laravel-twig. The bundle’s Twig filters/functions would require explicit setup.
  • EnumMapper Core: The underlying 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.

Integration Feasibility

  • High-Level Workarounds:
    1. Extract Core Logic: Use enum-mapper directly in Laravel (skip the bundle) by:
      • Registering AbstractEnumMapper classes as services in AppServiceProvider.
      • Implementing custom Twig extensions for filters/functions.
      • Replicating validator logic via Laravel’s Validator facade.
    2. Symfony-Laravel Bridge: Use a package like symfony/var-dumper or symfony/console for shared components, but this adds complexity.
    3. Hybrid Approach: Leverage the bundle in a Symfony microservice or API layer (e.g., via Lumen or Symfony UX) that Laravel consumes via HTTP/GraphQL.
  • Doctrine ORM: If using Doctrine in Laravel, the bundle’s enum mapping could simplify database enum handling, but this is a minor use case.

Technical Risk

  • Breaking Changes: The package is immature (no stars, minimal documentation). Risk of:
    • Undocumented Symfony dependencies (e.g., FrameworkBundle).
    • API shifts in enum-mapper breaking compatibility.
  • Maintenance Overhead: Requires custom glue code to adapt Symfony patterns to Laravel, increasing long-term maintenance.
  • Performance: Enum mapping in Laravel is often handled via:
    • Native PHP enums (PHP 8.1+).
    • Database-level enums (PostgreSQL/MySQL).
    • Simple const classes. The bundle may add unnecessary abstraction.

Key Questions

  1. Why Enums?
    • Are you using enums for database storage, domain modeling, or API responses? Native solutions (e.g., PHP 8.1 enums + Doctrine) may suffice.
  2. Symfony Dependency Tolerance:
    • Can the project tolerate Symfony-specific code (e.g., ContainerAware traits) in a Laravel app?
  3. Validation Needs:
    • Does the bundle’s validator integration solve a gap not covered by Laravel’s Validator or FormRequest?
  4. Twig Requirement:
    • Is Twig a hard requirement, or can Blade templates handle enum logic via helpers?
  5. Alternatives:

Integration Approach

Stack Fit

  • Laravel Stack Compatibility:
    • ✅ Core PHP: Works (enum-mapper is PHP-native).
    • ❌ Symfony Ecosystem: Bundle requires Symfony’s Kernel, DependencyInjection, and Twig components. Laravel alternatives:
      • Replace AppKernel with AppServiceProvider for service registration.
      • Replace services.yaml with Laravel’s config/services.php.
      • Replace Twig filters with Blade directives or custom helpers.
    • ⚠️ Doctrine: If using Doctrine, the bundle’s enum mapping might integrate, but this is untested.
  • Recommended Stack:
    • For Minimal Impact: Use enum-mapper directly + custom Laravel services.
    • For Full Bundle: Requires:
      • Laravel 8+ (for Symfony 5+ compatibility).
      • spatie/laravel-twig for Twig support.
      • Custom ServiceProvider to replicate bundle logic.

Migration Path

  1. Phase 1: Proof of Concept (PoC)

    • Install enum-mapper standalone:
      composer require adrenalinkin/enum-mapper
      
    • Implement a basic 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();
              });
          }
      }
      
    • Test enum mapping in a controller/model.
  2. Phase 2: Bundle Integration (If Needed)

    • Fork the bundle and replace Symfony-specific code with Laravel equivalents:
      • Replace Bundle with a ServiceProvider.
      • Replace services.yaml with Laravel config.
      • Replace Twig extensions with Blade directives.
    • Example Twig-to-Blade migration:
      {{ enum_filter(gender) }}  {# Twig #}
      
      // Blade: Create a helper in `app/Helpers/enum.php`
      function enum_filter($enum) { ... }
      
      @enum_filter($gender)
      
  3. Phase 3: Validation/Twig

    • Replace bundle validators with Laravel’s Validator::extend().
    • Add Twig support via spatie/laravel-twig if required.

Compatibility

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

Sequencing

  1. Assess Need: Confirm enums are a pain point not solved by PHP 8.1 enums or Doctrine.
  2. PoC: Test enum-mapper standalone before committing to bundle integration.
  3. Stack Decision:
    • If using Symfony components (e.g., API Platform), consider a hybrid Symfony/Laravel setup.
    • If pure Laravel, avoid the bundle and use native solutions or enum-mapper directly.
  4. Incremental Rollout:
    • Start with enum mapping in models.
    • Add Twig/validation only if needed.

Operational Impact

Maintenance

  • Bundle-Specific Risks:
    • Forking Required: Likely need to maintain a Laravel-compatible fork due to Symfony dependencies.
    • Dependency Bloat: Adding Symfony components (e.g., Twig, Validator) increases attack surface.
  • Native Alternatives:
    • PHP 8.1 enums + Doctrine require zero maintenance.
    • Custom helpers for Twig/validation are easier to debug than bundle interactions.
  • Long-Term Cost:
    • Bundle: High (Symfony-Laravel context switching).
    • Native: Low (standard Laravel patterns).

Support

  • Community:
    • Bundle: No stars/issues → no community support.
    • Underlying enum-mapper: Also minimal activity.
  • Debugging:
    • Symfony-specific errors (e.g., Container misconfigurations) will be harder to diagnose in Laravel.
    • Example error:
      Call to undefined method Illuminate\Container\Container::getParameterBag()
      
  • Vendor Lock-in:
    • Tight coupling to adrenalinkin packages may limit future flexibility.

Scaling

  • Performance:
    • Enum mapping is O(1) in both approaches. No scalability impact expected.
  • Team Onboarding:
    • Bundle: Requires Symfony knowledge (e.g., Bundle lifecycle, services.yaml).
    • Native: Familiar Laravel patterns (ServiceProvider, helpers).
  • Monorepo Considerations:
    • If using a Symfony/Laravel hybrid, the bundle could work in the Symfony portion.

Failure Modes

Risk Bundle Impact Native Impact
Symfony Dependency Breaks ❌ Fails in Laravel
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony