Console & workflows
bin/consoleis Artisan's twin. Generators, cache clears, debug dumpers - muscle memory lives here.
Everyday commands
bash
php bin/console list
php bin/console about
php bin/console debug:router
php bin/console debug:container SomeType
php bin/console cache:clear
php bin/console make:controller
php bin/console make:entity
php bin/console doctrine:migrations:migrate
php bin/console doctrine:fixtures:load # if you installed fixturesTab-completion via Symfony CLI is nice when you install it.
Custom commands
bash
php bin/console make:command App\\Command\\SendDigestCommandphp
<?php
namespace App\Command;
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: 'app:send-digest')]
class SendDigestCommand extends Command
{
public function __construct(
// inject services here
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$output->writeln('Sending digest…');
return Command::SUCCESS;
}
}Comments for the code above:
- Auto-registration via attribute / services config
- Return
SUCCESS/FAILURE- like process exit codes - Same DI as controllers - cron jobs become boring PHP 🙌
When to use console vs HTTP
| Job | Prefer |
|---|---|
| One-off data fix | Command |
| Nightly digest | Command (+ Messenger later) |
| User-facing CRUD | Controller |
Next: config, env, and where secrets live.
Best,
-- ł.