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 a4c5edc

Browse filesBrowse files
committed
Merge branch '5.2' into 5.x
* 5.2: [Workflow] Re-add InvalidTokenConfigurationException for BC Fix PHP 8.1 null values [Console] Fix PHP 8.1 null error for preg_match flag Fix: Article Definition::removeMethodCall should remove all matching calls [HttpFoundation] Fix typo in exception message mark the LazyIterator class as internal fix extracting mixed type-hinted property types [Worflow] Fixed GuardListener when using the new Security system keep valid submitted choices when additional choices are submitted
2 parents 1b94d88 + 4365af6 commit a4c5edc
Copy full SHA for a4c5edc

File tree

37 files changed

+152
-75
lines changed
Filter options

37 files changed

+152
-75
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
14721472
->info('A network interface name, IP address, a host name or a UNIX socket to bind to.')
14731473
->end()
14741474
->booleanNode('verify_peer')
1475-
->info('Indicates if the peer should be verified in a SSL/TLS context.')
1475+
->info('Indicates if the peer should be verified in an SSL/TLS context.')
14761476
->end()
14771477
->booleanNode('verify_host')
14781478
->info('Indicates if the host should exist as a certificate common name.')
@@ -1615,7 +1615,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
16151615
->info('A network interface name, IP address, a host name or a UNIX socket to bind to.')
16161616
->end()
16171617
->booleanNode('verify_peer')
1618-
->info('Indicates if the peer should be verified in a SSL/TLS context.')
1618+
->info('Indicates if the peer should be verified in an SSL/TLS context.')
16191619
->end()
16201620
->booleanNode('verify_host')
16211621
->info('Indicates if the host should exist as a certificate common name.')

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/form.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/form.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@
9797
->tag('form.type')
9898

9999
->set('form.type.choice', ChoiceType::class)
100-
->args([service('form.choice_list_factory')])
100+
->args([
101+
service('form.choice_list_factory'),
102+
service('translator')->ignoreOnInvalid(),
103+
])
101104
->tag('form.type')
102105

103106
->set('form.type.file', FileType::class)

‎src/Symfony/Component/BrowserKit/AbstractBrowser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/BrowserKit/AbstractBrowser.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public function submit(Form $form, array $values = [], array $serverParameters =
329329
* @param string $button The text content, id, value or name of the form <button> or <input type="submit">
330330
* @param array $fieldValues Use this syntax: ['my_form[name]' => '...', 'my_form[email]' => '...']
331331
* @param string $method The HTTP method used to submit the form
332-
* @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include a HTTP_ prefix as PHP does)
332+
* @param array $serverParameters These values override the ones stored in $_SERVER (HTTP headers must include an HTTP_ prefix as PHP does)
333333
*/
334334
public function submitForm(string $button, array $fieldValues = [], string $method = 'POST', array $serverParameters = []): Crawler
335335
{
@@ -350,7 +350,7 @@ public function submitForm(string $button, array $fieldValues = [], string $meth
350350
* @param string $uri The URI to fetch
351351
* @param array $parameters The Request parameters
352352
* @param array $files The files
353-
* @param array $server The server parameters (HTTP headers are referenced with a HTTP_ prefix as PHP does)
353+
* @param array $server The server parameters (HTTP headers are referenced with an HTTP_ prefix as PHP does)
354354
* @param string $content The raw body data
355355
* @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload())
356356
*

‎src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Config\Definition\PrototypedArrayNode;
1919

2020
/**
21-
* Dumps a XML reference configuration for the given configuration/node instance.
21+
* Dumps an XML reference configuration for the given configuration/node instance.
2222
*
2323
* @author Wouter J <waldio.webdesign@gmail.com>
2424
*/

‎src/Symfony/Component/Console/Input/StringInput.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Input/StringInput.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ private function tokenize(string $input): array
4848
$length = \strlen($input);
4949
$cursor = 0;
5050
while ($cursor < $length) {
51-
if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
52-
} elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
51+
if (preg_match('/\s+/A', $input, $match, 0, $cursor)) {
52+
} elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, 0, $cursor)) {
5353
$tokens[] = $match[1].$match[2].stripcslashes(str_replace(['"\'', '\'"', '\'\'', '""'], '', substr($match[3], 1, \strlen($match[3]) - 2)));
54-
} elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
54+
} elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, 0, $cursor)) {
5555
$tokens[] = stripcslashes(substr($match[0], 1, \strlen($match[0]) - 2));
56-
} elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
56+
} elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, 0, $cursor)) {
5757
$tokens[] = stripcslashes($match[1]);
5858
} else {
5959
// should never happen

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function process(ContainerBuilder $container)
3131
}
3232
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $id)) {
3333
if ($definition instanceof ChildDefinition && !class_exists($id)) {
34-
throw new InvalidArgumentException(sprintf('Service definition "%s" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.', $id));
34+
throw new InvalidArgumentException(sprintf('Service definition "%s" has a parent but no class, and its name looks like an FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.', $id));
3535
}
3636
$definition->setClass($id);
3737
}

