
Console & Commands
Custom commands, arguments, options, output styling, interactive commands, progress bars
1Which base class should be extended to create a custom console command in Symfony?
Which base class should be extended to create a custom console command in Symfony?
Answer
To create a console command in Symfony, the Command class from the Console component must be extended. This class provides all necessary methods to define the command name, description, arguments and options, as well as the execute() method containing the business logic. The #[AsCommand] attribute allows declarative command configuration.
2Which PHP attribute allows configuring a Symfony command declaratively since PHP 8?
Which PHP attribute allows configuring a Symfony command declaratively since PHP 8?
Answer
The #[AsCommand] attribute introduced in Symfony 6 allows declarative command configuration. It accepts the command name as the first argument and optionally a description. This replaces configuration in the configure() method for basic information, making code more readable and concise while still allowing configure() for more complex configurations.
3What is the fundamental difference between an argument and an option in a Symfony console command?
What is the fundamental difference between an argument and an option in a Symfony console command?
Answer
An argument is a positional value, required or optional, passed directly after the command name (e.g., app:user:create john). An option is prefixed with -- (or -) and can have a value or be a boolean flag (e.g., --verbose, --format=json). Arguments are ordered and identified by position, while options can appear in any order.
Which method of the command contains the main logic to execute?
How to define a required argument in a Symfony command?
+15 interview questions
Other Symfony interview topics
Modern PHP (8.1+)
Symfony Basics
Routing & Controllers
Twig & Templates
Doctrine ORM Basics
Symfony Forms
Data Validation
Dependency Injection & Services
Security & Authentication
Doctrine Advanced
API Platform
Serializer Component
Events & Event Subscribers
Messenger Component
HTTP Client
Cache & Performance
Workflow Component
Testing Symfony
Mailer Component
Translations & i18n
EasyAdmin Bundle
Symfony Architecture
Performance & Optimization
Security Advanced
Custom Bundles
Microservices with Symfony
Real-time & WebSockets
Deployment & DevOps
Master Symfony for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free