This library provides support to PHP Enums, introduced in PHP 8.1, within your Doctrine entities.
This means that this bundle will soon or later be discontinued. Please upgrade your dependencies!
composer require bentools/doctrine-native-enums
This library only works with Backed enums.
// config/bundles.php
return [
// ...
BenTools\Doctrine\NativeEnums\Bundle\DoctrineNativeEnumsBundle::class => ['all' => true],
];
# config/packages/doctrine_native_enums.yaml
doctrine_native_enums:
enum_types:
App\Entity\StatusEnum: ~
#App\Entity\StatusEnum: status # Alternatively, if you want your type to be named "status"
declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
final class Book
{
#[
ORM\Id,
ORM\Column(unique: true),
ORM\GeneratedValue(strategy: 'AUTO'),
]
public int $id;
#[ORM\Column]
public string $name;
#[ORM\Column(type: StatusEnum::class)]
public StatusEnum $status;
}
use App\Entity\StatusEnum;
use BenTools\Doctrine\NativeEnums\Type\NativeEnum;
use Doctrine\DBAL\Types\Type;
NativeEnum::registerEnumType(StatusEnum::class);
// NativeEnum::registerEnumType('status', StatusEnum::class); // Alternatively, if you want your type to be named "status"
php vendor/bin/pest
MIT.