Design pattern for implementing plugins in PHP applications

后端 未结 6 794
温柔的废话
温柔的废话 2021-01-30 23:15

Is there a consensus on how plugins should be implemented in a PHP application?

I\'ve looked into the observer pattern which comes close, it\'s really just a notificati

6条回答
  •  被撕碎了的回忆
    2021-01-30 23:41

    The way you've done this, with hooks is also how I implement this.

    The biggest problem with your sample though, is that your function instantiates the plugin. Why not pass an instance of the plugin instead?

    The way I've done this, is that a plugin gets instantiated first, and registers its hooks itself.

提交回复
热议问题