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

Doctrine Enum Type Laravel Package

acelaya/doctrine-enum-type

Doctrine DBAL type for mapping MyCLabs\Enum\Enum values to entity columns. Provides a reusable PhpEnumType to register enums as custom Doctrine types. Note: largely obsolete now that PHP has native enums and Doctrine supports them.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: Continues to fit Laravel applications using Doctrine ORM (via spatie/laravel-doctrine or Symfony integration) for type-safe enums. No change—still a poor fit for native Eloquent unless Doctrine is explicitly adopted.
  • Paradigm Compatibility: Remains aligned with type safety and DDD, enforcing enum constraints at the database layer. Contrasts with Eloquent’s dynamic typing but offers stricter validation.
  • Layer Abstraction: Operates at the Doctrine type system level, requiring minimal application-layer changes if Doctrine is already in use.

Integration Feasibility

  • Doctrine DBAL 3.0 Support: Critical update—now compatible with Doctrine DBAL 3.0, resolving potential integration blocks for modern Symfony/Laravel setups using newer Doctrine versions.
  • Doctrine ORM Dependency: Still mandates Doctrine ORM (not native to Laravel). Requires either:
    • A Symfony-based Laravel setup (e.g., spatie/laravel-doctrine).
    • A hybrid architecture where Doctrine handles specific entities while Eloquent manages others.
  • Enum Backend: Still relies on myclabs/php-enum (deprecated in favor of PHP 8.1+ native enums or ramsey/uuid-style enums). No change—may still need polyfills or migration.
  • Database Schema Impact: Enums must be predefined in the database (e.g., ENUM('value1', 'value2')), limiting flexibility for dynamic enums.

Technical Risk

  • Deprecation Risk: Package archived in 2021; no PHP 8.x/Doctrine 3.x compatibility guarantees beyond DBAL 3.0. Risk of breaking changes with modern Doctrine ORM (e.g., Doctrine 3.x).
  • Performance Overhead: Enum hydration/dehydration adds minor overhead vs. native types. No change—benchmark if used in high-throughput systems.
  • Tooling Gaps: Limited IDE support (e.g., PHPStorm enum autocompletion may not integrate seamlessly). No change—manual type hints required.
  • Migration Complexity: Switching from Eloquent to Doctrine for enum-heavy models may require refactoring repositories, queries, and migrations. No change.

Key Questions

  1. Why Doctrine? Is Doctrine already in use, or is this a greenfield decision? If the latter, weigh tradeoffs vs. Eloquent’s simplicity.
  2. Enum Strategy: Are enums static (known at compile time) or dynamic (runtime-defined)? Dynamic enums may conflict with database ENUM types.
  3. PHP Version: Is PHP 8.1+ native enums an option? If yes, consider ramsey/uuid-style enums or Spatie’s Laravel Enums instead.
  4. Testing Coverage: Does the team have experience with Doctrine? Lack of familiarity could slow adoption.
  5. Long-Term Viability: Despite DBAL 3.0 support, the package’s archival status remains a risk. Is a maintained alternative (e.g., doctrine/doctrine-enum-bundle) preferable?
  6. Doctrine ORM Version: What version of Doctrine ORM is in use? DBAL 3.0 support does not guarantee ORM compatibility (e.g., Doctrine 2.10 vs. 3.x).

Integration Approach

Stack Fit

  • Target Environments:
    • Laravel + Doctrine: Ideal for apps using spatie/laravel-doctrine or Symfony components, now with DBAL 3.0 support.
    • Hybrid Eloquent/Doctrine: Possible but requires entity mapping layers (e.g., Doctrine entities extending Eloquent models).
    • Pure Eloquent: Not recommended—use Spatie/laravel-enum or native PHP 8.1 enums instead.
  • Database Compatibility:
    • MySQL/PostgreSQL: Native ENUM support.
    • SQLite: Limited ENUM support (may need workarounds like TEXT + validation).
    • SQL Server: Use VARCHAR with application-level validation.
  • Doctrine Version Alignment:
    • DBAL 3.0: Now compatible with modern Doctrine setups (e.g., Symfony 6.x).
    • ORM Version: Unverified—test with your specific Doctrine ORM version (e.g., 2.10 vs. 3.x).

