Skip to content

Commit f12a419

Browse files
Merge branch '5.3' into 5.4
* 5.3: [Console] Fix using #[AsCommand] without DI [DependencyInjection] fix parsing classes for attributes [HttpClient] fix compat with cURL <= 7.37 [Console] fix managing signals when commands are lazy loaded Remove Debug component from patch-types.php [Uid] Realign inspect commands labels [Runtime] fix overriding --env|-e with single-command apps [Serializer] Fix call to expectExceptionMessage() [Config] fix tracking attributes in ReflectionClassResource [Process] Fix incorrect parameter type [HttpFoundation] Handle tentative return types
2 parents 2a3c003 + 414c78b commit f12a419

27 files changed

+241
-127
lines changed

.github/patch-types.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadFileName.php'):
2020
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/BadParent.php'):
2121
case false !== strpos($file, '/src/Symfony/Component/Config/Tests/Fixtures/ParseError.php'):
22-
case false !== strpos($file, '/src/Symfony/Component/Debug/Tests/Fixtures/'):
2322
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Compiler/OptionalServiceClass.php'):
2423
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/autowiring_classes.php'):
2524
case false !== strpos($file, '/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/MultipleArgumentsOptionalScalarNotReallyOptional.php'):

src/Symfony/Component/Config/Resource/ReflectionClassResource.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ private function computeHash(): string
121121

122122
private function generateSignature(\ReflectionClass $class): iterable
123123
{
124+
if (\PHP_VERSION_ID >= 80000) {
125+
$attributes = [];
126+
foreach ($class->getAttributes() as $a) {
127+
$attributes[] = [$a->getName(), $a->getArguments()];
128+
}
129+
yield print_r($attributes, true);
130+
$attributes = [];
131+
}
132+
124133
yield $class->getDocComment();
125134
yield (int) $class->isFinal();
126135
yield (int) $class->isAbstract();
@@ -137,6 +146,14 @@ private function generateSignature(\ReflectionClass $class): iterable
137146
$defaults = $class->getDefaultProperties();
138147

139148
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) {
149+
if (\PHP_VERSION_ID >= 80000) {
150+
foreach ($p->getAttributes() as $a) {
151+
$attributes[] = [$a->getName(), $a->getArguments()];
152+
}
153+
yield print_r($attributes, true);
154+
$attributes = [];
155+
}
156+
140157
yield $p->getDocComment();
141158
yield $p->isDefault() ? '<default>' : '';
142159
yield $p->isPublic() ? 'public' : 'protected';
@@ -147,9 +164,25 @@ private function generateSignature(\ReflectionClass $class): iterable
147164
}
148165

