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

Skip to content

Commit 636ad0d

Browse files
Merge branch '6.0' into 6.1
* 6.0: [Messenger] cs fix [Messenger] Fix time-limit check exception [Console] Fix console `ProgressBar::override()` after manual `ProgressBar::cleanup()` [FrameworkBundle] typo default_lifetime example [HttpClient] Handle Amp HTTP client v5 incompatibility gracefully [HttpKernel] Don’t try to wire Response argument with controller.service_arguments [PhpUnitBridge] Fix language deprecations incorrectly marked as direct [FrameworkBundle] Removed unused $willBeAvailable params on Configuration [Cache] Remove extra type condition in MemcachedAdapter::createConnection() Tell about messenger:consume invalid limit options [Messenger] Do not throw 'no handlers' exception when skipping due to duplicate handling
2 parents 300dc26 + 90cb7d3 commit 636ad0d

File tree

18 files changed

+255
-33
lines changed

18 files changed

+255
-33
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function handleError($type, $msg, $file, $line, $context = [])
132132
$msg = $trace[1]['args'][0];
133133
}
134134

135-
$deprecation = new Deprecation($msg, $trace, $file);
135+
$deprecation = new Deprecation($msg, $trace, $file, \E_DEPRECATED === $type);
136136
if ($deprecation->isMuted()) {
137137
return null;
138138
}

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Deprecation
3737

