PHP code example of vkollin / doctrine-backed-enum-fields-bundle

1. Go to this page and download the library: Download vkollin/doctrine-backed-enum-fields-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vkollin / doctrine-backed-enum-fields-bundle example snippets


// config/bundles.php

return [
    // ...
    VKollin\Doctrine\BackedEnumFields\Bundle\DoctrineBackedEnumFieldsBundle::class => ['all' => true],
];

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;
}

#[ORM\Column(name: 'type', type: StatusEnum::class, nullable: false)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(EnumIdGenerator::class)]
#[ORM\Id]
private 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"