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

Skip to content

Navigation Menu

Sign in
Appearance settings

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 951b11e

Browse files
Merge branch '6.3' into 6.4
* 6.3: [Validator] Add annotation in Constraint [VarExporter] Remove unused test files [FrameworkBundle] Remove unused test file [DependencyInjection] Remove unused test file [HttpKernel] Fix missing Request in RequestStack for StreamedResponse Psalm: Ignore UnusedClass errors fix(console): avoid multiple new line when message already ends with a new line
2 parents 11b587a + 6126caf commit 951b11e

21 files changed

+79
-215
lines changed

psalm.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@
3838
<referencedClass name="ReflectionIntersectionType"/>
3939
<referencedClass name="UnitEnum"/>
4040
</errorLevel>
41-
</UndefinedDocblockClass>
41+
</UndefinedDocblockClass>
42+
<UnusedClass>
43+
<errorLevel type="suppress">
44+
<!--
45+
Because we don't analyze our tests or fixtures, we will
46+
get a lot of false positives regarding unused classes.
47+
-->
48+
<directory name="src/Symfony" />
49+
</errorLevel>
50+
</UnusedClass>
4251
<UnusedConstructor>
4352
<errorLevel type="suppress">
4453
<!--

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/legacy_translator_enabled_locales.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/serializer_legacy_cache.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/legacy_translator_enabled_locales.xml

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/serializer_legacy_cache.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/serializer_legacy_cache.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Symfony/Component/Console/Output/ConsoleSectionOutput.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ public function addContent(string $input, bool $newline = true): int
119119
// re-add the line break (that has been removed in the above `explode()` for
120120
// - every line that is not the last line
121121
// - if $newline is required, also add it to the last line
122-
// - if it's not new line, but input ending with `\PHP_EOL`
123-
if ($i < $count || $newline || str_ends_with($input, \PHP_EOL)) {
122+
if ($i < $count || $newline) {
124123
$lineContent .= \PHP_EOL;
125124
}
126125

@@ -168,6 +167,12 @@ public function addNewLineOfInputSubmit(): void
168167
*/
169168
protected function doWrite(string $message, bool $newline)
170169
{
170+
// Simulate newline behavior for consistent output formatting, avoiding extra logic
171+
if (!$newline && str_ends_with($message, \PHP_EOL)) {
172+
$message = substr($message, 0, -\strlen(\PHP_EOL));
173+
$newline = true;
174+
}
175+
171176
if (!$this->isDecorated()) {
172177
parent::doWrite($message, $newline);
173178

src/Symfony/Component/Console/Tests/Output/ConsoleSectionOutputTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function testMaxHeightMultipleSections()
159159
$expected .= 'Two'.\PHP_EOL.'Three'.\PHP_EOL.'Four'.\PHP_EOL;
160160

161161
// cause overflow of first section (redraw whole section, without first line)
162-
$firstSection->writeln("Four\nFive\nSix");
162+
$firstSection->writeln('Four'.\PHP_EOL.'Five'.\PHP_EOL.'Six');
163163
$expected .= "\x1b[6A\x1b[0J";
164164
$expected .= 'Four'.\PHP_EOL.'Five'.\PHP_EOL.'Six'.\PHP_EOL;
165165
$expected .= 'Two'.\PHP_EOL.'Three'.\PHP_EOL.'Four'.\PHP_EOL;
@@ -291,4 +291,16 @@ public function testClearSectionContainingQuestion()
291291
rewind($output->getStream());
292292
$this->assertSame('What\'s your favorite super hero?'.\PHP_EOL."\x1b[2A\x1b[0J", stream_get_contents($output->getStream()));
293293
}
294+
295+
public function testWriteWithoutNewLine()
296+
{
297+
$sections = [];
298+
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
299+
300+
$output->write('Foo'.\PHP_EOL);
301+
$output->write('Bar');
302+
303+
rewind($output->getStream());
304+
$this->assertEquals(escapeshellcmd('Foo'.\PHP_EOL.'Bar'.\PHP_EOL), escapeshellcmd(stream_get_contents($output->getStream())));
305+
}
294306
}

src/Symfony/Component/Console/Tests/Style/SymfonyStyleTest.php

Lines changed: 5 additions & 5 deletions
< 10000 td data-grid-cell-id="diff-5ec42113507b3d7e302943ad9cc566854d11ece087f05478598553537f986904-209-209-2" data-line-anchor="diff-5ec42113507b3d7e302943ad9cc566854d11ece087f05478598553537f986904R209" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">

Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ public function testAskAndClearExpectFullSectionCleared()
209209
210210
rewind($output->getStream());
211211
$this->assertEquals($answer, $givenAnswer);
212-
$this->assertEquals(
212+
$this->assertEquals(escapeshellcmd(
213213
'start'.\PHP_EOL. // write start
214214
'foo'.\PHP_EOL. // write foo
215215
"\x1b[1A\x1b[0Jfoo and bar".\PHP_EOL. // complete line
216-
\PHP_EOL.\PHP_EOL." \033[32mDummy question?\033[39m:".\PHP_EOL.' > '.\PHP_EOL.\PHP_EOL.\PHP_EOL. // question
217-
'foo2'.\PHP_EOL.\PHP_EOL. // write foo2
216+
\PHP_EOL." \033[32mDummy question?\033[39m:".\PHP_EOL.' > '.\PHP_EOL.\PHP_EOL. // question
217+
'foo2'.\PHP_EOL. // write foo2
218218
'bar2'.\PHP_EOL. // write bar
219-
"\033[12A\033[0J", // clear 12 lines (11 output lines and one from the answer input return)
220-
stream_get_contents($output->getStream())
219+
"\033[9A\033[0J"), // clear 9 lines (8 output lines and one from the answer input return)
220+
escapeshellcmd(stream_get_contents($output->getStream()))
221221
);
222222
}
223223
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/legacy_invalid_alias_definition.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/Symfony/Component/HttpFoundation/StreamedResponse.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public function setCallback(callable $callback): static
5656
return $this;
5757
}
5858

