Skip to content

Commit 5685496

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [ErrorHandler] Return false directly and remove unused variable [OptionsResolver] Assert that the error type is valid in deprecations test [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 44bd82c + 55a450d commit 5685496

File tree

12 files changed

+56
-32
lines changed

12 files changed

+56
-32
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

@@ -338,13 +339,22 @@ public function configureOptions(OptionsResolver $resolver)
338339

339340
return $timeWidget;
340341
});
341-
$resolver->setNormalizer('html5', function (Options $options, $html5) {
342-
if ($html5 && self::HTML5_FORMAT !== $options['format']) {
343-
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is enabled.', self::class));
344-
}
345-
346-
return $html5;
347-
});
342+
foreach (['html5', 'format'] as $option) {
343+
$resolver->setDeprecated($option, static function (Options $options, $value) use ($option): string {
344+
try {
345+
$html5 = 'html5' === $option ? $value : $options['html5'];
346+
$format = 'format' === $option ? $value : $options['format'];
347+
} catch (OptionDefinitionException $e) {
348+
return '';
349+
}
350+
351+
if ($html5 && self::HTML5_FORMAT !== $format) {
352+
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
353+
}
354+
355+
return $html5;
356+
});
357+
}
348358
}
349359

350360
/**

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

@@ -323,13 +324,23 @@ public function configureOptions(OptionsResolver $resolver)
323324
$resolver->setAllowedTypes('days', 'array');
324325
$resolver->setAllowedTypes('input_format', 'string');
325326

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

331-
return $html5;
332-
});
337+
if ($html5 && 'single_text' === $widget && self::HTML5_FORMAT !== $format) {
338+
throw new LogicException(sprintf('Cannot use the "format" option of "%s" when the "html5" option is disabled.', self::class));
339+
}
340+
341+
return $html5;
342+
});
343+
}
333344
}
334345

335346
/**

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/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
/**

src/Symfony/Component/Validator/Resources/translations/validators.ar.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,10 @@
382382
<source>Each element of this collection should satisfy its own set of constraints.</source>
383383
<target>يجب أن يفي كل عنصر من عناصر هذه المجموعة بمجموعة القيود الخاصة به.</target>
384384
</trans-unit>
385+
<trans-unit id="99">
386+
<source>This value is not a valid International Securities Identification Number (ISIN).</source>
387+
<target> صالح (ISIN) هذه القيمة ليست رقم تعريف الأوراق المالية الدولي.</target>
388+
</trans-unit>
385389
</body>
386390
</file>
387391
</xliff>

0 commit comments

Comments
 (0)