Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d082b38

Browse filesBrowse files
committed
[DoctrineBridge] Optimize DoctrineChoiceLoader
1 parent 2946932 commit d082b38
Copy full SHA for d082b38

File tree

2 files changed

+10
-7
lines changed
Filter options

2 files changed

+10
-7
lines changed

‎src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php
+9-6Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
1313

1414
use Doctrine\Common\Persistence\ObjectManager;
15+
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
1516
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
1617
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
1718
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
@@ -69,15 +70,19 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
6970
* IDs.
7071
* @param null|EntityLoaderInterface $objectLoader The objects loader
7172
*/
72-
public function __construct(ChoiceListFactoryInterface $factory, ObjectManager $manager, $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
73+
public function __construct(ChoiceListFactoryInterface $factory = null, ObjectManager $manager, $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
7374
{
7475
$classMetadata = $manager->getClassMetadata($class);
7576

76-
$this->factory = $factory;
7777
$this->manager = $manager;
7878
$this->class = $classMetadata->getName();
7979
$this->idReader = $idReader ?: new IdReader($manager, $classMetadata);
8080
$this->objectLoader = $objectLoader;
81+
82+
if (null !== $this->factory) {
83+
@trigger_error(sprintf('Passing a ChoiceListFactoryInterface to %s is deprecated since version 3.1 and will no longer be supported in 4.0. You should either call "%s::loadChoiceList" or override it to return a ChoiceListInterface.', __CLASS__, __CLASS__));
84+
$this->factory = $factory;
85+
}
8186
}
8287

8388
/**
@@ -93,9 +98,7 @@ public function loadChoiceList($value = null)
9398
? $this->objectLoader->getEntities()
9499
: $this->manager->getRepository($this->class)->findAll();
95100

96-
$this->choiceList = $this->factory->createListFromChoices($objects, $value);
97-
98-
return $this->choiceList;
101+
return $this->choiceList = new ArrayChoiceList($objects, $value);
99102
}
100103

101104
/**
@@ -146,7 +149,7 @@ public function loadChoicesForValues(array $values, $value = null)
146149

147150
// Optimize performance in case we have an object loader and
148151
// a single-field identifier
149-
$optimize = null === $value || is_array($value) && $value[0] === $this->idReader;
152+
$optimize = is_array($value) && $this->idReader && $value[0];
150153

151154
if ($optimize && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
152155
$unorderedObjects = $this->objectLoader->getEntitiesByIds($this->idReader->getIdField(), $values);

‎src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function configureOptions(OptionsResolver $resolver)
160160
}
161161

162162
$doctrineChoiceLoader = new DoctrineChoiceLoader(
163-
$this->choiceListFactory,
163+
null, // Passing a {@link ChoiceListFactory} instance is deprecated as of 3.1
164164
$options['em'],
165165
$options['class'],
166166
$options['id_reader'],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.