https://github.com/phpnomad/symfony-console-integration
Symfony Console integration for building nomadic CLI commands in PHPNomad
https://github.com/phpnomad/symfony-console-integration
cli console framework integration php phpnomad platform-agnostic symfony
Last synced: 6 days ago
JSON representation
Symfony Console integration for building nomadic CLI commands in PHPNomad
- Host: GitHub
- URL: https://github.com/phpnomad/symfony-console-integration
- Owner: phpnomad
- License: mit
- Created: 2025-04-16T20:39:23.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-05-26T17:34:35.000Z (11 days ago)
- Last Synced: 2026-05-26T19:18:15.958Z (11 days ago)
- Topics: cli, console, framework, integration, php, phpnomad, platform-agnostic, symfony
- Language: PHP
- Homepage: https://phpnomad.com
- Size: 50.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# phpnomad/symfony-console-integration
[](https://packagist.org/packages/phpnomad/symfony-console-integration)
[](https://packagist.org/packages/phpnomad/symfony-console-integration)
[](https://packagist.org/packages/phpnomad/symfony-console-integration)
[](https://packagist.org/packages/phpnomad/symfony-console-integration)
Integrates [Symfony Console](https://symfony.com/doc/current/components/console.html) with PHPNomad's console abstraction. Your commands implement `phpnomad/console`'s `Command` interface and declare their arguments through PHPNomad's signature syntax. This package parses those signatures, registers the commands with a Symfony `Application`, and runs `handle()` through any declared middleware and interceptors. Your command classes never reference Symfony directly.
## Installation
```bash
composer require phpnomad/symfony-console-integration
```
## What This Provides
- `ConsoleStrategy` parses a PHPNomad signature into Symfony `InputArgument` and `InputOption` definitions, wraps the command in an anonymous Symfony `Command` subclass, and runs `handle()` through any `HasMiddleware` and `HasInterceptors` hooks. `ConsoleException` failures are logged via `LoggerStrategy` and surfaced through `OutputStrategy::error()` with exit code 1.
- `ConsoleOutputStrategy` maps `writeln`, `info`, `success`, `warning`, `error`, `newline`, and `table` onto a Symfony `OutputInterface` with blue, green, yellow, and red formatter styles.
- `Input` wraps a Symfony `InputInterface` behind PHPNomad's `Input` contract, with an override map so middleware can mutate values without touching the Symfony request.
- `Initializer` is a `phpnomad/loader` initializer that binds the strategies to their PHPNomad interfaces and provides a singleton Symfony `OutputInterface` (a `ConsoleOutput` with the default formatter).
## Requirements
- `phpnomad/console`, the contract this package implements
- `symfony/console` ^7.2, the library this package bridges
- `phpnomad/logger` for exception logging inside the command wrapper
- `phpnomad/utils` and `phpnomad/loader` for bootstrapping
## Usage
Bind a Symfony `Application` into your container, pass this package's `Initializer` to your `Bootstrapper` alongside any initializer that declares commands via `HasCommands`, then call `run()` on the resolved `ConsoleStrategy`:
```php
bindSingletonFromFactory(
Application::class,
fn() => new Application('MyApp CLI')
);
$bootstrapper = new Bootstrapper(
$container,
new SymfonyConsoleInitializer(),
new CommandsInitializer()
);
$bootstrapper->load();
$container->get(ConsoleStrategy::class)->run();
```
`CommandsInitializer` is any class implementing `HasCommands`. Its `getCommands()` returns an array of command class names, and the loader registers each one automatically. Each command class implements `Command`, with `getSignature()` returning a string like `widget:create {name:The widget name} {--force}` and `handle(Input $input)` running the work.
## Documentation
PHPNomad documentation lives at [phpnomad.com](https://phpnomad.com). For the underlying library, see the [Symfony Console documentation](https://symfony.com/doc/current/components/console.html).
## License
Licensed under the [MIT License](LICENSE.txt).