mj-zana / console
Console kernel on Symfony Console with a container scope per command for Zana applications
v2.1.0
2026-10-25 20:32 UTC
Requires
- php: ^8.5
- mj-zana/core: ^2.0
- symfony/console: ^7.4 || ^8.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-25 20:42:08 UTC
README
Console commands on Symfony Console, each run in its own container scope. Requires PHP 8.5 or later.
composer require mj-zana/console
Usage
// bin/zana $app = require __DIR__ . '/../bootstrap/app.php'; // with ConsoleServiceProvider exit(Zana\Console\ConsoleKernel::runApplication($app));
#[AsCommand(name: 'bmi:report', description: 'Print the BMI report of a patient')] final class BmiReportCommand extends Command { protected function configure(): void { $this->addArgument('patient', InputArgument::REQUIRED); } public function handle(InputInterface $input, SymfonyStyle $io, MeasurementRepository $measurements): int { $io->table(['Date', 'BMI'], $measurements->rowsFor($input->getArgument('patient'))); return self::SUCCESS; // or null } }
Register commands as services tagged console.commands:
$services->transient(BmiReportCommand::class)->tag(ConsoleKernel::TAG, BmiReportCommand::class);
- Scope: every run gets a fresh scope (
ScopeMetadata::cli('bmi:report')), disposed afterwards. handle()injection: the command's dependencies are injected, plus the current input, output and aSymfonyStyle, by type.- Plain Symfony commands work too.
License
MIT — see LICENSE.