8000 fix #17993 - Deprecated callable strings · symfony/symfony@39e9859 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39e9859

Browse files
author
hamza
committed
fix #17993 - Deprecated callable strings
1 parent b868feb commit 39e9859

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public function createListFromChoices($choices, $value = null)
8686
{
8787
if (is_string($value) && !is_callable($value)) {
8888
$value = new PropertyPath($value);
89+
} elseif (is_string($value) && is_callable($value)) {
90+
@trigger_error('createListFromChoices() treats callable strings as callable and is deprecated since version 3.1.', E_USER_DEPRECATED);
91+
$value = function ($choice) use ($value) {
92+
return $value($choice);
93+
};
8994
}
9095

9196
if ($value instanceof PropertyPath) {
@@ -117,6 +122,11 @@ public function createListFromLoader(ChoiceLoaderInterface $loader, $value = nul
117122
{
118123
if (is_string($value) && !is_callable($value)) {
119124
$value = new PropertyPath($value);
125+
} elseif (is_string($value) && is_callable($value)) {
126+
@trigger_error('createListFromLoader() treats callable strings as callable and is deprecated since version 3.1.', E_USER_DEPRECATED);
127+
$value = function ($choice) use ($value) {
128+
return $value($choice);
129+
};
120130
}
121131

122132
if ($value instanceof PropertyPath) {
@@ -153,6 +163,12 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
153163

154164
if (is_string($label) && !is_callable($label)) {
155165
$label = new PropertyPath($label);
166+
} elseif (is_string($label) && is_callable($label)) {
167+
@trigger_error('createView() - $label - Treating strings as callable is deprecated since version 3.1 and will throw an error in 4.0. You should use a "\Closure" instead', E_USER_DEPRECATED);
168+
169+
$label = function ($choice) use ($label) {
170+
return $label($choice);
171+
};
156172
}
157173

158174
if ($label instanceof PropertyPath) {
@@ -163,6 +179,12 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
163179

164180
if (is_string($preferredChoices) && !is_callable($preferredChoices)) {
165181
$preferredChoices = new PropertyPath($preferredChoices);
182+
} elseif (is_string($preferredChoices) && is_callable($preferredChoices)) {
183+
@trigger_error('createView() - $preferredChoices - Treating strings as callable is deprecated since version 3.1 and will throw an error in 4.0. You should use a "\Closure" instead', E_USER_DEPRECATED);
184+
185+
$preferredChoices = function ($choice) use ($preferredChoices) {
186+
return $preferredChoices($choice);
187+
};
166188
}
167189

168190
if ($preferredChoices instanceof PropertyPath) {
@@ -178,6 +200,12 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
178200

179201
if (is_string($index) && !is_callable($index)) {
180202
$index = new PropertyPath($index);
203+
} elseif (is_string($index) && is_callable($index)) {
204+
@trigger_error('createView() - $index - Treating strings as callable is deprecated since version 3.1 and will throw an error in 4.0. You should use a "\Closure" instead', E_USER_DEPRECATED);
205+
206+
$index = function ($choice) use ($index) {
207+
return $index($choice);
208+
};
181209
}
182210

183211
if ($index instanceof PropertyPath) {
@@ -188,6 +216,12 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
188216

189217
if (is_string($groupBy) && !is_callable($groupBy)) {
190218
$groupBy = new PropertyPath($groupBy);
219+
} elseif (is_string($groupBy) && is_callable($groupBy)) {
220+
@trigger_error('createView() - $groupBy - Treating strings as callable is deprecated since version 3.1 and will throw an error in 4.0. You should use a "\Closure" instead', E_USER_DEPRECATED);
221+
222 9FB4 +
$groupBy = function ($choice) use ($groupBy) {
223+
return $groupBy($choice);
224+
};
191225
}
192226

193227
if ($groupBy instanceof PropertyPath) {
@@ -202,6 +236,12 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null,
202236

203237
if (is_string($attr) && !is_callable($attr)) {
204238
$attr = new PropertyPath($attr);
239+
} elseif (is_string($attr) && is_callable($attr)) {
240+
@trigger_error('createView() - $attr - Treating strings as callable is deprecated since version 3.1 and will throw an error in 4.0. You should use a "\Closure" instead', E_USER_DEPRECATED);
241+
242+
$attr = function ($choice) use ($attr) {
243+
return $attr($choice);
244+
};
205245
}
206246

207247
if ($attr instanceof PropertyPath) {

0 commit comments

Comments
 (0)
0