149166
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) {
167+
if (\PHP_VERSION_ID >= 80000) {
168+
foreach ($m->getAttributes() as $a) {
169+
$attributes[] = [$a->getName(), $a->getArguments()];
170+
}
171+
yield print_r($attributes, true);
172+
$attributes = [];
173+
}
174+
150175
$defaults = [];
151176
$parametersWithUndefinedConstants = [];
152177
foreach ($m->getParameters() as $p) {
178+
if (\PHP_VERSION_ID >= 80000) {
179+
foreach ($p->getAttributes() as $a) {
180+
$attributes[] = [$a->getName(), $a->getArguments()];
181+
}
182+
yield print_r($attributes, true);
183+
$attributes = [];
184+
}
185+
153186
if (!$p->isDefaultValueAvailable()) {
154187
$defaults[$p->name] = null;
155188

src/Symfony/Component/Config/Tests/Resource/ReflectionClassResourceTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public function provideHashedSignature(): iterable
121121
{
122122
yield [false, 0, "// line change\n\n"];
123123
yield [true, 0, '/** class docblock */'];
124+
125+
if (\PHP_VERSION_ID >= 80000) {
126+
yield [true, 0, '#[Foo]'];
127+
}
128+
124129
yield [true, 1, 'abstract class %s'];
125130
yield [true, 1, 'final class %s'];
126131
yield [true, 1, 'class %s extends Exception'];
@@ -140,6 +145,12 @@ public function provideHashedSignature(): iterable
140145
yield [false, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"];
141146
yield [true, 12, '/** prot docblock */'];
142147
yield [true, 13, 'protected function prot($a = [123]) {}'];
148+
149+
if (\PHP_VERSION_ID >= 80000) {
150+
yield [true, 13, '#[Foo] protected function prot($a = []) {}'];
151+
yield [true, 13, 'protected function prot(#[Foo] $a = []) {}'];
152+
}
153+
143154
yield [false, 14, '/** priv docblock */'];
144155
yield [false, 15, ''];
145156

src/Symfony/Component/Console/Application.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ public function doRun(InputInterface $input, OutputInterface $output)
287287
$command = $this->find($alternative);
288288
}
289289

290+
if ($command instanceof LazyCommand) {
291+
$command = $command->getCommand();
292+
}
293+
290294
$this->runningCommand = $command;
291295
$exitCode = $this->doRunCommand($command, $input, $output);
292296
$this->runningCommand = null;

src/Symfony/Component/Console/Command/Command.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,18 @@ public function __construct(string $name = null)
101101
{
102102
$this->definition = new InputDefinition();
103103

104-
if (null !== $name || null !== $name = static::getDefaultName()) {
104+
if (null === $name && null !== $name = static::getDefaultName()) {
105+
$aliases = explode('|', $name);
106+
107+
if ('' === $name = array_shift($aliases)) {
108+
$this->setHidden(true);
109+
$name = array_shift($aliases);
110+
}
111+
112+
$this->setAliases($aliases);
113+
}
114+
115+
if (null !== $name) {
105116
$this->setName($name);
106117
}
107118

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Console\Application;
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Command\HelpCommand;
18+
use Symfony\Component\Console\Command\LazyCommand;
1819
use Symfony\Component\Console\Command\SignalableCommandInterface;
1920
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
2021
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
@@ -1672,7 +1673,7 @@ public function testRunLazyCommandService()
16721673
$container = new ContainerBuilder();
16731674
$container->addCompilerPass(new AddConsoleCommandPass());
16741675
$container
1675-
->register('lazy-command', LazyCommand::class)
1676+
->register('lazy-command', LazyTestCommand::class)
16761677
->addTag('console.command', ['command' => 'lazy:command'])
16771678
->addTag('console.command', ['command' => 'lazy:alias'])
16781679
->addTag('console.command', ['command' => 'lazy:alias2']);
@@ -1847,7 +1848,7 @@ public function testSignal()
18471848
$application->setAutoExit(false);
18481849
$application->setDispatcher($dispatcher);
18491850
$application->setSignalsToDispatchEvent(\SIGALRM);
1850-
$application->add($command);
1851+
$application->add(new LazyCommand('signal', [], '', false, function () use ($command) { return $command; }, true));
18511852

18521853
$this->assertFalse($command->signaled);
18531854
$this->assertFalse($dispatcherCalled);
@@ -1902,7 +1903,7 @@ public function __construct()
19021903
}
19031904
}
19041905

1905-
class LazyCommand extends Command
1906+
class LazyTestCommand extends Command
19061907
{
19071908
public function execute(InputInterface $input, OutputInterface $output): int
19081909
{

src/Symfony/Component/Console/Tests/Command/CommandTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ public function testCommandAttribute()
414414
{
415415
$this->assertSame('|foo|f', Php8Command::getDefaultName());
416416
$this->assertSame('desc', Php8Command::getDefaultDescription());
417+
418+
$command = new Php8Command();
419+
420+
$this->assertSame('foo', $command->getName());
421+
$this->assertSame('desc', $command->getDescription());
422+
$this->assertTrue($command->isHidden());
423+
$this->assertSame(['f'], $command->getAliases());
417424
}
418425
}
419426

src/Symfony/Component/DependencyInjection/Compiler/RegisterAutoconfigureAttributesPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function process(ContainerBuilder $container)
3636
}
3737

3838
foreach ($container->getDefinitions() as $id => $definition) {
39-
if ($this->accept($definition) && null !== $class = $container->getReflectionClass($definition->getClass())) {
39+
if ($this->accept($definition) && $class = $container->getReflectionClass($definition->getClass(), false)) {
4040
$this->processClass($container, $class);
4141
}
4242
}

src/Symfony/Component/DependencyInjection/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function registerClasses(Definition $prototype, string $namespace, string
105105
$serializedPrototype = serialize($prototype);
106106

107107
foreach ($classes as $class => $errorMessage) {
108-
if ($autoconfigureAttributes && $this->env) {
108+
if (null === $errorMessage && $autoconfigureAttributes && $this->env) {
109109
$r = $this->container->getReflectionClass($class);
110110
$attribute = null;
111111
foreach ($r->getAttributes(When::class) as $attribute) {

src/Symfony/Component/DependencyInjection/Tests/Compiler/RegisterAutoconfigureAttributesPassTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\Reference;
2020
use Symfony\Component\DependencyInjection\Tests\Fixtures\AutoconfigureAttributed;
2121
use Symfony\Component\DependencyInjection\Tests\Fixtures\AutoconfiguredInterface;
22+
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
2223

2324
/**
2425
* @requires PHP 8
@@ -78,4 +79,16 @@ public function testAutoconfiguredTag()
7879
;
7980
$this->assertEquals([AutoconfiguredInterface::class => $expected], $container->getAutoconfiguredInstanceof());
8081
}
82+
83+
public function testMissingParent()
84+
{
85+
$container = new ContainerBuilder();
86+
87+
$definition = $container->register(ParentNotExists::class, ParentNotExists::class)
88+
->setAutoconfigured(true);
89+
90+
(new RegisterAutoconfigureAttributesPass())->process($container);
91+
92+
$this->addToAssertionCount(1);
93+
}
8194
}

0 commit comments

Comments
 (0)