PHP code example of heymoon / doctrine-psql-enum

1. Go to this page and download the library: Download heymoon/doctrine-psql-enum 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/ */

    

heymoon / doctrine-psql-enum example snippets


use HeyMoon\DoctrinePostgresEnum\Attribute\EnumType;

#[EnumType('auth_status')]
enum AuthStatus: string
{
    case New = 'new';
    case Active = 'active';
    case Inactive = 'inactive';
    case Deleted = 'deleted';
}

#[EnumType('auth_service')]
enum Service: string
{
    case Google = 'google';
}

#[ORM\Entity(repositoryClass: AuthRepository::class)]
class Auth
{
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: "CUSTOM")]
    #[ORM\CustomIdGenerator(class: "doctrine.uuid_generator")]
    #[ORM\Column(type: 'uuid')]
    private Uuid $id;

    #[ORM\Column(type: 'enum', enumType: AuthStatus::class)]
    private AuthStatus $status;

    #[ORM\Column(type: 'enum', enumType: Service::class)]
    private Service $service;
}

$this->addSql('DROP TYPE IF EXISTS auth_status');
$this->addSql('CREATE TYPE auth_status AS ENUM (\'new\',\'active\',\'inactive\',\'deleted\')');
$this->addSql('DROP TYPE IF EXISTS auth_service');
$this->addSql('CREATE TYPE auth_service AS ENUM (\'google\')');
$this->addSql('CREATE TABLE auth (id UUID NOT NULL, status auth_status NOT NULL, service auth_service NOT NULL, PRIMARY KEY(id))');