‎src/Symfony/Component/DependencyInjection/Definition.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Definition.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ public function removeMethodCall(string $method)
370370
foreach ($this->calls as $i => $call) {
371371
if ($call[0] === $method) {
372372
unset($this->calls[$i]);
373-
break;
374373
}
375374
}
376375

‎src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/BindTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/BindTrait.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait BindTrait
2626
* injected in the matching parameters (of the constructor, of methods
2727
* called and of controller actions).
2828
*
29-
* @param string $nameOrFqcn A parameter name with its "$" prefix, or a FQCN
29+
* @param string $nameOrFqcn A parameter name with its "$" prefix, or an FQCN
3030
* @param mixed $valueOrRef The value or reference to bind
3131
*
3232
* @return $this

‎src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ private function parseDefinition(\DOMElement $service, string $file, Definition
373373
}
374374

375375
/**
376-
* Parses a XML file to a \DOMDocument.
376+
* Parses an XML file to a \DOMDocument.
377377
*
378378
* @throws InvalidArgumentException When loading of XML file returns error
379379
*/

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveClassPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveClassPassTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function testClassFoundChildDefinition()
8686
public function testAmbiguousChildDefinition()
8787
{
8888
$this->expectException(InvalidArgumentException::class);
89-
$this->expectExceptionMessage('Service definition "App\Foo\Child" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.');
89+
$this->expectExceptionMessage('Service definition "App\Foo\Child" has a parent but no class, and its name looks like an FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.');
9090
$container = new ContainerBuilder();
9191
$container->register('App\Foo', null);
9292
$container->setDefinition('App\Foo\Child', new ChildDefinition('App\Foo'));

‎src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,20 @@ public function testAddError()
411411
$def->addError('Second error');
412412
$this->assertSame(['First error', 'Second error'], $def->getErrors());
413413
}
414+
415+
public function testMultipleMethodCalls()
416+
{
417+
$def = new Definition('stdClass');
418+
419+
$def->addMethodCall('configure', ['arg1']);
420+
$this->assertTrue($def->hasMethodCall('configure'));
421+
$this->assertCount(1, $def->getMethodCalls());
422+
423+
$def->addMethodCall('configure', ['arg2']);
424+
$this->assertTrue($def->hasMethodCall('configure'));
425+
$this->assertCount(2, $def->getMethodCalls());
426+
427+
$def->removeMethodCall('configure');
428+
$this->assertFalse($def->hasMethodCall('configure'));
429+
}
414430
}

‎src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Field/ChoiceFormField.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* ChoiceFormField represents a choice form field.
1616
*
17-
* It is constructed from a HTML select tag, or a HTML checkbox, or radio inputs.
17+
* It is constructed from an HTML select tag, or an HTML checkbox, or radio inputs.
1818
*
1919
* @author Fabien Potencier <fabien@symfony.com>
2020
*/

