Integrating Bundles (Related Doctrine 2 Entities) in Symfony 2 and Coupling

倖福魔咒の 提交于 2019-12-04 14:29:28

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!