#[Command] becomes a first-class bean, its properties can be typed CLI arguments via #[CommandArg], and the whole thing runs under WinterCliApplication instead of the Swoole HTTP runner.
The CLI programming model is stable at the attribute level, but higher-level docs and examples for command dispatch have not yet been published upstream. The definitive reference is the source under
src/stereotype/cli/ and the WinterCliApplication class.The #[Command] attribute
Apply #[Command] to a class to register it as a CLI command bean.
src/cli/MigrateCommand.php
Constructor parameters
The #[CommandArg] attribute
Apply #[CommandArg] to a property to bind it to a named CLI argument. The framework infers the argument type from the property’s PHP type hint.
Constructor parameters
Supported property types
#[CommandArg] only accepts scalar property types. The following are valid:
stringintfloatbool
TypeError at container startup.
If optionsProvider is set, the class name must implement dev\winterframework\core\data\provider\OptionsProvider, or the framework raises a TypeError.
Running as a CLI application
Instead ofWinterWebSwooleApplication, run the command bean under WinterCliApplication. It boots the same container (modules, beans, #[OnApplicationReady] hooks) without starting the HTTP server.
bin/myapp.php
Related pages
- Application lifecycle covers boot ordering and
#[OnApplicationReady], which fires the same way for CLI and web apps. - Dependency injection applies to command classes:
#[Autowired]any service you need. - SQL migrations and OpenSearch migrations ship a ready-to-use CLI (
bin/migrate.php) built with the same model.