Intermediate
What are Symfony bundles and how do you create one?
Bundles in Symfony are reusable packages that encapsulate specific functionality, promoting modular development. They can be shared across projects or published for public use.
To create a Symfony bundle, follow these steps:
- Bundle Structure: Create a directory structure that follows the Symfony bundle conventions.
- Create Bundle Class: Define a main bundle class that extends the Bundle class from Symfony.
- Register the Bundle: Register the bundle in the `bundles.php` file of your application.
Example of a simple bundle structure:
namespace App\MyBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MyBundle extends Bundle {}