Skip to content

Commit bd126f6

Browse files
committed
updated based on review
Signed-off-by: bidi <bidi@apidemia.com>
1 parent 170333e commit bd126f6

7 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Dates before 4.0.0 are the commit dates of the tagged commits.
1919
- `ApplicationFactory::__invoke()` returns `Dot\Cli\Application`.
2020
- The `MESSAGE_*` constants are typed (`public const string`).
2121
- `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.
2223
- 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.
2324
- Documentation for 4.0 is available in `docs/book/v4`, including an upgrade guide from 3.x.
2425

@@ -37,7 +38,6 @@ Dates before 4.0.0 are the commit dates of the tagged commits.
3738

3839
- PHP 8.2 support.
3940
- `laminas/laminas-servicemanager` as a requirement. dot-cli only uses PSR-11; applications that use Laminas Service Manager require it themselves.
40-
- `DemoCommand::$defaultName` and `DemoCommand::configure()`. The name and description come from the `#[AsCommand]` attribute.
4141
- `mikey179/vfsstream` as a development requirement. Lock tests use a real temporary directory.
4242

4343
### Fixed

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"laminas/laminas-coding-standard": "^3.0",
3939
"phpstan/phpstan": "^2.1.17",
4040
"phpstan/phpstan-phpunit": "^2.0.6",
41-
"phpunit/phpunit": "^12"
41+
"phpunit/phpunit": "^12.5"
4242
},
4343
"conflict": {
4444
"symfony/event-dispatcher-contracts": "<2.5.3 || >=3.0,<3.5"

‎config/autoload/cli.global.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'version' => '1.0.0',
1111
'name' => 'Dotkernel CLI',
1212
'commands' => [
13-
'demo:command' => DemoCommand::class,
13+
DemoCommand::$defaultName => DemoCommand::class,
1414
],
1515
],
1616
FileLockerInterface::class => [

‎docs/book/v4/upgrading.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Most applications only need to update the `commands` keys in `config/autoload/cl
99
| --- | --- | --- |
1010
| PHP 8.2 is no longer supported | Composer refuses to install 4.0 | Use PHP 8.3 or newer, or stay on 3.x |
1111
| `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` and `DemoCommand::configure()` were removed | 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) |
12+
| 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) |
1313
| 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) |
1414
| 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 |
1515
| Aliases and abbreviations of a command share its lock | `demo:com` or an alias is rejected while `demo:command` runs | This is intended. Give commands that must run in parallel their own names |
@@ -38,7 +38,9 @@ After:
3838
],
3939
```
4040

41-
If one of your own commands still sets `protected static $defaultName`, move the name to the `#[AsCommand]` attribute and remove the property.
41+
If one of your own commands still sets `protected static $defaultName`, move the name to the `#[AsCommand]` attribute.
42+
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).
4244

4345
## Event dispatcher
4446

‎docs/book/v4/usage.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Usage
22

33
Use `src/Command/DemoCommand.php` as an example when creating a new command.
4-
Set the name and description in the `#[AsCommand]` attribute: the command needs no `$defaultName` property and no `configure()` call to set them.
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.
5+
6+
`DemoCommand` also implements `configure()` to show where a command can be extended by chaining methods, for example `setHelp()`, `addArgument()` and `addOption()`.
7+
For the demo, its `configure()` sets the same name and description as the attribute.
8+
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.
510

611
```php
712
<?php

‎src/Command/DemoCommand.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
)]
1616
class DemoCommand extends Command
1717
{
18+
public static string $defaultName = 'demo:command';
19+
20+
protected function configure(): void
21+
{
22+
$this
23+
->setName(self::$defaultName)
24+
->setDescription('Demo command description.');
25+
}
26+
1827
protected function execute(InputInterface $input, OutputInterface $output): int
1928
{
2029
return Command::SUCCESS;

‎test/Command/DemoCommandTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class DemoCommandTest extends TestCase
1313
{
14-
public function testNameAndDescriptionComeFromTheAttribute(): void
14+
public function testHasNameAndDescription(): void
1515
{
1616
$command = new DemoCommand();
1717

0 commit comments

Comments
 (0)