Skip to main content
Winter Boot ships two stereotypes for building command-line applications on top of the same DI container the rest of your services use. Any class marked with #[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:
  • string
  • int
  • float
  • bool
Any other type throws a 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 of WinterWebSwooleApplication, run the command bean under WinterCliApplication. It boots the same container (modules, beans, #[OnApplicationReady] hooks) without starting the HTTP server.
bin/myapp.php