59+
public function getCallback(): \Closure
60+
{
61+
return ($this->callback)(...);
62+
}
63+
5964
/**
6065
* This method only sends the headers once.
6166
*

src/Symfony/Component/HttpKernel/HttpKernel.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\RequestStack;
1717
use Symfony\Component\HttpFoundation\Response;
18+
use Symfony\Component\HttpFoundation\StreamedResponse;
1819
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
1920
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
2021
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
@@ -70,8 +71,9 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
7071
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
7172

7273
$this->requestStack->push($request);
74+
$response = null;
7375
try {
74-
return $this->handleRaw($request, $type);
76+
return $response = $this->handleRaw($request, $type);
7577
} catch (\Throwable $e) {
7678
if ($e instanceof \Error && !$this->handleAllThrowables) {
7779
throw $e;
@@ -86,9 +88,23 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
8688
throw $e;
8789
}
8890

89-
return $this->handleThrowable($e, $request, $type);
91+
return $response = $this->handleThrowable($e, $request, $type);
9092
} finally {
9193
$this->requestStack->pop();
94+
95+
if ($response instanceof StreamedResponse) {
96+
$callback = $response->getCallback();
97+
$requestStack = $this->requestStack;
98+
99+
$response->setCallback(static function () use ($request, $callback, $requestStack) {
100+
$requestStack->push($request);
101+
try {
102+
$callback();
103+
} finally {
104+
$requestStack->pop();
105+
}
106+
});
107+
}
92108
}
93109
}
94110

src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\HttpFoundation\Request;
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020
use Symfony\Component\HttpFoundation\Response;
21+
use Symfony\Component\HttpFoundation\StreamedResponse;
2122
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
2223
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
2324
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
@@ -457,6 +458,23 @@ public function testVerifyRequestStackPushPopDuringHandle()
457458
$kernel->handle($request, HttpKernelInterface::MAIN_REQUEST);
458459
}
459460

461+
public function testVerifyRequestStackPushPopWithStreamedResponse()
462+
{
463+
$request = new Request();
464+
$stack = new RequestStack();
465+
$dispatcher = new EventDispatcher();
466+
$kernel = $this->getHttpKernel($dispatcher, fn () => new StreamedResponse(function () use ($stack) {
467+
echo $stack->getMainRequest()::class;
468+
}), $stack);
469+
470+
$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST);
471+
self::assertNull($stack->getMainRequest());
472+
ob_start();
473+
$response->send();
474+
self::assertSame(Request::class, ob_get_clean());
475+
self::assertNull($stack->getMainRequest());
476+
}
477+
460478
public function testInconsistentClientIpsOnMainRequests()
461479
{
462480
$this->expectException(BadRequestHttpException::class);

src/Symfony/Component/HttpKernel/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/deprecation-contracts": "^2.5|^3",
2121
"symfony/error-handler": "^6.4|^7.0",
2222
"symfony/event-dispatcher": "^5.4|^6.0|^7.0",
23-
"symfony/http-foundation": "^6.2.7|^7.0",
23+
"symfony/http-foundation": "^6.3.4|^7.0",
2424
"symfony/polyfill-ctype": "^1.8",
2525
"psr/log": "^1|^2|^3"
2626
},

src/Symfony/Component/Validator/Constraint.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ abstract class Constraint
4646

4747
/**
4848
* Maps error codes to the names of their constants.
49+
*
50+
* @var array<string, string>
4951
*/
5052
protected const ERROR_NAMES = [];
5153

src/Symfony/Component/VarExporter/Tests/Fixtures/array-iterator-legacy.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Symfony/Component/VarExporter/Tests/Fixtures/array-object-custom-legacy.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Symfony/Component/VarExporter/Tests/Fixtures/array-object-legacy.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Symfony/Component/VarExporter/Tests/Fixtures/final-array-iterator-legacy.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Symfony/Component/VarExporter/Tests/Fixtures/final-error-legacy.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0