As I understand, Bundles is to separate functionality. Suppose I have a UserBundle & a BlogBundle. Then my BlogBundle:Post will have an author field that references UserBundle:User. Doesn't that defeats the purpose of Bundles? I cant swap another UserBundle in? How can I do it a proper way? Or is this the best it can go?
If you are uncomfortable with those dependencies between bundles (I personally agree with you), you can create your model outside of any bundle. This can be configured like so…
doctrine_mongodb:
document_managers:
default:
mappings:
model:
type: annotation
dir: %kernel.root_dir%/../src/MyApp/Model
prefix: MyApp\Model\
alias: Model
Configuration for the ORM would look similar.
Bundles are meant to separate functionality as much as possible, but that doesn't mean that some won't have dependencies on others.
I think it's interesting that even some of the Symfony2 components, which are supposed to be stand-alone libraries, have dependencies. For example, the HttpKernel class depends on classes from the HttpFoundation and EventDispatcher components.
In your example, if you needed to swap in another UserBundle, you'd have to take the necessary steps to ensure your BlogBundle's dependency is still fulfilled. This may mean you need to refactor.
So, the purpose of bundles isn't defeated because one references the other. Bundles are still advantageous to use even if they're not always 100% uncoupled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With