‎src/Symfony/Component/Finder/Iterator/LazyIterator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Iterator/LazyIterator.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
/**
1515
* @author Jérémy Derussé <jeremy@derusse.com>
16+
*
17+
* @internal
1618
*/
1719
class LazyIterator implements \IteratorAggregate
1820
{

‎src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DateTimeToHtml5LocalDateTimeTransformer extends BaseDateTimeTransformer
2626
* Transforms a \DateTime into a local date and time string.
2727
*
2828
* According to the HTML standard, the input string of a datetime-local
29-
* input is a RFC3339 date followed by 'T', followed by a RFC3339 time.
29+
* input is an RFC3339 date followed by 'T', followed by an RFC3339 time.
3030
* https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
3131
*
3232
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object

‎src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
+61-16Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,25 @@
3737
use Symfony\Component\Form\Extension\Core\DataTransformer\ChoiceToValueTransformer;
3838
use Symfony\Component\Form\Extension\Core\EventListener\MergeCollectionListener;
3939
use Symfony\Component\Form\FormBuilderInterface;
40+
use Symfony\Component\Form\FormError;
4041
use Symfony\Component\Form\FormEvent;
4142
use Symfony\Component\Form\FormEvents;
4243
use Symfony\Component\Form\FormInterface;
4344
use Symfony\Component\Form\FormView;
4445
use Symfony\Component\OptionsResolver\Options;
4546
use Symfony\Component\OptionsResolver\OptionsResolver;
4647
use Symfony\Component\PropertyAccess\PropertyPath;
48+
use Symfony\Contracts\Translation\TranslatorInterface;
4749

4850
class ChoiceType extends AbstractType
4951
{
5052
private $choiceListFactory;
53+
private $translator;
5154

52-
public function __construct(ChoiceListFactoryInterface $choiceListFactory = null)
55+
/**
56+
* @param TranslatorInterface $translator
57+
*/
58+
public function __construct(ChoiceListFactoryInterface $choiceListFactory = null, $translator = null)
5359
{
5460
$this->choiceListFactory = $choiceListFactory ?: new CachingFactoryDecorator(
5561
new PropertyAccessDecorator(
@@ -67,13 +73,19 @@ public function __construct(ChoiceListFactoryInterface $choiceListFactory = null
6773
if ($ref->getNumberOfParameters() < 3) {
6874
trigger_deprecation('symfony/form', '5.1', 'Not defining a third parameter "callable|null $filter" in "%s::%s()" is deprecated.', $ref->class, $ref->name);
6975
}
76+
77+
if (null !== $translator && !$translator instanceof TranslatorInterface) {
78+
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be han instance of "%s", "%s" given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
79+
}
80+
$this->translator = $translator;
7081
}
7182

7283
/**
7384
* {@inheritdoc}
7485
*/
7586
public function buildForm(FormBuilderInterface $builder, array $options)
7687
{
88+
$unknownValues = [];
7789
$choiceList = $this->createChoiceList($options);
7890
$builder->setAttribute('choice_list', $choiceList);
7991

@@ -101,10 +113,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
101113

102114
$this->addSubForms($builder, $choiceListView->preferredChoices, $options);
103115
$this->addSubForms($builder, $choiceListView->choices, $options);
116+
}
104117

118+
if ($options['expanded'] || $options['multiple']) {
105119
// Make sure that scalar, submitted values are converted to arrays
106120
// which can be submitted to the checkboxes/radio buttons
107-
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
121+
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($choiceList, $options, &$unknownValues) {
108122
$form = $event->getForm();
109123
$data = $event->getData();
110124

@@ -119,6 +133,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
119133
// Convert the submitted data to a string, if scalar, before
120134
// casting it to an array
121135
if (!\is_array($data)) {
136+
if ($options['multiple']) {
137+
throw new TransformationFailedException('Expected an array.');
138+
}
139+
122140
$data = (array) (string) $data;
123141
}
124142

@@ -130,34 +148,61 @@ public function buildForm(FormBuilderInterface $builder, array $options)
130148
$unknownValues = $valueMap;
131149

132150
// Reconstruct the data as mapping from child names to values
133-
$data = [];
134-
135-
/** @var FormInterface $child */
136-
foreach ($form as $child) {
137-
$value = $child->getConfig()->getOption('value');
138-
139-
// Add the value to $data with the child's name as key
140-
if (isset($valueMap[$value])) {
141-
$data[$child->getName()] = $value;
142-
unset($unknownValues[$value]);
143-
continue;
151+
$knownValues = [];
152+
153+
if ($options['expanded']) {
154+
/** @var FormInterface $child */
155+
foreach ($form as $child) {
156+
$value = $child->getConfig()->getOption('value');
157+
158+
// Add the value to $data with the child's name as key
159+
if (isset($valueMap[$value])) {
160+
$knownValues[$child->getName()] = $value;
161+
unset($unknownValues[$value]);
162+
continue;
163+
}
164+
}
165+
} else {
166+
foreach ($data as $value) {
167+
if ($choiceList->getChoicesForValues([$value])) {
168+
$knownValues[] = $value;
169+
unset($unknownValues[$value]);
170+
}
144171
}
145172
}
146173

147174
// The empty value is always known, independent of whether a
148175
// field exists for it or not
149176
unset($unknownValues['']);
150177

151-
// Throw exception if unknown values were submitted
152-
if (\count($unknownValues) > 0) {
178+
// Throw exception if unknown values were submitted (multiple choices will be handled in a different event listener below)
179+
if (\count($unknownValues) > 0 && !$options['multiple']) {
153180
throw new TransformationFailedException(sprintf('The choices "%s" do not exist in the choice list.', implode('", "', array_keys($unknownValues))));
154181
}
155182

156-
$event->setData($data);
183+
$event->setData($knownValues);
157184
});
158185
}
159186

160187
if ($options['multiple']) {
188+
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) use (&$unknownValues) {
189+
// Throw exception if unknown values were submitted
190+
if (\count($unknownValues) > 0) {
191+
$form = $event->getForm();
192+
193+
$clientDataAsString = is_scalar($form->getViewData()) ? (string) $form->getViewData() : \gettype($form->getViewData());
194+
$messageTemplate = 'The value {{ value }} is not valid.';
195+
196+
if (null !== $this->translator) {
197+
$message = $this->translator->trans($messageTemplate, ['{{ value }}' => $clientDataAsString], 'validators');
198+
} else {
199+
$message = strtr($messageTemplate, ['{{ value }}' => $clientDataAsString]);
200+
}
201+
202+
$form->addError(new FormError($message, $messageTemplate, ['{{ value }}' => $clientDataAsString], null, new TransformationFailedException(sprintf('The choices "%s" do not exist in the choice list.', implode('", "', array_keys($unknownValues))))));
203+
}
204+
});
205+
161206
// <select> tag with "multiple" option or list of checkbox inputs
162207
$builder->addViewTransformer(new ChoicesToValuesTransformer($choiceList));
163208
} else {

‎src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
209209
{
210210
$view->vars['widget'] = $options['widget'];
211211

212-
// Change the input to a HTML5 datetime input if
212+
// Change the input to an HTML5 datetime input if
213213
// * the widget is set to "single_text"
214214
// * the format matches the one expected by HTML5
215215
// * the html5 is set to true

‎src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateType.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function finishView(FormView $view, FormInterface $form, array $options)
189189
{
190190
$view->vars['widget'] = $options['widget'];
191191

192-
// Change the input to a HTML5 date input if
192+
// Change the input to an HTML5 date input if
193193
// * the widget is set to "single_text"
194194
// * the format matches the one expected by HTML5
195195
// * the html5 is set to true

‎src/Symfony/Component/Form/Extension/Core/Type/TimeType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/TimeType.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
221221
'with_seconds' => $options['with_seconds'],
222222
]);
223223

224-
// Change the input to a HTML5 time input if
224+
// Change the input to an HTML5 time input if
225225
// * the widget is set to "single_text"
226226
// * the html5 is set to true
227227
if ($options['html5'] && 'single_text' === $options['widget']) {

0 commit comments

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