From 07d90f987ed064da501b974d5f2af38709ed5237 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 6 Apr 2019 19:22:14 +0200 Subject: [PATCH] Move doctrine/collections to an optional dep in doctrine-bridge The EntityType does not need to convert the array to a collection if the project does not care about using doctrine/collections. So this can become an optional dependency. --- src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php | 3 ++- src/Symfony/Bridge/Doctrine/composer.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php index 327e7abb05..cd3534d512 100644 --- a/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php +++ b/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php @@ -11,6 +11,7 @@ namespace Symfony\Bridge\Doctrine\Form\Type; +use Doctrine\Common\Collections\Collection; use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader; @@ -107,7 +108,7 @@ abstract class DoctrineType extends AbstractType implements ResetInterface public function buildForm(FormBuilderInterface $builder, array $options) { - if ($options['multiple']) { + if ($options['multiple'] && interface_exists(Collection::class)) { $builder ->addEventSubscriber(new MergeDoctrineCollectionListener()) ->addViewTransformer(new CollectionToArrayTransformer(), true) diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 849d2069ad..819af85220 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -17,7 +17,6 @@ ], "require": { "php": "^7.1.3", - "doctrine/collections": "~1.0", "doctrine/event-manager": "~1.0", "doctrine/persistence": "~1.0", "symfony/contracts": "^1.0", @@ -39,6 +38,7 @@ "symfony/translation": "~3.4|~4.0", "doctrine/annotations": "~1.0", "doctrine/cache": "~1.6", + "doctrine/collections": "~1.0", "doctrine/data-fixtures": "1.0.*", "doctrine/dbal": "~2.4", "doctrine/orm": "^2.4.5",