Best way to allow plugins for a PHP application

前端 未结 8 753
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 09:12

I am starting a new web application in PHP and this time around I want to create something that people can extend by using a plugin interface.

How does one go about

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 09:44

    Here is an approach I've used, it's an attempt to copy from Qt signals/slots mechanism, a kind of Observer pattern. Objects can emit signals. Every signal has an ID in the system - it's composed by sender's id + object name Every signal can be binded to the receivers, which simply is a "callable" You use a bus class to pass the signals to anybody interested in receiving them When something happens, you "send" a signal. Below is and example implementation

        login();
    
    ?>
    

提交回复
热议问题