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 e690da1

Browse filesBrowse files
committed
[DoctrineBridge] Optimize DoctrineChoiceLoader
1 parent 93e09fe commit e690da1
Copy full SHA for e690da1

File tree

Expand file treeCollapse file tree

2 files changed

+17
-9
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-9
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
+17-8Lines changed: 17 additions & 8 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;
@@ -60,20 +61,30 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
6061
* passed which optimizes the object loading for one of the Doctrine
6162
* mapper implementations.
6263
*
63-
* @param ChoiceListFactoryInterface $factory The factory for creating
64-
* the loaded choice list
6564
* @param ObjectManager $manager The object manager
6665
* @param string $class The class name of the
6766
* loaded objects
6867
* @param IdReader $idReader The reader for the object
6968
* IDs.
69+
* @param ChoiceListFactoryInterface $factory The factory for creating
70+
* the loaded choice list
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($manager, $class, $idReader = null, $objectLoader = null, $factory = null)
7374
{
75+
// BC to be removed in 4.0
76+
if ($manager instanceof ChoiceListFactoryInterface) {
77+
@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__));
78+
79+
// Provide a BC layer since $factory as changed form first to last argument as of 3.1
80+
$this->factory = $manager;
81+
$manager = $class;
82+
$class = $idReader;
83+
$objectLoader = $factory;
84+
}
85+
7486
$classMetadata = $manager->getClassMetadata($class);
7587

76-
$this->factory = $factory;
7788
$this->manager = $manager;
7889
$this->class = $classMetadata->getName();
7990
$this->idReader = $idReader ?: new IdReader($manager, $classMetadata);
@@ -93,9 +104,7 @@ public function loadChoiceList($value = null)
93104
? $this->objectLoader->getEntities()
94105
: $this->manager->getRepository($this->class)->findAll();
95106

96-
$this->choiceList = $this->factory->createListFromChoices($objects, $value);
97-
98-
return $this->choiceList;
107+
return $this->choiceList = new ArrayChoiceList($objects, $value);
99108
}
100109

101110
/**
@@ -146,7 +155,7 @@ public function loadChoicesForValues(array $values, $value = null)
146155

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

151160
if ($optimize && !$this->choiceList && $this->objectLoader && $this->idReader->isSingleId()) {
152161
$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
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public function configureOptions(OptionsResolver $resolver)
160160
}
161161

162162
$doctrineChoiceLoader = new DoctrineChoiceLoader(
163-
$this->choiceListFactory,
164163
$options['em'],
165164
$options['class'],
166165
$options['id_reader'],

0 commit comments

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