Skip to content

Commit

Permalink
ORM3 and DBAL4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
michnovka committed Jan 5, 2024
1 parent 572f0d8 commit 9a6e4be
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 65 deletions.
24 changes: 4 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,22 @@ jobs:
#

# Most recent versions
- name: 'Test Symfony 5.4 [Linux, PHP 8.1]'
- name: 'Test Symfony 6.4 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
symfony: '5.4.*@dev'
symfony: '6.4.*@dev'
allow-unstable: true
mongodb: true
mysql: true

- name: 'Test Symfony 5.4 [Windows, PHP 8.1]'
- name: 'Test Symfony 6.4 [Windows, PHP 8.1]'
os: 'windows-latest'
php: '8.1'
symfony: '5.4.*@dev'
mongodb: true
mysql: true
allow-unstable: true

- name: 'Test Symfony 6.3 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
symfony: '6.3.*@dev'
symfony: '6.4.*@dev'
mongodb: true
mysql: true
allow-unstable: true

- name: 'Test Symfony 6.4 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
symfony: '6.4.*@dev'
allow-unstable: true
mysql: true
mongodb: true

- name: 'Test Symfony 7.0 [Linux, PHP 8.2]'
os: 'ubuntu-latest'
php: '8.2'
Expand Down
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@
"require-dev": {
"ext-pdo_sqlite": "*",
"composer/semver": "^3.2",
"doctrine/dbal": "^3.2",
"doctrine/doctrine-bundle": "^2.5",
"doctrine/orm": "^2.10",
"doctrine/dbal": "^4.0",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/orm": "^3.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-symfony": "^1.2",
"symfony/browser-kit": "^5.4|^6.3|^7.0",
"symfony/config": "^5.4|^6.3|^7.0",
"symfony/dependency-injection": "^5.4.2|^6.3|^7.0",
"symfony/filesystem": "^5.4|^6.3|^7.0",
"symfony/form": "^5.4|^6.3|^7.0",
"symfony/framework-bundle": "^5.4|^6.3|^7.0",
"symfony/http-kernel": "^5.4.2|^6.3|^7.0",
"symfony/phpunit-bridge": "^5.4|^6.3|^7.0",
"symfony/translation": "^5.4|^6.3|^7.0",
"symfony/var-dumper": "^5.4|^6.3|^7.0",
"symfony/yaml": "^5.4|^6.3|^7.0"
"phpstan/phpstan-symfony": "^1.3",
"symfony/browser-kit": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/filesystem": "^6.4|^7.0",
"symfony/form": "^6.4|^7.0",
"symfony/framework-bundle": "^6.4|^7.0",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/phpunit-bridge": "^6.4|^7.0",
"symfony/translation": "^6.4|^7.0",
"symfony/var-dumper": "^6.4|^7.0",
"symfony/yaml": "^6.4|^7.0"
},
"extra": {
"branch-alias": {
Expand Down
13 changes: 3 additions & 10 deletions src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

namespace Elao\Enum\Bridge\Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Elao\Enum\Exception\LogicException;
Expand All @@ -25,16 +24,10 @@ abstract class AbstractEnumSQLDeclarationType extends AbstractEnumType
/**
* {@inheritdoc}
*/
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
if (class_exists(AbstractMySQLPlatform::class)) {
if (!$platform instanceof AbstractMySQLPlatform) {
throw new LogicException('SQL ENUM type is not supported on the current platform');
}
} elseif (class_exists(MySQLPlatform::class)) {
if (!$platform instanceof MySQLPlatform) {
throw new LogicException('SQL ENUM type is not supported on the current platform');
}
if (!$platform instanceof MySQLPlatform) {
throw new LogicException('SQL ENUM type is not supported on the current platform');
}

$values = array_map(
Expand Down
14 changes: 2 additions & 12 deletions src/Bridge/Doctrine/DBAL/Types/AbstractEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,13 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st
$column['length'] = 255;
}

return method_exists($platform, 'getStringTypeDeclarationSQL') ?
$platform->getStringTypeDeclarationSQL($column) :
$platform->getVarcharTypeDeclarationSQL($column);
return $platform->getStringTypeDeclarationSQL($column);
}

/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function getBindingType(): int
public function getBindingType(): ParameterType
{
return $this->isIntBackedEnum() ? ParameterType::INTEGER : ParameterType::STRING;
}
Expand Down
13 changes: 5 additions & 8 deletions src/Bridge/Doctrine/DBAL/Types/AbstractFlagBagType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
namespace Elao\Enum\Bridge\Doctrine\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\IntegerType;
use Doctrine\DBAL\Types\Type;
use Elao\Enum\Exception\InvalidArgumentException;
use Elao\Enum\FlagBag;

abstract class AbstractFlagBagType extends IntegerType
abstract class AbstractFlagBagType extends Type
{
/**
* The enum FQCN for which we should make the DBAL conversion.
Expand Down Expand Up @@ -73,7 +73,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?int
*
* @return FlagBag<\BackedEnum>|null
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
public function convertToPHPValue($value, AbstractPlatform $platform): ?FlagBag
{
$value = parent::convertToPHPValue($value, $platform);

Expand All @@ -84,12 +84,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
return new FlagBag($this->getEnumClass(), $value);
}

/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform): bool
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
{
return true;
return $platform->getIntegerTypeDeclarationSQL($column);
}

public function getName(): string
Expand Down

0 comments on commit 9a6e4be

Please sign in to comment.