Technical Entry Level

How do you build console commands in Symfony? Discuss argument/option handling, interactive input, progress bars, and when to use commands versus controllers.

Quick Tip

Show good structure: "My commands are thin — they parse input, call a service, and format output with SymfonyStyle. The business logic lives in the service so it can be reused by controllers and tested independently."

What good answers include

Console commands extend Command or use the #[AsCommand] attribute. Define arguments (required positional values) and options (optional flags) in configure(). Use SymfonyStyle for formatted output, progress bars for long operations, and the QuestionHelper for interactive input. Commands are ideal for: scheduled tasks (cron), data migrations, maintenance operations, and developer tooling. Controllers handle HTTP requests. Strong candidates discuss: lazy command loading for performance, command locking to prevent parallel execution, injecting services via the constructor, and writing testable commands by keeping logic in services.

What interviewers are looking for

Tests practical Symfony development. Candidates who put complex business logic directly in command execute() methods create untestable, unreusable code. Those who keep commands as thin wrappers around services demonstrate good architecture.

← All Symfony questions