sanmai / console
Ready-made extensible console application using Symfony Console component
Fund package maintenance!
sanmai
Requires
- php: >=8.2
- sanmai/later: ^0.1.7
- sanmai/pipeline: ^6.17
- sanmai/version-info: ^0.2
- symfony/console: ^6.0 || ^7.0
Requires (Dev)
- composer/composer: ^2.2
- ergebnis/composer-normalize: ^2.8
- friendsofphp/php-cs-fixer: ^3.17
- infection/infection: >=0.29
- league/pipeline: ^0.3 || ^1.0
- php-coveralls/php-coveralls: ^2.4.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2
- phpunit/phpunit: >=9.4 <12
- symfony/process: ^7.3
- vimeo/psalm: >=2
This package is auto-updated.
Last update: 2025-06-27 12:24:32 UTC
README
Zero-configuration console executable that auto-discovers your Symfony Console commands.
Requirements
- Composer with optimized autoloader (
composer dump-autoload --optimize
)
Installation
composer require sanmai/console composer dump-autoload --optimize
Why --optimize? This library discovers commands by scanning Composer's classmap, which requires an optimized autoloader. This is the trade-off for zero-configuration simplicity.
Quick Start
- Create a Symfony Console command:
<?php // src/Commands/HelloCommand.php namespace App\Commands; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'hello', description: 'Says hello' )] class HelloCommand extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('Hello, World!'); return Command::SUCCESS; } }
- Update the autoloader:
composer dump-autoload --optimize
- Run your command:
vendor/bin/console hello
That's it! No configuration files, no manual command registration. Just create command files and they're automatically discovered.
How It Works
This library provides a ready-made vendor/bin/console
executable that automatically discovers all Symfony Console commands in your project by:
- Scanning Composer's optimized classmap
- Finding classes that end with
Command.php
- Loading those that extend
Symfony\Component\Console\Command\Command
- Filtering out vendored files
The Problem It Solves
Even with Symfony's built-in command discovery, you still need to:
- Create a console executable file (e.g.,
bin/console
) - Set up the Application instance
- Configure command discovery
- Make the file executable
With sanmai/console
, you get a ready-made vendor/bin/console
executable installed via Composer. No files to create, no permissions to set - just install the package and vendor/bin/console
is ready to use.
Troubleshooting
Commands not showing up?
- Ensure you ran
composer dump-autoload --optimize
- Verify your command files end with
Command.php
- Check that commands extend
Symfony\Component\Console\Command\Command
- Commands in
vendor/
are ignored by design
Testing
vendor/bin/phpunit