8000 Merge branch '6.2' into 6.3 · symfony/symfony@f4659f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit f4659f8

Browse files
Merge branch '6.2' into 6.3
* 6.2: [Serializer] Handle datetime deserialization in U format [HttpFoundation] Fix file streaming after connection aborted Update HeaderBag::all PhpDoc [Messenger] Add `IS_REPEATABLE` flag to `AsMessageHandler` attribute Allow resources in Query::setParam Fix param type annotation [HttpClient] Fix setting duplicate-name headers when redirecting with AmpHttpClient
2 parents 90879b4 + 4c39613 commit f4659f8

File tree

8 files changed

+30
-13
lines changed

8 files changed

+30
-13
lines changed

src/Symfony/Bridge/Doctrine/Middleware/Debug/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function stop(): void
4343
}
4444
}
4545

46-
public function setParam(string|int $param, null|string|int|float|bool &$variable, int $type): void
46+
public function setParam(string|int $param, mixed &$variable, int $type): void
4747
{
4848
// Numeric indexes start at 0 in profiler
4949
$idx = \is_int($param) ? $param - 1 : $param;

src/Symfony/Bridge/Doctrine/Tests/Middleware/Debug/MiddlewareTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,23 +145,31 @@ public function testWithParamBound(callable $executeMethod)
145145
{
146146
$this->init();
147147

148-
$product = 'product1';
149-
$price = 12.5;
150-
$stock = 5;
148+
$sql = <<<EOT
149+
INSERT INTO products(name, price, stock, picture, tags)
150+
VALUES (?, ?, ?, ?, ?)
151+
EOT;
152+
153+
$expectedRes = $res = $this->getResourceFromString('mydata');
151154

152-
$stmt = $this->conn->prepare('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)');
155+
$stmt = $this->conn->prepare($sql);
153156
$stmt->bindParam(1, $product);
154157
$stmt->bindParam(2, $price);
155158
$stmt->bindParam(3, $stock, ParameterType::INTEGER);
159+
$stmt->bindParam(4, $res, ParameterType::BINARY);
160+
161+
$product = 'product1';
162+
$price = 12.5;
163+
$stock = 5;
156164

157165
$executeMethod($stmt);
158166

159167
// Debug data should not be affected by these changes
160168
$debug = $this->debugDataHolder->getData()['default'] ?? [];
161169
$this->assertCount(2, $debug);
162-
$this->assertSame('INSERT INTO products(name, price, stock) VALUES (?, ?, ?)', $debug[1]['sql']);
163-
$this->assertSame(['product1', '12.5', 5], $debug[1]['params']);
164-
$this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER], $debug[1]['types']);
170+
$this->assertSame($sql, $debug[1]['sql']);
171+
$this->assertSame(['product1', 12.5, 5, $expectedRes], $debug[1]['params']);
172+
$this->assertSame([ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER, ParameterType::BINARY], $debug[1]['types']);
165173
$this->assertGreaterThan(0, $debug[1]['executionMS']);
166174
}
167175

src/Symfony/Component/HttpClient/Response/AmpResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ private static function followRedirects(Request $originRequest, AmpClientState $
346346
}
347347

348348
foreach ($originRequest->getRawHeaders() as [$name, $value]) {
349-
$request->setHeader($name, $value);
349+
$request->addHeader($name, $value);
350350
}
351351

352352
if ($request->getUri()->getAuthority() !== $originRequest->getUri()->getAuthority()) {

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ public function sendContent(): static
319319
while ('' !== $data) {
320320
$read = fwrite($out, $data);
321321
if (false === $read || connection_aborted()) {
322-
break;
322+
break 2;
323323
}
324324
if (0 < $length) {
325325
$length -= $read;

src/Symfony/Component/HttpFoundation/HeaderBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __toString(): string
6363
*
6464
* @param string|null $key The name of the headers to return or null to get them all
6565
*
66-
* @return ($key is null ? array<string, array<int, string|null>> : array<int, string|null>)
66+
* @return ($key is null ? array<string, list<string|null>> : list<string|null>)
6767
*/
6868
public function all(string $key = null): array
6969
{

src/Symfony/Component/Messenger/Attribute/AsMessageHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Alireza Mirsepassi <alirezamirsepassi@gmail.com>
1818
*/
19-
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
19+
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
2020
class AsMessageHandler
2121
{
2222
public function __construct(

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
9696
$dateTimeFormat = $context[self::FORMAT_KEY] ?? null;
9797
$timezone = $this->getTimezone($context);
9898

99-
if (null === $data || !\is_string($data) || '' === trim($data)) {
99+
if (\is_int($data) || \is_float($data)) {
100+
switch ($dateTimeFormat) {
101+
case 'U': $data = sprintf('%d', $data); break;
102+
case 'U.u': $data = sprintf('%.6F', $data); break;
103+
}
104+
}
105+
106+
if (!\is_string($data) || '' === trim($data)) {
100107
throw NotNormalizableValueException::createForUnexpectedDataType('The data is either not an string, an empty string, or null; you should pass a string that can be parsed with the passed format or a valid DateTime string.', $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
101108
}
102109

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ public function testDenormalize()
178178
$this->assertEquals(new \DateTimeImmutable('2016/01/01', new \DateTimeZone('UTC')), $this->normalizer->denormalize('2016-01-01T00:00:00+00:00', \DateTimeImmutable::class));
179179
$this->assertEquals(new \DateTime('2016/01/01', new \DateTimeZone('UTC')), $this->normalizer->denormalize('2016-01-01T00:00:00+00:00', \DateTime::class));
180180
$this->assertEquals(new \DateTime('2016/01/01', new \DateTimeZone('UTC')), $this->normalizer->denormalize(' 2016-01-01T00:00:00+00:00 ', \DateTime::class));
181+
$this->assertEquals(new \DateTimeImmutable('2023-05-06T17:35:34.000000+0000', new \DateTimeZone('UTC')), $this->normalizer->denormalize(1683394534, \DateTimeImmutable::class, null, [DateTimeNormalizer::FORMAT_KEY => 'U']));
182+
$this->assertEquals(new \DateTimeImmutable('2023-05-06T17:35:34.123400+0000', new \DateTimeZone('UTC')), $this->normalizer->denormalize(1683394534.1234, \DateTimeImmutable::class, null, [DateTimeNormalizer::FORMAT_KEY => 'U.u']));
181183
}
182184

183185
public function testDenormalizeUsingTimezonePassedInConstructor()

0 commit comments

Comments
 (0)
0