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 Bundle Laravel Package

fresh/doctrine-enum-bundle

Symfony bundle adding ENUM type support to Doctrine ORM/DBAL. Register custom enum types and map them to entity fields for safer, consistent values across databases. Works with modern Symfony/Doctrine versions and common platforms like PostgreSQL, MySQL, SQLite, and MSSQL.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Domain-Driven Design (DDD) Alignment: Enables strict enum types for business entities (e.g., OrderStatus, PaymentMethod), reducing ambiguity in domain logic and improving collaboration between developers and stakeholders. Aligns with ubiquitous language by enforcing valid states at the database and application layers.
  • Scalable Feature Flags: Simplifies implementation of feature toggles or configuration flags (e.g., NotificationChannel::EMAIL | NotificationChannel::PUSH) with type safety and database constraints.
  • State Machine Patterns: Accelerates development of workflow-driven features (e.g., order processing, approval pipelines) by replacing manual state validation with enum-backed transitions.
  • Build vs. Buy Decision: Buy—avoids reinventing enum handling (validation, migrations, templating) while maintaining consistency with Doctrine’s ecosystem. Custom implementation would require ~100+ hours of development, testing, and maintenance, with higher long-term risk.
  • Roadmap for Modern PHP/Symfony: Future-proofs the stack by supporting Symfony 8.x/9.x, PHP 8.4+, and Doctrine ORM 3.x, reducing migration friction for upcoming upgrades.
  • Performance-Critical Features: Optimizes database queries for enum fields (e.g., WHERE status = 'PENDING') by leveraging native ENUM types, which are index-friendly and storage-efficient.
  • Audit and Compliance: Facilitates immutable logging of state changes (e.g., UserRole::GUEST → UserRole::ADMIN) for compliance and debugging, with built-in support for Doctrine migrations.

When to Consider This Package

Adopt if:

  • Your application uses Symfony + Doctrine ORM (PHP 8.2+, Symfony 6.4+) and requires strongly typed enums with database-level constraints.
  • You prioritize type safety over flexibility (e.g., replacing strings/integers like '1' for 'active' with UserStatus::ACTIVE).
  • Your team values maintainability and reduced technical debt over custom solutions (e.g., avoiding manual validation or switch statements).
  • You need seamless integration with Symfony Forms, Twig templating, and Doctrine migrations without reinventing the wheel.
  • Your database supports ENUM types (PostgreSQL, MySQL, SQLite; MSSQL via custom types) and you want to leverage them for performance.
  • You’re building stateful features (e.g., orders, subscriptions, workflows) where invalid states must be prevented at the database level.
  • Your roadmap includes Symfony 8.x/9.x or PHP 8.4+, and you want to avoid migration pain.

Look Elsewhere if:

  • You’re not using Symfony/Doctrine (e.g., Laravel, raw PHP, or other ORMs like Eloquent). Consider native Laravel enums or custom solutions.
  • Your enums are dynamic or user-defined (e.g., configurable options). Use a jsonb/json column or a separate lookup table instead.
  • You need multi-language enum labels. This bundle lacks i18n support; pair it with a translation service (e.g., Symfony’s Trans component).
  • Your team lacks PHP/Symfony expertise, as the learning curve for Doctrine attributes and ENUM types may be steep.
  • You’re on legacy PHP (<8.2) or Symfony <6.4. Use an older bundle version or migrate first.
  • You require advanced enum features like inheritance, computed values, or complex validation logic. This bundle focuses on simplicity and Doctrine integration.
  • Your database does not support ENUM types (e.g., Oracle, older SQL Server versions). Use integers or strings with application-level validation instead.

How to Pitch It (Stakeholders)

For Executives/Stakeholders:

*"This package lets us eliminate bugs caused by invalid state values (e.g., 'active' vs. 1 for user status) by enforcing type-safe enums in our Symfony backend. For example:

  • Fewer production incidents: Invalid states (e.g., order_status = 'invalid') are caught at the database level, not in runtime errors.
  • Faster development: No more writing manual validation logic or switch statements for state transitions—just annotate your entities and go.
  • Future-proof: Supports Symfony 8.x and PHP 8.4+, so we won’t face migration headaches later.
  • Cost-effective: Avoids reinventing enum handling (which would take ~100+ hours of dev effort) while leveraging a battle-tested, community-backed solution.

Use Cases:

  • E-commerce: Strict OrderStatus (e.g., PENDING, SHIPPED, CANCELLED) with database constraints.
  • Subscriptions: PaymentMethod enums (e.g., CREDIT_CARD, PAYPAL) for feature flags.
  • Audit trails: Immutable logs of state changes (e.g., UserRole::GUEST → UserRole::ADMIN).

Risk: Minimal—MIT-licensed, 462+ stars, and used in production by other teams. We can pilot it with a single entity (e.g., UserRole) before full adoption."*


For Engineers/Developers:

*"DoctrineEnumBundle gives us native ENUM support in Doctrine/Symfony with zero trade-offs for our stack: ✅ What You Get:

  • Database constraints: ENUM columns enforce valid values (e.g., ORDER_STATUS can’t be 'invalid').
  • Type safety: PHP enums + Doctrine attributes replace strings/integers, reducing runtime errors.
  • Seamless integration:
    • Works with Doctrine migrations (no manual SQL).
    • Symfony Forms: Auto-generates dropdowns for enums (e.g., select2 with UserStatus::values()).
    • Twig templating: Access enum labels/values without magic strings (e.g., {% if order.status == App\Enum\OrderStatus::SHIPPED %}).
  • Modern PHP/Symfony: Supports PHP 8.4+, Symfony 8.0, and Doctrine ORM 3.x.

🔧 How to Adopt:

  1. Spike: Test with one entity (e.g., UserRole) to validate migrations, forms, and Twig workflows.
  2. Phase in: Use for new features; avoid retrofitting legacy entities unless critical.
  3. Monitor: Check DB performance (ENUM types are efficient but may limit future flexibility).

⚠️ Caveats:

  • Symfony/Doctrine only: Not a drop-in for Laravel or raw PHP.
  • Templating relies on constants: Use App\Enum\Status::ACTIVE in Twig, not strings.
  • No i18n: Labels are hardcoded; pair with Symfony’s Trans component if needed.

Example Migration:

// Before: Manual validation + strings
$order->setStatus('shipped'); // Risk of typos!

// After: Type-safe + database constraint
$order->setStatus(OrderStatus::SHIPPED); // Caught at compile time.

Next Steps:

  • Add to composer.json (fresh/doctrine-enum-bundle).
  • Update config/bundles.php (Symfony Flex handles this by default).
  • Pilot with a high-impact entity (e.g., Order)."*
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor