Skip to content

Commit

Permalink
minor #3227 Require Doctrine DBAL 2.10 (javiereguiluz)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.0.x-dev branch.

Discussion
----------

Require Doctrine DBAL 2.10

Inspired by symfony/symfony#36790. I think this doesn't introduced any issue in this bundle and we can get rid of some deprecations.

Commits
-------

43a1fcc Require Doctrine DBAL 2.10
  • Loading branch information
javiereguiluz committed May 16, 2020
2 parents 865c303 + 43a1fcc commit bc2db6f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 39 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"php": "^7.2.5",
"ext-json": "*",
"doctrine/common": "^2.8",
"doctrine/dbal": "^2.10",
"doctrine/doctrine-bundle": "^1.8|^2.0",
"doctrine/orm": "^2.6,>=2.6.3",
"doctrine/persistence": "^1.0",
Expand Down Expand Up @@ -44,6 +45,9 @@
"symfony/dom-crawler": "^4.4|^5.0",
"symfony/phpunit-bridge": "^4.4|^5.0"
},
"conflict": {
"doctrine/dbal": "<2.10"
},
"config": {
"sort-packages": true
},
Expand Down
7 changes: 3 additions & 4 deletions src/Factory/FieldFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace EasyCorp\Bundle\EasyAdminBundle\Factory;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
Expand All @@ -26,9 +26,8 @@
*/
final class FieldFactory
{
// TODO: update this map when ArrayField is implemented
private static $doctrineTypeToFieldFqcn = [
//Type::TARRAY => 'array',
Types::ARRAY => ArrayField::class,
Types::BIGINT => TextField::class,
Types::BINARY => TextareaField::class,
Types::BLOB => TextareaField::class,
Expand All @@ -46,7 +45,7 @@ final class FieldFactory
Types::INTEGER => IntegerField::class,
Types::JSON => TextField::class,
Types::OBJECT => TextField::class,
//Types::SIMPLE_ARRAY => 'array',
Types::SIMPLE_ARRAY => ArrayField::class,
Types::SMALLINT => IntegerField::class,
Types::STRING => TextField::class,
Types::TEXT => TextareaField::class,
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/ArrayFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EasyCorp\Bundle\EasyAdminBundle\Filter;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr\Orx;
use Doctrine\ORM\QueryBuilder;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterInterface;
Expand Down Expand Up @@ -38,7 +38,7 @@ public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto,
$parameterName = $filterDataDto->getParameterName();
$value = $filterDataDto->getValue();

$useQuotes = Type::SIMPLE_ARRAY === $fieldDto->getDoctrineMetadata()->get('type');
$useQuotes = Types::SIMPLE_ARRAY === $fieldDto->getDoctrineMetadata()->get('type');

if (null === $value || [] === $value) {
$queryBuilder->andWhere(sprintf('%s.%s %s', $alias, $property, $comparison));
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/Configurator/ComparisonConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EasyCorp\Bundle\EasyAdminBundle\Filter\Configurator;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
Expand All @@ -26,7 +26,7 @@ public function configure(FilterDto $filterDto, ?FieldDto $fieldDto, EntityDto $
{
$propertyType = $entityDto->getPropertyMetadata($filterDto->getProperty())->get('type');

if (Type::DATEINTERVAL === $propertyType) {
if (Types::DATEINTERVAL === $propertyType) {
$filterDto->setFormTypeOption('value_type', DateIntervalType::class);
$filterDto->setFormTypeOption('comparison_type_options.type', 'datetime');
}
Expand Down
12 changes: 6 additions & 6 deletions src/Filter/Configurator/DateTimeConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EasyCorp\Bundle\EasyAdminBundle\Filter\Configurator;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
Expand All @@ -27,25 +27,25 @@ public function configure(FilterDto $filterDto, ?FieldDto $fieldDto, EntityDto $
{
$propertyType = $entityDto->getPropertyMetadata($filterDto->getProperty())->get('type');

if (Type::DATE === $propertyType) {
if (Types::DATE_MUTABLE === $propertyType) {
$filterDto->setFormTypeOptionIfNotSet('value_type', DateType::class);
}

if (Type::DATE_IMMUTABLE === $propertyType) {
if (Types::DATE_IMMUTABLE === $propertyType) {
$filterDto->setFormTypeOptionIfNotSet('value_type', DateType::class);
$filterDto->setFormTypeOptionIfNotSet('value_type_options.input', 'datetime_immutable');
}

if (Type::TIME === $propertyType) {
if (Types::TIME_MUTABLE === $propertyType) {
$filterDto->setFormTypeOptionIfNotSet('value_type', TimeType::class);
}

if (Type::TIME_IMMUTABLE === $propertyType) {
if (Types::TIME_IMMUTABLE === $propertyType) {
$filterDto->setFormTypeOptionIfNotSet('value_type', TimeType::class);
$filterDto->setFormTypeOptionIfNotSet('value_type_options.input', 'datetime_immutable');
}

if (\in_array($propertyType, [Type::DATETIME_IMMUTABLE, Type::DATETIMETZ_IMMUTABLE], true)) {
if (\in_array($propertyType, [Types::DATETIME_IMMUTABLE, Types::DATETIMETZ_IMMUTABLE], true)) {
$filterDto->setFormTypeOptionIfNotSet('value_type_options.input', 'datetime_immutable');
}
}
Expand Down
52 changes: 27 additions & 25 deletions src/Maker/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace EasyCorp\Bundle\EasyAdminBundle\Maker;

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
Expand Down Expand Up @@ -436,30 +436,32 @@ private function guessFieldFqcnForProperty(array $fieldConfig): string
];

$doctrineTypeToFqcn = [
Type::TARRAY => ArrayField::class,
Type::BIGINT => TextField::class,
Type::BINARY => TextareaField::class,
Type::BLOB => TextareaField::class,
Type::BOOLEAN => BooleanField::class,
Type::DATE => DateField::class,
Type::DATE_IMMUTABLE => DateField::class,
Type::DATEINTERVAL => TextField::class,
Type::DATETIME => DateTimeField::class,
Type::DATETIME_IMMUTABLE => DateTimeField::class,
Type::DATETIMETZ => DateTimeField::class,
Type::DATETIMETZ_IMMUTABLE => DateTimeField::class,
Type::DECIMAL => NumberField::class,
Type::FLOAT => NumberField::class,
Type::GUID => TextField::class,
Type::INTEGER => IntegerField::class,
Type::JSON => TextField::class,
Type::OBJECT => TextField::class,
Type::SIMPLE_ARRAY => ArrayField::class,
Type::SMALLINT => IntegerField::class,
Type::STRING => TextField::class,
Type::TEXT => TextareaField::class,
Type::TIME => TimeField::class,
Type::TIME_IMMUTABLE => TimeField::class,
Types::ARRAY => ArrayField::class,
Types::BIGINT => TextField::class,
Types::BINARY => TextareaField::class,
Types::BLOB => TextareaField::class,
Types::BOOLEAN => BooleanField::class,
Types::DATE_MUTABLE => DateField::class,
Types::DATE_IMMUTABLE => DateField::class,
Types::DATEINTERVAL => TextField::class,
Types::DATETIME_MUTABLE => DateTimeField::class,
Types::DATETIME_IMMUTABLE => DateTimeField::class,
Types::DATETIMETZ_MUTABLE => DateTimeField::class,
Types::DATETIMETZ_IMMUTABLE => DateTimeField::class,
Types::DECIMAL => NumberField::class,
Types::FLOAT => NumberField::class,
Types::GUID => TextField::class,
Types::INTEGER => IntegerField::class,
Types::JSON => TextField::class,
// 'json_array' is now deprecated in favor of Types::JSON
'json_array' => TextField::class,
Types::OBJECT => TextField::class,
Types::SIMPLE_ARRAY => ArrayField::class,
Types::SMALLINT => IntegerField::class,
Types::STRING => TextField::class,
Types::TEXT => TextareaField::class,
Types::TIME_MUTABLE => TimeField::class,
Types::TIME_IMMUTABLE => TimeField::class,
];

return $fieldTypeToFqcn[$fieldType] ?? $doctrineTypeToFqcn[$doctrineDataType] ?? Field::class;
Expand Down

0 comments on commit bc2db6f

Please sign in to comment.