Skip to content

Console & workflows ​

bin/console is 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 fixtures

Tab-completion via Symfony CLI is nice when you install it.

Custom commands ​

bash
php bin/console make:command App\\Command\\SendDigestCommand
php
<?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 ​

JobPrefer
One-off data fixCommand
Nightly digestCommand (+ Messenger later)
User-facing CRUDController

Next: config, env, and where secrets live.

Best,

-- ł.

Continues after /lab/php-tutorial-for-fe-devs/