Doctrine Listener versus Subscriber

后端 未结 7 965
离开以前
离开以前 2020-12-12 19:52

I\'m working in the Symfony2 framework and wondering when would one use a Doctrine subscriber versus a listener. Doctrine\'s documentation for listeners is very clear, howe

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 20:03

    Both allow you to execute something on a particular event pre / post persist etc.

    However listeners only allow you to execute behaviours encapsulated within your Entity. So an example might be updating a "date_edited" timestamp.

    If you need to move outside the context of your Entity, then you'll need a subscriber. A good example might be for calling an external API, or if you need to use / inspect data not directly related to your Entity.

提交回复
热议问题