Skip to content

Commit 3f879f0

Browse files
Neutron-ProNeutron-Pro
authored andcommitted
Initialize project
0 parents  commit 3f879f0

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
vendor/
3+
composer.lock

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "neutronstars/dotrine-enum-php-type",
3+
"description": "Added an enumeration system as close as possible to PHP 8.1 for earlier versions.",
4+
"type": "library",
5+
"license": [ "Apache-2.0" ],
6+
"authors": [
7+
{
8+
"name": "NeutronStars",
9+
"email": "pro@neutronstars.fr"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"NeutronStars\\Doctrine\\Enum\\Type\\": "src/"
15+
}
16+
},
17+
"minimum-stability": "stable",
18+
"require": {
19+
"php": "^7.1 | ^8.0",
20+
"doctrine/dbal": "^2.1",
21+
"neutronstars/enum": "^1.4"
22+
}
23+
}

src/EnumType.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NeutronStars\Doctrine\Enum\Type;
6+
7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
use Doctrine\DBAL\Types\Type;
9+
use Doctrine\DBAL\Types\Types;
10+
use NeutronStars\Enum\Enum;
11+
12+
abstract class EnumType extends Type
13+
{
14+
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
15+
{
16+
return Types::STRING;
17+
}
18+
19+
public function convertToDatabaseValue($value, AbstractPlatform $platform): ?string
20+
{
21+
return ($value instanceof Enum) ? (string) $value : null;
22+
}
23+
}

0 commit comments

Comments
 (0)