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
{{ message }}
Repository navigation
Commit 4cc7bb7
Browse filesBrowse the repository at this point in the historyBrowse files
- The `MESSAGE_*` constants are typed (`public const string`).
21
-
-`config/autoload/cli.global.php` uses the command name as the key instead of `DemoCommand::getDefaultName()`, which Symfony Console 8 removed.
22
-
-`DemoCommand::$defaultName` is typed as `string`. `DemoCommand` keeps it and `configure()` as a demo of extending a command; Symfony Console reads the name and description from the `#[AsCommand]` attribute.
23
-
- Development tooling: PHPUnit 12 with strict `failOn*` flags, PHPStan level 8, GitHub Actions run PHP 8.3 to 8.6 with `actions/checkout@v7`, `actions/cache@v6` and `codecov/codecov-action@v7`, and the Laminas backward-compatibility check is disabled for this major version.
22
+
-`config/autoload/cli.global.php` uses `DemoCommand::DEFAULT_NAME` as the key instead of `DemoCommand::getDefaultName()`, which Symfony Console 8 removed.
23
+
-The `#[AsCommand]` attribute of `DemoCommand` reads its name from `DemoCommand::DEFAULT_NAME`. `DemoCommand` keeps `configure()` as a demo of extending a command.
24
+
- Development tooling: PHPUnit 12 with strict `failOn*` flags, PHPStan level 8, GitHub Actions run PHP 8.3 to 8.6 with `actions/checkout@v7`, `actions/cache@v6` and `codecov/codecov-action@v7`.
24
25
- Documentation for 4.0 is available in `docs/book/v4`, including an upgrade guide from 3.x.
25
26
26
27
### Added
27
28
28
29
-`Dot\Cli\Exception\ExceptionInterface`, `Dot\Cli\Exception\RuntimeException` and `Dot\Cli\Exception\InvalidConfigException`.
29
30
-`ApplicationFactory::EVENT_DISPATCHER` and `ApplicationFactory::LEGACY_EVENT_DISPATCHER`.
30
31
-`psr/container`, `symfony/console` and `symfony/event-dispatcher` as direct requirements.
32
+
- A conflict with `symfony/event-dispatcher-contracts` versions before 2.5.3 and from 3.0 to 3.4. In those versions, `EventDispatcherInterface::dispatch()` has an implicitly nullable parameter, which PHP 8.4 and newer report as deprecated.
31
33
- Tests with a minimal PSR-11 container and a real temporary directory, covering lock contention, aliases, abbreviations, quiet output and the event dispatcher keys.
32
34
33
35
### Deprecated
@@ -38,6 +40,7 @@ Dates before 4.0.0 are the commit dates of the tagged commits.
38
40
39
41
- PHP 8.2 support.
40
42
-`laminas/laminas-servicemanager` as a requirement. dot-cli only uses PSR-11; applications that use Laminas Service Manager require it themselves.
43
+
-`DemoCommand::$defaultName`. Use `DemoCommand::DEFAULT_NAME`.
41
44
-`mikey179/vfsstream` as a development requirement. Lock tests use a real temporary directory.
Copy file name to clipboardExpand all lines: docs/book/v4/upgrading.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ Most applications only need to update the `commands` keys in `config/autoload/cl
9
9
| --- | --- | --- |
10
10
| PHP 8.2 is no longer supported | Composer refuses to install 4.0 | Use PHP 8.3 or newer, or stay on 3.x |
11
11
|`laminas/laminas-servicemanager` is no longer required |`Class "Laminas\ServiceManager\ServiceManager" not found` if your application relied on dot-cli to install it | Run `composer require laminas/laminas-servicemanager` in your application |
12
+
|`DemoCommand::$defaultName` was replaced by the `DemoCommand::DEFAULT_NAME` constant | A subclass that reads `static::$defaultName` fails with `Access to undeclared static property`| Read `DemoCommand::DEFAULT_NAME`|
12
13
| The shipped config no longer uses `DemoCommand::getDefaultName()` as a key | A config key such as `DemoCommand::getDefaultName()` fails with `Call to undefined method` on Symfony Console 8 | Use the command name as the key, see [below](#command-keys)|
13
14
| The event dispatcher service key is now `Laminas\Cli\SymfonyEventDispatcher`| None yet: the old key still works, but it is deprecated | Rename the service key, see [below](#event-dispatcher)|
14
15
| A service under the event dispatcher key must implement `Symfony\Component\EventDispatcher\EventDispatcherInterface`|`Dot\Cli\Exception\InvalidConfigException` when the application is created | Register a Symfony event dispatcher under that key |
@@ -34,13 +35,17 @@ After:
34
35
35
36
```php
36
37
'commands' => [
37
-
'demo:command' => DemoCommand::class,
38
+
DemoCommand::DEFAULT_NAME => DemoCommand::class,
38
39
],
39
40
```
40
41
41
-
If one of your own commands still sets `protected static $defaultName`, move the name to the `#[AsCommand]` attribute.
42
+
The `DemoCommand::DEFAULT_NAME` constant replaces the `DemoCommand::$defaultName` property.
43
+
A subclass of `DemoCommand` that reads `static::$defaultName` fails with `Access to undeclared static property`.
44
+
Read `DemoCommand::DEFAULT_NAME` instead.
45
+
46
+
If one of your own commands still sets `protected static $defaultName`, replace it with a `DEFAULT_NAME` constant and use the constant in the `#[AsCommand]` attribute.
42
47
Symfony Console 7.4 and 8 do not read the property, so it no longer names the command.
43
-
`DemoCommand` keeps it, typed as `string`, together with `configure()`, only to demonstrate both, see [Usage](usage.md).
Copy file name to clipboardExpand all lines: docs/book/v4/usage.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,13 @@
1
1
# Usage
2
2
3
3
Use `src/Command/DemoCommand.php` as an example when creating a new command.
4
-
Set the name and description in the `#[AsCommand]` attribute: Symfony Console reads them from there, so a command needs neither a `$defaultName` property nor a `configure()` method to set them.
4
+
Set the name and description in the `#[AsCommand]` attribute: Symfony Console reads them from there, so a command does not need a `configure()` method to set them.
5
+
Keep the name in a `DEFAULT_NAME` class constant, and use the constant in the attribute and in `config/autoload/cli.global.php`.
6
+
Then the command name is written in one place only.
5
7
6
8
`DemoCommand` also implements `configure()` to show where a command can be extended by chaining methods, for example `setHelp()`, `addArgument()` and `addOption()`.
7
9
For the demo, its `configure()` sets the same name and description as the attribute.
8
10
Values set in `configure()` override the attribute, so if you keep both in your own command, keep them identical.
9
-
Symfony Console 7.4 and 8 do not read the `$defaultName` property: it is only there for the demo.
10
11
11
12
```php
12
13
<?php
@@ -21,11 +22,13 @@ use Symfony\Component\Console\Input\InputInterface;
21
22
use Symfony\Component\Console\Output\OutputInterface;
22
23
23
24
#[AsCommand(
24
-
name: 'app:example',
25
+
name: ExampleCommand::DEFAULT_NAME,
25
26
description: 'Example command description.',
26
27
)]
27
28
class ExampleCommand extends Command
28
29
{
30
+
public const string DEFAULT_NAME = 'app:example';
31
+
29
32
protected function execute(InputInterface $input, OutputInterface $output): int
30
33
{
31
34
$output->writeln('Hello from app:example');
@@ -39,7 +42,7 @@ Then register it in `config/autoload/cli.global.php`:
0 commit comments