Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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.
- Host: GitHub
- URL: https://github.com/neutron-pro/doctrine-enum-php-type
- Owner: Neutron-Pro
- License: apache-2.0
- Created: 2021-07-08T20:33:04.000Z (over 3 years ago)
- Default Branch: develop
- Last Pushed: 2021-07-09T21:06:02.000Z (over 3 years ago)
- Last Synced: 2024-10-12T12:22:00.255Z (about 1 month ago)
- Topics: doctrine, doctrine-orm, php, php-enum, php7, php71, php72, php73, php74, php8, symfony
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
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)\';');
```---