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

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 51e5cc0

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: Update bootstrap_5_layout.html.twig [HttpClient] Fix seeking in not-yet-initialized requests [Serializer] Allow getting discriminated type by class name
2 parents 8acd166 + df86e34 commit 51e5cc0

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 HttpClientInterface|ResponseInterface $client;
2929

3030
private ResponseInterface $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): string|false
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): string|false
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
@@ -132,6 +132,18 @@ public function testNonBlockingStream()
132132
$this->assertTrue(feof($stream));
133133
}
134134

135+
public function testSeekAsyncStream()
136+
{
137+
$client = $this->getHttpClient(__FUNCTION__);
138+
$response = $client->request('GET', 'http://localhost:8057/timeout-body');
139+
$stream = $response->toStream(false);
140+
141+
$this->assertSame(0, fseek($stream, 0, \SEEK_CUR));
142+
$this->assertSame('<1>', fread($stream, 8192));
143+
$this->assertFalse(feof($stream));
144+
$this->assertSame('<2>', stream_get_contents($stream));
145+
}
146+
135147
public function testResponseStreamRewind()
136148
{
137149
$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
@@ -480,6 +480,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
480480
return $client;
481481

482482
case 'testNonBlockingStream':
483+
case 'testSeekAsyncStream':
483484
$responses[] = new MockResponse((function () { yield '<1>'; yield ''; yield '<2>'; })(), ['response_headers' => $headers]);
484485
break;
485486

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', $mapping->getMappedObjectType(new AbstractDummyThirdChild()));

0 commit comments

Comments
 (0)
0