Search code examples
symfonydynamicentitybundlefactory

Symfony2 extensible collection entities from different bundles


I am building a CMS that has an abstract definition of an asset.

A page is a collection of assets.

The collection would store details of what is in the collection - but the entities are responsible for their crud process.

I want to be able to manage the collection but have each asset defined in its own bundle - in order to allow 3rd parties to create new asset types.

We are looking at a asset registry / factory pattern.

The process of adding a new asset needs to be dynamic or can be done via a config - but should not require any code changes.

Symfony form types seem to be the closest example to this - any advice / thoughts greatly appreciated.


Solution

  • It seems like it's a perfect job for a compiler pass and tagged services.

    3rd parties would need to register their assets as services and tag them with a specific tag. During the container compilation phase you'd get all the tagged services and register them in your service.

    Related docs: