Skip to content

Commit 6ca9225

Browse files
committed
Merge branch '5.1'
* 5.1: [ErrorHandler] Return false directly and remove unused variable [OptionsResolver] Assert that the error type is valid in deprecations test [OptionsResolver] Fix deprecation message access [HttpClient] Allow bearer token with colon [Form] Fix custom formats deprecation with HTML5 widgets [Translator] Optional Intl dependency [Contracts][Translation] Optional Intl dependency [ErrorHandler] Escape JSON encoded log context update missing translations arabic [Yaml] simplify the test fix test by letting mock throw the actual expected exception
2 parents a6aa08e + 5685496 commit 6ca9225

File tree

13 files changed

+57
-33
lines changed

13 files changed

+57
-33
lines changed

src/Symfony/Component/ErrorHandler/ErrorHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ public function handleError(int $type, string $message, string $file, int $line)
425425
}
426426

427427
if (!$type || (!$log && !$throw)) {
428-
return !$silenced && $type && $log;
428+
return false;
429429
}
430-
$scope = $this->scopedErrors & $type;
431430

432431
if (false !== strpos($message, "@anonymous\0")) {
433432
$logMessage = $this->parseAnonymousClass($message);

src/Symfony/Component/ErrorHandler/Resources/views/logs.html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<td>
3636
<?= $this->formatLogMessage($log['message'], $log['context']); ?>
3737
<?php if ($log['context']) { ?>
38-
<pre class="text-muted prewrap m-t-5"><?= json_encode($log['context'], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES); ?></pre>
38+
<pre class="text-muted prewrap m-t-5"><?= $this->escape(json_encode($log['context'], \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES)); ?></pre>
3939
<?php } ?>
4040
</td>
4141
</tr>

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Component\Form\FormView;
2727
use Symfony\Component\Form\ReversedTransformer;
2828
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
29+
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
2930
use Symfony\Component\OptionsResolver\Options;
3031
use Symfony\Component\OptionsResolver\OptionsResolver;
3132

@@ -343,13 +344,22 @@ public function configureOptions(OptionsResolver $resolver)
343344

344345
return $timeWidget;
345346
});
346-
$resolver->setNormalizer('html5', function (Options $options, $html5) {
347-
if ($html5 && self::HTML5_FORMAT !== $options['format']) {
348-
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
349-
}
350-
351-
return $html5;
352-
});
347+
foreach (['html5', 'format'] as $option) {
348+
$resolver->setDeprecated($option, static function (Options $options, $value) use ($option): string {
349+
try {
350+
$html5 = 'html5' === $option ? $value : $options['html5'];
351+
$format = 'format' === $option ? $value : $options['format'];
352+
} catch (OptionDefinitionException $e) {
353+
return '';
354+
}
355+
356+
if ($html5 && self::HTML5_FORMAT !== $format) {
357+
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
358+
}
359+
360+
return $html5;
361+
});
362+
}
353363
}
354364

355365
/**

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Form\FormView;
2424
use Symfony\Component\Form\ReversedTransformer;
2525
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
26+
use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
2627
use Symfony\Component\OptionsResolver\Options;
2728
use Symfony\Component\OptionsResolver\OptionsResolver;
2829

@@ -328,13 +329,23 @@ public function configureOptions(OptionsResolver $resolver)
328329
$resolver->setAllowedTypes('days', 'array');
329330
$resolver->setAllowedTypes('input_format', 'string');
330331

331-
$resolver->setNormalizer('html5', function (Options $options, $html5) {
332-
if ($html5 && 'single_text' === $options['widget'] && self::HTML5_FORMAT !== $options['format']) {
333-
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
334-
}
332+
foreach (['html5', 'widget', 'format'] as $option) {
333+
$resolver->setDeprecated($option, static function (Options $options, $value) use ($option): string {
334+
try {
335+
$html5 = 'html5' === $option ? $value : $options['html5'];
336+
$widget = 'widget' === $option ? $value : $options['widget'];
337+
$format = 'format' === $option ? $value : $options['format'];
338+
} catch (OptionDefinitionException $e) {
339+
return '';
340+
}
335341

336-
return $html5;
337-
});
342+
if ($html5 && 'single_text' === $widget && self::HTML5_FORMAT !== $format) {
343+
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
344+
}
345+
346+
return $html5;
347+
});
348+
}
338349
}
339350

340351
/**

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ public function testSingleTextWidgetWithCustomNonHtml5Format()
520520
'widget' => 'single_text',
521521
'date_format' => \IntlDateFormatter::SHORT,
522522
'format' => null,
523+
'html5' => false,
523524
]);
524525
$view = $form->createView();
525526

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
111111
throw new InvalidArgumentException(sprintf('Option "auth_basic" must be string or an array, "%s" given.', get_debug_type($options['auth_basic'])));
112112
}
113113

114-
if (isset($options['auth_bearer']) && (!\is_string($options['auth_bearer']) || !preg_match('{^[-._=~+/0-9a-zA-Z]++$}', $options['auth_bearer']))) {
114+
if (isset($options['auth_bearer']) && (!\is_string($options['auth_bearer']) || !preg_match('{^[-._=:~+/0-9a-zA-Z]++$}', $options['auth_bearer']))) {
115115
throw new InvalidArgumentException(sprintf('Option "auth_bearer" must be a string containing only characters from the base 64 alphabet, %s given.', \is_string($options['auth_bearer']) ? 'invalid string' : '"'.get_debug_type($options['auth_bearer']).'"'));
116116
}
117117

src/Symfony/Component/Intl/Tests/Data/Bundle/Reader/BundleEntryReaderTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ public function testFallbackIfLocaleDoesNotExist()
144144
[self::RES_DIR, 'en_GB'],
145145
[self::RES_DIR, 'en']
146146
)
147-
->willReturnOnConsecutiveCalls(self::$data, self::$fallbackData);
147+
->willReturnOnConsecutiveCalls(
148+
$this->throwException(new ResourceBundleNotFoundException()),
149+
self::$fallbackData
150+
);
148151

149152
$this->assertSame('Lah', $this->reader->readEntry(self::RES_DIR, 'en_GB', ['Entries', 'Bam']));
150153
}
@@ -283,7 +286,7 @@ public function testFailIfEntryFoundNeitherInParentNorChild()
283286
[self::RES_DIR, 'en_GB'],
284287
[self::RES_DIR, 'en']
285288
)
286-
->willReturnOnConsecutiveCalls(['Foo' => 'Baz'], ['Foo' => 'Baz']);
289+
->willReturnOnConsecutiveCalls(['Foo' => 'Baz'], ['Foo' => 'Bar']);
287290

288291
$this->reader->readEntry(self::RES_DIR, 'en_GB', ['Foo', 'Bar'], true);
289292
}

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ public function offsetGet($option, bool $triggerDeprecation = true)
10791079

10801080
// Check whether the option is deprecated
10811081
// and it is provided by the user or is being called from a lazy evaluation
1082-
if ($triggerDeprecation && isset($this->deprecated[$option]) && (isset($this->given[$option]) || ($this->calling && \is_string($this->deprecated[$option])))) {
1082+
if ($triggerDeprecation && isset($this->deprecated[$option]) && (isset($this->given[$option]) || ($this->calling && \is_string($this->deprecated[$option]['message'])))) {
10831083
$deprecation = $this->deprecated[$option];
10841084
$message = $this->deprecated[$option]['message'];
10851085

src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,9 @@ public function testDeprecationMessages(\Closure $configureOptions, array $optio
524524
{
525525
$count = 0;
526526
error_clear_last();
527-
set_error_handler(function () use (&$count) {
527+
set_error_handler(function (int $type) use (&$count) {
528+
$this->assertSame(\E_USER_DEPRECATED, $type);
529+
528530
++$count;
529531

530532
return false;

src/Symfony/Component/Translation/Translator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ public function addResource(string $format, $resource, string $locale, string $d
150150
public function setLocale(string $locale)
151151
{
152152
$this->assertValidLocale($locale);
153-
$this->locale = $locale;
153+
$this->locale = $locale ?? (class_exists(\Locale::class) ? \Locale::getDefault() : 'en');
154154
}
155155

156156
/**
157157
* {@inheritdoc}
158158
*/
159159
public function getLocale()
160160
{
161-
return $this->locale ?? \Locale::getDefault();
161+
return $this->locale;
162162
}
163163

164164
/**

0 commit comments

Comments
 (0)