Migration Path

  1. Assess Current State:
    • Audit enum usage (Eloquent models, constants, or raw strings).
    • Identify Doctrine-compatible entities (or plan to migrate).
  2. Update Dependencies:
    • Ensure Doctrine DBAL 3.0 is installed (doctrine/dbal:^3.0).
    • Test compatibility with your Doctrine ORM version.
  3. Setup Doctrine:
    • Install doctrine/orm + acelaya/doctrine-enum-type.
    • Configure Doctrine in config/doctrine.php (if using Spatie’s package).
  4. Model Migration:
    • Replace Eloquent models with Doctrine entities (same as before):
      use Acelaya\DoctrineEnumType\Type\EnumType;
      use Myclabs\Enum\Enum;
      
      #[ORM\Entity]
      class UserStatus implements Enum
      {
          public const ACTIVE = 'active';
          public const INACTIVE = 'inactive';
      }
      
      #[ORM\Entity]
      class User
      {
          #[ORM\Column(type: EnumType::NAME, enumClass: UserStatus::class)]
          private UserStatus $status;
      }
      
  5. Database Schema Update:
    • Alter tables to use ENUM types (or VARCHAR with validation).
    • Example MySQL:
      ALTER TABLE users MODIFY status ENUM('active', 'inactive');
      
  6. Query Layer Adjustments:
    • Replace Eloquent queries with Doctrine QueryBuilder or DQL (same as before).

Compatibility

  • Doctrine DBAL 3.0: Now supported—resolves integration blocks for modern setups.
  • Doctrine ORM: Unverified—test with your specific ORM version (e.g., 2.10 vs. 3.x).
  • Enum Library: Still requires myclabs/php-enum (v1.8.x). Conflicts with PHP 8.1+ enums.
  • Laravel Services: Ensure no conflicts with Laravel’s service container (Doctrine uses its own DI).
  • Caching: Enum hydration may impact query caching (test with Doctrine’s cache drivers).

Sequencing

  1. Phase 1: Pilot with non-critical entities.
  2. Phase 2: Migrate high-value enums (e.g., UserRole, OrderStatus).
  3. Phase 3: Replace Eloquent queries with Doctrine equivalents.
  4. Phase 4: Deprecate old enum implementations (e.g., constants).
  5. Phase 5: Test with Doctrine ORM 3.x if applicable (add to QA pipeline).

Operational Impact

Maintenance

  • Dependency Management:
    • Monitor myclabs/php-enum for security updates (though inactive).
    • New: Verify compatibility with Doctrine ORM 3.x if upgrading.
    • Prepare for forking or switching to ramsey/uuid-style enums if issues arise.
  • Schema Changes:
    • Database migrations for enum additions/removals require downtime if not using zero-downtime ALTERs.
  • IDE Support:
    • Manual type hints may need updates if enum classes change.

Support

  • Debugging Complexity:
    • Doctrine errors (e.g., ClassMetadataInfoException) may be less intuitive than Eloquent’s.
    • Stack traces for enum hydration issues require familiarity with Doctrine’s lifecycle.
  • Community Resources:
    • Limited Laravel-specific docs; rely on Doctrine/Symfony resources.
  • Vendor Lock-in:
    • Custom enum types may complicate future migrations to other ORMs (e.g., back to Eloquent).

Scaling

  • Performance:
    • Enum hydration adds ~1–5ms per query (benchmark with doctrine/orm profiling).
    • Database ENUM types improve validation but may not index as efficiently as VARCHAR.
  • Horizontal Scaling:
    • No inherent issues, but ensure Doctrine’s connection pooling is configured.
  • Cold Starts:
    • Metadata compilation may impact first-request latency in serverless environments.

Failure Modes

Failure Scenario Impact Mitigation
Database ENUM value mismatch Query failures, data corruption Use VARCHAR + application validation
Doctrine metadata cache corruption Enum hydration fails Clear cache (php bin/console cache:clear)
PHP 8.1+
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.
bugban/php-sdk
littlerocket/job-queue-bundle
graham-campbell/flysystem
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/opensearch-client
directorytree/opensearch-adapter
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