Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Stovepipe Systems:
What are Bundles in Symfony?
Dec 06, 2016 @ 16:22:56

On the Stovepipe Systems Dev blog today Iltar van der Berg has shared a post about bundles, one of the key concepts in the Symfony ecosystem - what they are and some of the common features they all share.

People often refer to bundles as modules or re-usable code for Symfony applications. When a developer has experience with Symfony1 or another framework with the module concept, it might seem logical that this is what a bundle represents in Symfony.

So what is a bundle? When do you need one and what can it do? What's the difference between an AppBundle and a vendor Bundle?

He starts with the release of Symfony 2, including bundle support, and how common practices created hard dependencies between bundles. This created issues in the applications and reusability of the bundles (their whole purpose) so a solution was created: the AppBundle. This bundle shifted the emphasis away from the file structure of the bundles and more towards the domain they occupied, handling some "magic" references automatically for you.

As mentioned, the bundle provides an extension point. Other bundles for example, can hook in on your bundle because it contains some logic to expose information such as the directory of the bundle.

[...] The main purpose of a bundle however, is to provide an extension point for the Dependency Injection Container. When talking about this extension point, it revolves around adding, changing or removing service definitions.

tagged: symfony bundle introduction appbundle vendor

Link: https://stovepipe.systems/post/what-are-bundles-in-symfony


Trending Topics: