Search by

mj-zana / console

mjnable

Console kernel on Symfony Console with a container scope per command for Zana applications

Package info

github.com/mjnable/zana-console

pkg:composer/mj-zana/console

Statistics

Installs: 19

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

v2.1.0 2026-10-25 20:32 UTC

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 a SymfonyStyle, by type.
  • Plain Symfony commands work too.

License

MIT — see LICENSE.