Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Well, in context of another application one might not want to bind a given blog post to a person/user, rather than a group. To keep your code portable to its maximum I think you should abstract the scenario a bit. Relations would be unacceptable. Owner identity, on the other hand, is.

So imagine that a given blog post has an owner. In the context if a different application with its own bundles, an owner identity might be a group, a user, an outside source, etc.

Imho you should use only id of the "one" who has wrote the article, not bounding your implementation implying that this would be a "person" on the local database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top