2

Possible Duplicate:
Best way to allow plugins for a PHP application
PHP Event-Listener best-practice implementation

I'm building a simple CMS-like application in PHP which should allow an administrator to enable additional functionality trough plugins (from within an administration area).

Currently it's based on the observer pattern and it works like this:

  • each plugin must extend an abstract class
  • besides one "init" method, all methods that the plugin (child classes) define are considered observers.
  • the constructor of the abstract class is final, and it uses get_class_methods to map these observers to events.
  • from the time the application starts until its end it will notify these observers of its events like app_start / process_request / app_end etc and the observer functions are executed, with the application instance as the first argument, because the app also acts like a service container that the plugins can use to access other components like the db for example.

Is this a good way of implementing a plugin arhitecture in PHP? Or are there better ways? I already have this running, but as I'm adding new API to the abstract class that the child classes can use its starting to feel weird :)

Community
  • 1
  • 1
reflekt
  • 29
  • 1
  • another tip: final is not that needed. you want to allow plugin authors to actually test their plugins which might need them to override the constructor in a stub or mock. – hakre Oct 05 '12 at 15:46

0 Answers0