8000 Merge branch '4.4' into 5.4 · symfony/symfony@ae61b4d · GitHub
[go: up one dir, main page]

Skip to content

Commit ae61b4d

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: [HttpClient] Fix the CS fix Workaround disabled "var_dump" [Serializer] Respect default context in DateTimeNormalizer::denormalize # Conflicts: # src/Symfony/Component/Debug/ErrorHandler.php # src/Symfony/Component/HttpClient/HttpClientTrait.php # src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php
2 parents 00037d8 + 57e5141 commit ae61b4d

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function shutdown()
188188
if (class_exists(DebugClassLoader::class, false)) {
189189
DebugClassLoader::checkClasses();
190190
}
191-
$currErrorHandler = set_error_handler('var_dump');
191+
$currErrorHandler = set_error_handler('is_int');
192192
restore_error_handler();
193193

194194
if ($currErrorHandler !== [$this, 'handleError']) {

src/Symfony/Component/ErrorHandler/ErrorHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ public function screamAt(int $levels, bool $replace = false): int
381381
private function reRegister(int $prev): void
382382
{
383383
if ($prev !== $this->thrownErrors | $this->loggedErrors) {
384-
$handler = set_error_handler('var_dump');
384+
$handler = set_error_handler('is_int');
385385
$handler = \is_array($handler) ? $handler[0] : null;
386386
restore_error_handler();
387387
if ($handler === $this) {
@@ -528,7 +528,7 @@ public function handleError(int $type, string $message, string $file, int $line)
528528
$log = 0;
529529
} else {
530530
if (\PHP_VERSION_ID < (\PHP_VERSION_ID < 70400 ? 70316 : 70404)) {
531-
$currentErrorHandler = set_error_handler('var_dump');
531+
$currentErrorHandler = set_error_handler('is_int');
532532
restore_error_handler();
533533
}
534534

@@ -645,7 +645,7 @@ public static function handleFatalError(array $error = null): void
645645
$sameHandlerLimit = 10;
646646

647647
while (!\is_array($handler) || !$handler[0] instanceof self) {
648-
$handler = set_exception_handler('var_dump');
648+
$handler = set_exception_handler('is_int');
649649
restore_exception_handler();
650650

651651
if (!$handler) {

src/Symfony/Component/HttpClient/HttpClientTrait.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
117117
}
118118

119119
// Validate on_progress
120-
if (!\is_callable($onProgress = $options['on_progress'] ?? 'var_dump')) {
120+
if (isset($options['on_progress']) && !\is_callable($onProgress = $options['on_progress'])) {
121121
throw new InvalidArgumentException(sprintf('Option "on_progress" must be callable, "%s" given.', get_debug_type($onProgress)));
122122
}
123123

@@ -206,9 +206,11 @@ private static function mergeDefaultOptions(array $options, array $defaultOption
206206

207207
$options += $defaultOptions;
208208

209-
foreach (self::$emptyDefaults ?? [] as $k => $v) {
210-
if (!isset($options[$k])) {
211-
$options[$k] = $v;
209+
if (isset(self::$emptyDefaults)) {
210+
foreach (self::$emptyDefaults as $k => $v) {
211+
if (!isset($options[$k])) {
212+
$options[$k] = $v;
213+
}
212214
}
213215
}
214216

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(callable $exceptionHandler = null, LoggerInterface $
5757
$deprecationLogger = $fileLinkFormat;
5858
}
5959

60-
$handler = set_exception_handler('var_dump');
60+
$handler = set_exception_handler('is_int');
6161
$this->earlyHandler = \is_array($handler) ? $handler[0] : null;
6262
restore_exception_handler();
6363

@@ -83,7 +83,7 @@ public function configure(object $event = null)
8383
}
8484
$this->firstCall = $this->hasTerminatedWithException = false;
8585

86-
$handler = set_exception_handler('var_dump');
86+
$handler = set_exception_handler('is_int');
8787
$handler = \is_array($handler) ? $handler[0] : null;
8888
restore_exception_handler();
8989

src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php

< 7803 span class="prc-TooltipV2-Tooltip-cYMVY" data-direction="s" role="tooltip" aria-hidden="true" id=":R13etlab:">Expand all lines: src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ public function denormalize($data, string $type, string $format = null, array $c
107107
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('Parsing datetime string "%s" using format "%s" resulted in %d errors: ', $data, $dateTimeFormat, $dateTimeErrors['error_count'])."\n".implode("\n", $this->formatDateTimeErrors($dateTimeErrors['errors'])), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
108108
}
109109

110+
$defaultDateTimeFormat = $this->defaultContext[self::FORMAT_KEY] ?? null;
111+
112+
if (null !== $defaultDateTimeFormat) {
113+
$object = \DateTime::class === $type ? \DateTime::createFromFormat($defaultDateTimeFormat, $data, $timezone) : \DateTimeImmutable::createFromFormat($defaultDateTimeFormat, $data, $timezone);
114+
115+
if (false !== $object) {
116+
return $object;
117+
}
118+
}
119+
110120
try {
111121
return \DateTime::class === $type ? new \DateTime($data, $timezone) : new \DateTimeImmutable($data, $timezone);
112122
} catch (\Exception $e) {

src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,28 @@ public function testDenormalizeDateTimeStringWithSpacesUsingFormatPassedInContex
271271
$this->normalizer->denormalize(' 2016.01.01 ', \DateTime::class, null, [DateTimeNormalizer::FORMAT_KEY => 'Y.m.d|']);
272272
}
273273

274+
public function testDenormalizeDateTimeStringWithDefaultContextFormat()
275+
{
276+
$format = 'd/m/Y';
277+
$string = '01/10/2018';
278+
279+
$normalizer = new DateTimeNormalizer([DateTimeNormalizer::FORMAT_KEY => $format]);
280+
$denormalizedDate = $normalizer->denormalize($string, \DateTimeInterface::class);
281+
282+
$this->assertSame('01/10/2018', $denormalizedDate->format($format));
283+
}
284+
285+
public function testDenormalizeDateTimeStringWithDefaultContextAllowsErrorFormat()
286+
{
287+
$format = 'd/m/Y'; // the default format
288+
$string = '2020-01-01'; // the value which is in the wrong format, but is accepted because of `new \DateTime` in DateTimeNormalizer::denormalize
289+
290+
$normalizer 66F9 = new DateTimeNormalizer([DateTimeNormalizer::FORMAT_KEY => $format]);
291+
$denormalizedDate = $normalizer->denormalize($string, \DateTimeInterface::class);
292+
293+
$this->assertSame('2020-01-01', $denormalizedDate->format('Y-m-d'));
294+
}
295+
274296
public function testDenormalizeFormatMismatchThrowsException()
275297
{
276298
$this->expectException(UnexpectedValueException::class);

0 commit comments

Comments
 (0)
0