Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/neutron-pro/doctrine-enum-php-type

Added a doctrine type for the php enumeration system designed to be as close as possible to PHP 8.1 for earlier versions.
https://github.com/neutron-pro/doctrine-enum-php-type

doctrine doctrine-orm php php-enum php7 php71 php72 php73 php74 php8 symfony

Last synced: 3 days ago
JSON representation

Added a doctrine type for the php enumeration system designed to be as close as possible to PHP 8.1 for earlier versions.

Awesome Lists containing this project

README

        

# Doctrine Enum PHP Type

---

## Read the enum php doc:

> https://github.com/Neutron-Pro/enum-php

---

## Installation

`composer require neutronstars/doctrine-enum-php-type`

---

## Doctrine Configuration

If you use it, you must create a Type class for your enum:

```php
namespace App\Types;

class MyEnumType extends \NeutronStars\Enum\Types\EnumType {
public const MY_ENUM = 'my_enum';

public function getName(): string
{
return self::MY_ENUM;
}

public function convertToPHPValue($value,\Doctrine\DBAL\Platforms\AbstractPlatform $platform): MyEnum
{
return MyEnum::from($value);
}
}
```

You must add this to the `doctrine.yaml` configuration file:

```yml
doctrine:
dbal:
types:
my_enum:
class: App\Types\MyEnumType
```

On the annotation that contains the field of your entity, you must put the type:

```php
/**
* @ORM\Column(type="my_enum")
* @var MyEnum|null
*/
private ?MyEnum $myEnum;
```

you must comment out the column that contains the enum during your sql migration:

```php
$this->addSql('COMMENT ON COLUMN "your_table"."your_column" IS \'(DC2Type:my_enum)\';');
```

---