定制 josuealcalde-utamed/doctrine-enums-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

josuealcalde-utamed/doctrine-enums-bundle

Composer 安装命令:

composer require josuealcalde-utamed/doctrine-enums-bundle

包简介

Bundle for Doctrine enumerations extension for Postgres

README 文档

README

Symfony bundle for Doctrine enums extension.

Requirements

Minimum PHP version is 8.1.

Installation

composer require enumeum/doctrine-enums-bundle

Bundle registration

If Symfony did not add bundle into ./config/bundles.php then do it manually.

<?php

return [
    // ...
    Enumeum\DoctrineEnumBundle\DoctrineEnumBundle::class => ['all' => true],
];

Setup

Create doctrine_enum.yaml file under Symfony config folder. For single default connection setup is pretty easy

doctrine_enum:
  types:
    - App\EnumType\StatusType
    - App\EnumType\AnotherStatusType
  paths:
    - dir: '%kernel.project_dir%/src/EnumFolder/One'
      namespace: App\EnumFolder\One
    - dir: '%kernel.project_dir%/src/EnumFolder/Two'
      namespace: App\EnumFolder\Two

For multiple named connections config also supports them. Connections naming should be similar to Doctrine.

doctrine_enum:
  connections:
    first:
      types:
        - App\EnumType\AnotherStatusType
      paths:
        - dir: '%kernel.project_dir%/src/EnumFolder/One'
          namespace: App\EnumFolder\One
    second:
      types:
        - App\EnumType\StatusType
      paths:
        - dir: '%kernel.project_dir%/src/EnumFolder/Two'
          namespace: App\EnumFolder\Two

Types and Entities

Enumeum attribute for PHP enum:

  • #[Enumeum\DoctrineEnum\Attribute\EnumType(name: 'type_name')] this attribute tells that this enum is database type. By default, it creates type in database with its own cases.

Enum setup

<?php
namespace App\Enums;

use Enumeum\DoctrineEnum\Attribute\EnumType;

#[EnumType(name: 'status_type')]
enum StatusType: string
{
    case STARTED = 'started';
    case PROCESSING = 'processing';
    case FINISHED = 'finished';
}

Entity setup

Please note that the configuration of the entity is no different from the usual one. Doctrine supports "enumType" property and converts it transparently.

<?php
namespace App\Entities;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Enum\StatusType;

/**
 * @ORM\Entity
 * @ORM\Table(name="entity")
 */
#[ORM\Entity]
#[ORM\Table(name: 'entity')]
class Entity
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     */
    #[ORM\Id]
    #[ORM\Column(type: Types::INTEGER)]
    private int $id;

    /**
     * @ORM\Column(type="string", enumType=StatusType::class, options={"comment":"Comment"})
     */
    #[ORM\Column(type: Types::STRING, enumType: StatusType::class, options: ['comment' => 'Comment'])]
    private StatusType $status;

    public function __construct(
        int $id,
        StatusType $status,
    ) {
        $this->id = $id;
        $this->status = $status;
    }

    public function getId(): int
    {
        return $this->id;
    }

    public function getStatus(): StatusType
    {
        return $this->status;
    }
}

Commands

In order to automate enums management bundle provides some commands.

Diff

Diff command will create migration file using Doctrine Migrations bundle config.

./bin/console enumeum:migrations:diff

List of options is generally similar to Doctrine's doctrine:migrations:diff command, except one additional option. "-U" allows to ignore enums already existing in database, otherwise diff command will try to drop them.

Schema validate

Schema validate command will check whether database enums are in sync with their definitions in application.

./bin/console enumeum:schema:validate

This command has optional "--em" and "--conn" options for those cases when application has different from "default" configuration.
Option "-U" allows to ignore enums already existing in database.

Integration with Doctrine's commands

Bundle also allows to use Enumeum commands with appropriate Doctrine's commands to perform better usability.

enumeum:migrations:diff -> doctrine:migrations:diff
enumeum:schema:validate -> doctrine:schema:validate

This is provided by Doctrine's commands overriding using commands decoration. Every Doctrine's command has additional option "-E" which allows to run Enumeum command before the general. Commands decoration is enabled by default and can be disabled by following configuration:

doctrine_enum:
  doctrine:
    commands_decoration: false

josuealcalde-utamed/doctrine-enums-bundle 适用场景与选型建议

josuealcalde-utamed/doctrine-enums-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.87k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「extensions」 「doctrine」 「postgres」 「enum」 「enumeration」 「enumeum」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 josuealcalde-utamed/doctrine-enums-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 josuealcalde-utamed/doctrine-enums-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 josuealcalde-utamed/doctrine-enums-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.87k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-11