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 b474c39

Browse filesBrowse files
committed
[DoctrineBridge] Backport workaround for closures
1 parent a0e916b commit b474c39
Copy full SHA for b474c39

File tree

Expand file treeCollapse file tree

1 file changed

+12
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-3
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
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,27 @@ protected function doLoadChoicesForValues(array $values, ?callable $value): arra
9191
trigger_deprecation('symfony/doctrine-bridge', '5.1', 'Not defining explicitly the IdReader as value callback when query can be optimized is deprecated. Don\'t pass the IdReader to "%s" or define the "choice_value" option instead.', __CLASS__);
9292
}
9393

94+
$idReader = null;
95+
if (\is_array($value) && $value[0] instanceof IdReader) {
96+
$idReader = $value[0];
97+
} elseif ($value instanceof \Closure && ($rThis = (new \ReflectionFunction($value))->getClosureThis()) instanceof IdReader) {
98+
$idReader = $rThis;
99+
} elseif ($legacy) {
100+
$idReader = $this->idReader;
101+
}
102+
94103
// Optimize performance in case we have an object loader and
95104
// a single-field identifier
96-
if (($legacy || \is_array($value) && $this->idReader === $value[0]) && $this->objectLoader) {
105+
if ($idReader && $this->objectLoader) {
97106
$objects = [];
98107
$objectsById = [];
99108

100109
// Maintain order and indices from the given $values
101110
// An alternative approach to the following loop is to add the
102111
// "INDEX BY" clause to the Doctrine query in the loader,
103112
// but I'm not sure whether that's doable in a generic fashion.
104-
foreach ($this->objectLoader->getEntitiesByIds($this->idReader->getIdField(), $values) as $object) {
105-
$objectsById[$this->idReader->getIdValue($object)] = $object;
113+
foreach ($this->objectLoader->getEntitiesByIds($idReader->getIdField(), $values) as $object) {
114+
$objectsById[$idReader->getIdValue($object)] = $object;
106115
}
107116

108117
foreach ($values as $i => $id) {

0 commit comments

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