mediagone/types-enums-doctrine

为 mediagone/types-enums 包提供 Doctrine 类型。

0.1.4 2022-02-14 16:12 UTC

This package is auto-updated.

Last update: 2024-09-14 21:54:45 UTC


README

Latest Version on Packagist Total Downloads Software License

为 "mediagone/types-enums" 包提供 Doctrine 类型。

安装

此包需要 PHP 7.4+ 和 Doctrine DBAL 2.7+

将其作为 Composer 依赖项添加

$ composer require mediagone/types-enums-doctrine

配置

此包提供了一个通用的 Doctrine 类型,以消除手动为每个枚举类创建自定义类型的需要。然后,您只需在 DoctrineEnumTypesLoader 类中注册您的枚举,自定义类型将自动为您创建和注册。

使用 Symfony

如果您在 Symfony 项目中使用此包,请在其应用程序的内核类中注册枚举类

use App\MyCustomEnum;
use App\MyOtherEnum;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    public function boot(): void
    {
        parent::boot();

        (new DoctrineEnumTypesLoader())->registerEnumTypes([
            MyCustomEnum::class,
            MyOtherEnum::class,
            // any other enum classes here
        ]);
    }

    ...
}

许可证

Doctrine 的类型枚举 根据 MIT 许可证授权。请参阅 LICENSE 文件。