You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: UPGRADE-8.0.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,66 @@ release process, both versions have the same features, but Symfony 8.0 doesn't i
6
6
To upgrade, make sure to resolve all deprecation notices.
7
7
Read more about this in the [Symfony documentation](https://symfony.com/doc/8.0/setup/upgrade_major.html).
8
8
9
+
Console
10
+
-------
11
+
12
+
* Remove methods `Command::getDefaultName()` and `Command::getDefaultDescription()` in favor of the `#[AsCommand]` attribute
13
+
14
+
*Before*
15
+
```php
16
+
use Symfony\Component\Console\Command\Command;
17
+
18
+
class CreateUserCommand extends Command
19
+
{
20
+
public static function getDefaultName(): ?string
21
+
{
22
+
return 'app:create-user';
23
+
}
24
+
25
+
public static function getDefaultDescription(): ?string
26
+
{
27
+
return 'Creates users';
28
+
}
29
+
30
+
// ...
31
+
}
32
+
```
33
+
34
+
*After*
35
+
```php
36
+
use Symfony\Component\Console\Attribute\AsCommand;
37
+
use Symfony\Component\Console\Command\Command;
38
+
39
+
#[AsCommand('app:create-user', 'Creates users')]
40
+
class CreateUserCommand
41
+
{
42
+
// ...
43
+
}
44
+
```
45
+
46
+
* Ensure closures set via `Command::setCode()` method have proper parameter and return types
47
+
48
+
*Before*
49
+
```php
50
+
$command->setCode(function ($input, $output) {
51
+
// ...
52
+
});
53
+
```
54
+
55
+
*After*
56
+
```php
57
+
use Symfony\Component\Console\Input\InputInterface;
58
+
use Symfony\Component\Console\Output\OutputInterface;
59
+
60
+
$command->setCode(function (InputInterface $input, OutputInterface $output): int {
Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Command/Command.php
+2-44Lines changed: 2 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -54,34 +54,6 @@ class Command implements SignalableCommandInterface
54
54
privatearray$usages = [];
55
55
private ?HelperSet$helperSet = null;
56
56
57
-
/**
58
-
* @deprecated since Symfony 7.3, use the #[AsCommand] attribute instead
59
-
*/
60
-
publicstaticfunctiongetDefaultName(): ?string
61
-
{
62
-
trigger_deprecation('symfony/console', '7.3', 'Method "%s()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', __METHOD__);
63
-
64
-
if ($attribute = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) {
65
-
return$attribute[0]->newInstance()->name;
66
-
}
67
-
68
-
returnnull;
69
-
}
70
-
71
-
/**
72
-
* @deprecated since Symfony 7.3, use the #[AsCommand] attribute instead
trigger_deprecation('symfony/console', '7.3', 'Method "%s()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', __METHOD__);
77
-
78
-
if ($attribute = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) {
79
-
return$attribute[0]->newInstance()->description;
80
-
}
81
-
82
-
returnnull;
83
-
}
84
-
85
57
/**
86
58
* @param string|null $name The name of the command; passing null means it must be set in configure()
87
59
*
@@ -94,13 +66,7 @@ public function __construct(?string $name = null)
if (self::class !== (new \ReflectionMethod($this, 'getDefaultName'))->class) {
98
-
trigger_deprecation('symfony/console', '7.3', 'Overriding "Command::getDefaultName()" in "%s" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', static::class);
@@ -119,15 +85,7 @@ public function __construct(?string $name = null)
119
85
}
120
86
121
87
if ('' === $this->description) {
122
-
if (self::class !== (new \ReflectionMethod($this, 'getDefaultDescription'))->class) {
123
-
trigger_deprecation('symfony/console', '7.3', 'Overriding "Command::getDefaultDescription()" in "%s" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', static::class);
trigger_deprecation('symfony/console', '7.3', \sprintf('Returning a non-integer value from the command "%s" is deprecated and will throw an exception in Symfony 8.0.', $this->command->getName()));
57
-
58
-
return0;
59
-
}
60
-
61
54
thrownew \TypeError(\sprintf('The command "%s" must return an integer value in the "%s" method, but "%s" was returned.', $this->command->getName(), $this->reflection->getName(), get_debug_type($statusCode)));
62
55
}
63
56
@@ -87,8 +80,6 @@ private function getClosure(callable $code): \Closure
87
80
return$code(...);
88
81
}
89
82
90
-
$this->triggerDeprecations = true;
91
-
92
83
if (null !== (new \ReflectionFunction($code))->getClosureThis()) {
93
84
return$code;
94
85
}
@@ -124,12 +115,6 @@ private function getParameters(InputInterface $input, OutputInterface $output):
124
115
$type = $parameter->getType();
125
116
126
117
if (!$typeinstanceof \ReflectionNamedType) {
127
-
if ($this->triggerDeprecations) {
128
-
trigger_deprecation('symfony/console', '7.3', \sprintf('Omitting the type declaration for the parameter "$%s" is deprecated and will throw an exception in Symfony 8.0.', $parameter->getName()));
129
-
130
-
continue;
131
-
}
132
-
133
118
thrownewLogicException(\sprintf('The parameter "$%s" must have a named type. Untyped, Union or Intersection types are not supported.', $parameter->getName()));
if (Command::class !== (new \ReflectionMethod($class, 'getDefaultName'))->class) {
66
-
trigger_deprecation('symfony/console', '7.3', 'Overriding "Command::getDefaultName()" in "%s" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', $class);
if (Command::class !== (new \ReflectionMethod($class, 'getDefaultDescription'))->class) {
129
-
trigger_deprecation('symfony/console', '7.3', 'Overriding "Command::getDefaultDescription()" in "%s" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.', $class);
$this->expectUserDeprecationMessage('Since symfony/console 7.3: Method "Symfony\Component\Console\Command\Command::getDefaultName()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.');
457
-
$this->expectUserDeprecationMessage('Since symfony/console 7.3: Method "Symfony\Component\Console\Command\Command::getDefaultDescription()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.');
$this->expectUserDeprecationMessage('Since symfony/console 7.3: Method "Symfony\Component\Console\Command\Command::getDefaultName()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.');
477
-
$this->expectUserDeprecationMessage('Since symfony/console 7.3: Method "Symfony\Component\Console\Command\Command::getDefaultDescription()" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.');
$this->expectUserDeprecationMessage('Since symfony/console 7.3: Overriding "Command::getDefaultName()" in "Symfony\Component\Console\Tests\Command\FooCommand" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.');
503
-
$this->expectUserDeprecationMessage('Since symfony/console 7.3: Overriding "Command::getDefaultDescription()" in "Symfony\Component\Console\Tests\Command\FooCommand" is deprecated and will be removed in Symfony 8.0, use the #[AsCommand] attribute instead.');
$this->expectUserDeprecationMessage('Since symfony/console 7.3: Returning a non-integer value from the command "foo" is deprecated and will throw an exception in Symfony 8.0.');
0 commit comments