3838
private $trace = [];
3939
private $message;
40+
private $languageDeprecation;
4041
private $originClass;
4142
private $originMethod;
4243
private $triggeringFile;
@@ -56,8 +57,9 @@ class Deprecation
5657
/**
5758
* @param string $message
5859
* @param string $file
60+
F438 * @param bool $languageDeprecation
5961
*/
60-
public function __construct($message, array $trace, $file)
62+
public function __construct($message, array $trace, $file, $languageDeprecation = false)
6163
{
6264
if (isset($trace[2]['function']) && 'trigger_deprecation' === $trace[2]['function']) {
6365
$file = $trace[2]['file'];
@@ -66,6 +68,7 @@ public function __construct($message, array $trace, $file)
6668

6769
$this->trace = $trace;
6870
$this->message = $message;
71+
$this->languageDeprecation = $languageDeprecation;
6972

7073
$i = \count($trace);
7174
while (1 < $i && $this->lineShouldBeSkipped($trace[--$i])) {
@@ -239,7 +242,12 @@ public function isMuted()
239242
*/
240243
public function getType()
241244
{
242-
if (self::PATH_TYPE_SELF === $pathType = $this->getPathType($this->triggeringFile)) {
245+
$pathType = $this->getPathType($this->triggeringFile);
246+
if ($this->languageDeprecation && self::PATH_TYPE_VENDOR === $pathType) {
247+
// the triggering file must be used for language deprecations
248+
return self::TYPE_INDIRECT;
249+
}
250+
if (self::PATH_TYPE_SELF === $pathType) {
243251
return self::TYPE_SELF;
244252
}
245253
if (self::PATH_TYPE_UNDETERMINED === $pathType) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace acme\lib;
4+
5+
class PhpDeprecation implements \Serializable
6+
{
7+
public function serialize(): string
8+
{
9+
return serialize([]);
10+
}
11+
12+
public function unserialize($data): void
13+
{
14+
}
15+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
Test that a PHP deprecation from a vendor class autoload is considered indirect.
3+
--SKIPIF--
4+
<?php if (\PHP_VERSION_ID < 80100) echo 'skip'; ?>
5+
--FILE--
6+
<?php
7+
8+
$k = 'SYMFONY_DEPRECATIONS_HELPER';
9+
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[total]=0');
10+
putenv('ANSICON');
11+
putenv('ConEmuANSI');
12+
putenv('TERM');
13+
14+
$vendor = __DIR__;
15+
while (!file_exists($vendor.'/vendor')) {
16+
$vendor = dirname($vendor);
17+
}
18+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
19+
require PHPUNIT_COMPOSER_INSTALL;
20+
require_once __DIR__.'/../../bootstrap.php';
21+
eval(<<<'EOPHP'
22+
namespace PHPUnit\Util;
23+
24+
class Test
25+
{
26+
public static function getGroups()
27+
{
28+
return array();
29+
}
30+
}
31+
EOPHP
32+
);
33+
require __DIR__.'/fake_vendor/autoload.php';
34+
35+
\Symfony\Component\ErrorHandler\DebugClassLoader::enable();
36+
new \acme\lib\PhpDeprecation();
37+
38+
?>
39+
--EXPECTF--
40+
Remaining indirect deprecation notices (1)
41+
42+
1x: acme\lib\PhpDeprecation implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary)
43+
1x in DebugClassLoader::loadClass from Symfony\Component\ErrorHandler

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ public function getConfigTreeBuilder(): TreeBuilder
160160
$this->addRequestSection($rootNode);
161161
$this->addAssetsSection($rootNode, $enableIfStandalone);
162162
$this->addTranslatorSection($rootNode, $enableIfStandalone);
163-
$this->addValidationSection($rootNode, $enableIfStandalone, $willBeAvailable);
163+
$this->addValidationSection($rootNode, $enableIfStandalone);
164164
$this->addAnnotationsSection($rootNode, $willBeAvailable);
165-
$this->addSerializerSection($rootNode, $enableIfStandalone, $willBeAvailable);
165+
$this->addSerializerSection($rootNode, $enableIfStandalone);
166166
$this->addPropertyAccessSection($rootNode, $willBeAvailable);
167167
$this->addPropertyInfoSection($rootNode, $enableIfStandalone);
168168
$this->addCacheSection($rootNode, $willBeAvailable);
@@ -868,7 +868,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode, callable $e
868868
;
869869
}
870870

871-
private function addValidationSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone, callable $willBeAvailable)
871+
private function addValidationSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
872872
{
873873
$rootNode
874874
->children()
@@ -978,7 +978,7 @@ private function addAnnotationsSection(ArrayNodeDefinition $rootNode, callable $
978978
;
979979
}
980980

981-
private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone, callable $willBeAvailable)
981+
private function addSerializerSection(ArrayNodeDefinition $rootNode, callable $enableIfStandalone)
982982
{
983983
$rootNode
984984
->children()
@@ -1112,7 +1112,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode, callable $willBe
11121112
->booleanNode('public')->defaultFalse()->end()
11131113
->scalarNode('default_lifetime')
11141114
->info('Default lifetime of the pool')
1115-
->example('"600" for 5 minutes expressed in seconds, "PT5M" for five minutes expressed as ISO 8601 time interval, or "5 minutes" as a date expression')
1115+
->example('"300" for 5 minutes expressed in seconds, "PT5M" for five minutes expressed as ISO 8601 time interval, or "5 minutes" as a date expression')
11161116
->end()
11171117
->scalarNode('provider')
11181118
->info('Overwrite the setting from the default provider for this adapter.')

src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ public static function createConnection(array|string $servers, array $options =
9696
{
9797
if (\is_string($servers)) {
9898
$servers = [$servers];
99-
} elseif (!\is_array($servers)) {
100-
throw new InvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, "%s" given.', get_debug_type($servers)));
10199
}
102100
if (!static::isSupported()) {
103101
throw new CacheException('Memcached '.(\PHP_VERSION_ID >= 80100 ? '> 3.1.5' : '>= 2.2.0').' is required.');

src/Symfony/Component/Console/Exception/InvalidOptionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Console\Exception;
1313

1414
/**
15-
* Represents an incorrect option name typed in the console.
15+
* Represents an incorrect option name or value typed in the console.
1616
*
1717
* @author Jérôme Tamarelle <jerome@tamarelle.net>
1818
*/

src/Symfony/Component/Console/Helper/ProgressBar.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,13 @@ private function overwrite(string $message): void
466466
10000 }
467467
$this->output->clear($lineCount);
468468
} else {
469-
for ($i = 0; $i < $this->formatLineCount; ++$i) {
470-
$this->cursor->moveToColumn(1);
471-
$this->cursor->clearLine();
472-
$this->cursor->moveUp();
469+
if ('' !== $this->previousMessage) {
470+
// only clear upper lines when last call was not a clear
471+
for ($i = 0; $i < $this->formatLineCount; ++$i) {
472+
$this->cursor->moveToColumn(1);
473+
$this->cursor->clearLine();
474+
$this->cursor->moveUp();
475+
}
473476
}
474477

475478
$this->cursor->moveToColumn(1);

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,10 @@ public function testMultilineFormat()
812812
$this->assertEquals(
813813
">---------------------------\nfoobar".
814814
$this->generateOutput("=========>------------------\nfoobar").
815-
"\x1B[1G\x1B[2K\x1B[1A\x1B[1G\x1B[2K".
816-
$this->generateOutput("============================\nfoobar"),
815+
"\x1B[1G\x1B[2K\x1B[1A".
816+
$this->generateOutput('').
817+
$this->generateOutput('============================').
818+
"\nfoobar",
817819
stream_get_contents($output->getStream())
818820
);
819821
}
@@ -1124,4 +1126,29 @@ public function testMultiLineFormatIsFullyCleared()
11241126
stream_get_contents($output->getStream())
11251127
);
11261128
}
1129+
1130+
public function testMultiLineFormatIsFullyCorrectlyWithManuallyCleanup()
1131+
{
1132+
ProgressBar::setFormatDefinition('normal_nomax', "[%bar%]\n%message%");
1133+
$bar = new ProgressBar($output = $this->getOutputStream());
1134+
$bar->setMessage('Processing "foobar"...');
1135+
$bar->start();
1136+
$bar->clear();
1137+
$output->writeln('Foo!');
1138+
$bar->display();
1139+
$bar->finish();
1140+
1141+
rewind($output->getStream());
1142+
$this->assertEquals(
1143+
"[>---------------------------]\n".
1144+
'Processing "foobar"...'.
1145+
"\x1B[1G\x1B[2K\x1B[1A".
1146+
$this->generateOutput('').
1147+
'Foo!'.\PHP_EOL.
1148+
$this->generateOutput('[--->------------------------]').
1149+
"\nProcessing \"foobar\"...".
1150+
$this->generateOutput("[----->----------------------]\nProcessing \"foobar\"..."),
1151+
stream_get_contents($output->getStream())
1152+
);
1153+
}
11271154
}

src/Symfony/Component/HttpClient/AmpHttpClient.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Amp\Http\Client\PooledHttpClient;
1818
use Amp\Http\Client\Request;
1919
use Amp\Http\Tunnel\Http1TunnelConnector;
20+
use Amp\Promise;
2021
use Psr\Log\LoggerAwareInterface;
2122
use Psr\Log\LoggerAwareTrait;
2223
use Symfony\Component\HttpClient\Exception\TransportException;
@@ -29,7 +30,11 @@
2930
use Symfony\Contracts\Service\ResetInterface;
3031

3132
if (!interface_exists(DelegateHttpClient::class)) {
32-
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the "amphp/http-client" package is not installed. Try running "composer require amphp/http-client".');
33+
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the "amphp/http-client" package is not installed. Try running "composer require amphp/http-client:^4.2.1".');
34+
}
35+
36+
if (!interface_exists(Promise::class)) {
37+
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the installed "amphp/http-client" is not compatible with this version of "symfony/http-client". Try downgrading "amphp/http-client" to "^4.2.1".');
3338
}
3439

3540
/**

src/Symfony/Component/HttpClient/HttpClient.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpClient;
1313

1414
use Amp\Http\Client\Connection\ConnectionLimitingPool;
15+
use Amp\Promise;
1516
use Symfony\Contracts\HttpClient\HttpClientInterface;
1617

1718
/**
@@ -30,7 +31,7 @@ final class HttpClient
3031
*/
3132
public static function create(array $defaultOptions = [], int $maxHostConnections = 6, int $maxPendingPushes = 50): HttpClientInterface
3233
{
33-
if ($amp = class_exists(ConnectionLimitingPool::class)) {
34+
if ($amp = class_exists(ConnectionLimitingPool::class) && interface_exists(Promise::class)) {
3435
if (!\extension_loaded('curl')) {
3536
return new AmpHttpClient($defaultOptions, null, $maxHostConnections, $maxPendingPushes);
3637
}
@@ -61,7 +62,7 @@ public static function create(array $defaultOptions = [], int $maxHostConnection
6162
return new AmpHttpClient($defaultOptions, null, $maxHostConnections, $maxPendingPushes);
6263
}
6364

64-
@trigger_error((\extension_loaded('curl') ? 'Upgrade' : 'Install').' the curl extension or run "composer require amphp/http-client" to perform async HTTP operations, including full HTTP/2 support', \E_USER_NOTICE);
65+
@trigger_error((\extension_loaded('curl') ? 'Upgrade' : 'Install').' the curl extension or run "composer require amphp/http-client:^4.2.1" to perform async HTTP operations, including full HTTP/2 support', \E_USER_NOTICE);
6566

6667
return new NativeHttpClient($defaultOptions, $maxHostConnections);
6768
}

src/Symfony/Component/HttpKernel/DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\DependencyInjection\Reference;
2626
use Symfony\Component\DependencyInjection\TypedReference;
2727
use Symfony\Component\HttpFoundation\Request;
28+
use Symfony\Component\HttpFoundation\Response;
2829
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2930

3031
/**
@@ -154,7 +155,7 @@ public function process(ContainerBuilder $container)
154155
$invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE;
155156
}
156157

157-
if (Request::class === $type || SessionInterface::class === $type) {
158+
if (Request::class === $type || SessionInterface::class === $type || Response::class === $type) {
158159
continue;
159160
}
160161

src/Symfony/Component/HttpKernel/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\DependencyInjection\Reference;
2525
use Symfony\Component\DependencyInjection\ServiceLocator;
2626
use Symfony\Component\DependencyInjection\TypedReference;
27+
use Symfony\Component\HttpFoundation\Response;
2728
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
2829
use Symfony\Component\HttpKernel\Tests\Fixtures\Suit;
2930

@@ -443,6 +444,20 @@ public function testBindWithTarget()
443444
$this->assertEquals($expected, $locator->getArgument(0));
444445
}
445446

447+
public function testResponseArgumentIsIgnored()
448+
{
449+
$container = new ContainerBuilder();
450+
$resolver = $container->register('argument_resolver.service', 'stdClass')->addArgument([]);
451+
452+
$container->register('foo', WithResponseArgument::class)
453+
->addTag('controller.service_arguments');
454+
455+
(new RegisterControllerArgumentLocatorsPass())->process($container);
456+
457+
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
458+
$this->assertEmpty(array_keys($locator), 'Response typed argument is ignored');
459+
}
460+
446461
public function testAutowireAttribute()
447462
{
448463
if (!class_exists(Autowire::class)) {
@@ -558,6 +573,13 @@ public function fooAction(
558573
}
559574
}
560575

576+
class WithResponseArgument
577+
{
578+
public function fooAction(Response $response, ?Response $nullableResponse)
579+
{
580+
}
581+
}
582+
561583
class WithAutowireAttribute
562584
{
563585
public function fooAction(

0 commit comments

Comments
 (0)
0