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

Skip to content

Commit df86e34

Browse files
Merge branch '5.4' into 6.0
* 5.4: Update bootstrap_5_layout.html.twig [HttpClient] Fix seeking in not-yet-initialized requests [Serializer] Allow getting discriminated type by class name
2 parents f4990ee + 3b17a0c commit df86e34

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_5_layout.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@
213213
{%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
214214
{%- set row_class = 'form-check' -%}
215215
{%- if 'checkbox-inline' in parent_label_class %}
216-
{% set row_class = row_class ~ ' form-check-inline' %}
216+
{%- set row_class = row_class ~ ' form-check-inline' -%}
217217
{% endif -%}
218218
{%- if 'checkbox-switch' in parent_label_class %}
219-
{% set row_class = row_class ~ ' form-switch' %}
219+
{%- set row_class = row_class ~ ' form-switch' -%}
220220
{% endif -%}
221221
<div class="{{ row_class }}">
222222
{{- form_label(form, null, { widget: parent() }) -}}

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
*/
2323
class StreamWrapper
2424
{
25-
/** @var resource|string|null */
25+
/** @var resource|null */
2626
public $context;
2727

2828
private $client;
2929

3030
private $response;
3131

32-
/** @var resource|null */
32+
/** @var resource|string|null */
3333
private $content;
3434

3535
/** @var resource|null */
@@ -38,7 +38,7 @@ class StreamWrapper
3838
private bool $blocking = true;
3939
private ?float $timeout = null;
4040
private bool $eof = false;
41-
private int $offset = 0;
41+
private ?int $offset = 0;
4242

4343
/**
4444
* Creates a PHP stream resource from a ResponseInterface.
@@ -87,6 +87,7 @@ public function bindHandles(&$handle, &$content): void
8787
{
8888
$this->handle = &$handle;
8989
$this->content = &$content;
90+
$this->offset = null;
9091
}
9192

9293
public function stream_open(string $path, string $mode, int $options): bool
@@ -131,7 +132,7 @@ public function stream_read(int $count)
131132
}
132133
}
133134

134-
if (0 !== fseek($this->content, $this->offset)) {
135+
if (0 !== fseek($this->content, $this->offset ?? 0)) {
135136
return false;
136137
}
137138

@@ -160,6 +161,11 @@ public function stream_read(int $count)
160161
try {
161162
$this->eof = true;
162163
$this->eof = !$chunk->isTimeout();
164+
165+
if (!$this->eof && !$this->blocking) {
166+
return '';
167+
}
168+
163169
$this->eof = $chunk->isLast();
164170

165171
if ($chunk->isFirst()) {
@@ -202,7 +208,7 @@ public function stream_set_option(int $option, int $arg1, ?int $arg2): bool
202208

203209
public function stream_tell(): int
204210
{
205-
return $this->offset;
211+
return $this->offset ?? 0;
206212
}
207213

208214
public function stream_eof(): bool
@@ -212,14 +218,19 @@ public function stream_eof(): bool
212218

213219
public function stream_seek(int $offset, int $whence = \SEEK_SET): bool
214220
{
221+
if (null === $this->content && null === $this->offset) {
222+
$this->response->getStatusCode();
223+
$this->offset = 0;
224+
}
225+
215226
if (!\is_resource($this->content) || 0 !== fseek($this->content, 0, \SEEK_END)) {
216227
return false;
217228
}
218229

219230
$size = ftell($this->content);
220231

221232
if (\SEEK_CUR === $whence) {
222-
$offset += $this->offset;
233+
$offset += $this->offset ?? 0;
223234
}
224235

225236
if (\SEEK_END === $whence || $size < $offset) {

src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ public function testNonBlockingStream()
131131
$this->assertTrue(feof($stream));
132132
}
133133

134+
public function testSeekAsyncStream()
135+
{
136+
$client = $this->getHttpClient(__FUNCTION__);
137+
$response = $client->request('GET', 'http://localhost:8057/timeout-body');
138+
$stream = $response->toStream(false);
139+
140+
$this->assertSame(0, fseek($stream, 0, \SEEK_CUR));
141+
$this->assertSame('<1>', fread($stream, 8192));
142+
$this->assertFalse(feof($stream));
143+
$this->assertSame('<2>', stream_get_contents($stream));
144+
}
145+
134146
public function testResponseStreamRewind()
135147
{
136148
$client = $this->getHttpClient(__FUNCTION__);

src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
443443
return $client;
444444

445445
case 'testNonBlockingStream':
446+
case 'testSeekAsyncStream':
446447
$responses[] = new MockResponse((function () { yield '<1>'; yield ''; yield '<2>'; })(), ['response_headers' => $headers]);
447448
break;
448449

src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getClassForType(string $type): ?string
5050
public function getMappedObjectType(object|string $object): ?string
5151
{
5252
foreach ($this->typesMapping as $type => $typeClass) {
53-
if (is_a($object, $typeClass)) {
53+
if (is_a($object, $typeClass, true)) {
5454
return $type;
5555
}
5656
}

src/Symfony/Component/Serializer/Tests/Mapping/ClassDiscriminatorMappingTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function testMappedObjectType()
3939
'third' => AbstractDummyThirdChild::class,
4040
]);
4141

42+
$this->assertEquals('first', $mapping->getMappedObjectType(AbstractDummyFirstChild::class));
4243
$this->assertEquals('first', $mapping->getMappedObjectType(new AbstractDummyFirstChild()));
4344
$this->assertNull($mapping->getMappedObjectType(new AbstractDummySecondChild()));
4445
$this->assertSame('third', < 3959 span class=pl-c1>$mapping->getMappedObjectType(new AbstractDummyThirdChild()));

0 commit comments

Comments
 (0)
0