Symfony

Custom Bundles

Bundle creation, extension configuration, compiler passes, reusable bundles, best practices

20 interview questionsยท
Senior
1

Which class must the main bundle class extend in Symfony?

Answer

The main bundle class in Symfony must extend AbstractBundle (Symfony 6.1+) or Bundle. AbstractBundle is recommended as it simplifies configuration and allows defining configuration directly in the bundle class via the configure() method. Bundle remains available for backward compatibility but AbstractBundle offers a more modern API.

2

What is the role of the Extension class in a Symfony bundle?

Answer

The Extension class (extending ConfigurableExtension or Extension) is responsible for loading the bundle configuration and registering services in the container. It reads the bundle's configuration files, processes application parameters, and configures services via the ContainerBuilder. It implements the load() method which is called during container compilation.

3

What is the naming convention for the main class of a bundle named AcmePaymentBundle?

Answer

By Symfony convention, the main bundle class must have the same name as the bundle. For AcmePaymentBundle, the main class will be AcmePaymentBundle and must be in the corresponding namespace, typically Acme\PaymentBundle. The file will therefore be AcmePaymentBundle.php in the bundle's src/ folder.

4

What is a Compiler Pass in Symfony and when should it be used?

5

How to define semantic configuration for a bundle with parameter validation?

+17 interview questions

Master Symfony for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free