1

I need to implement a hook/plugin architecture for a project in PHP. I found a lot of articles and examples written in php and some information on plugin architecture, but I still cannot clearly understand how this works. This may be a real stupid question to someone, but I am new to these concepts and really need to find a clear answer. What is really the role of a hook in plugin architecture? How does hooks can make an application more extensible. I'd love to see a answer with an example from PHP.

Thank you.

Deepal
  • 1,729
  • 5
  • 24
  • 34
  • 1
    this is a better example for hook concept in wordpress http://stackoverflow.com/questions/5127424/how-does-plugin-system-work-wordpress-mybb/5127470#5127470 – Ananth Mar 21 '14 at 04:47
  • possible duplicate of [How to do a PHP hook system?](http://stackoverflow.com/questions/8336308/how-to-do-a-php-hook-system) – DanMan Mar 24 '15 at 13:03

1 Answers1

1

In simple terms, hook is nothing but event handler in Event Based Architecture. You can subscribe any public event through your handler(hooks) and it will be fired/callback when that event happens. e.g. WordPress built upon the event based architecture.

How its extensible? publish-subscribe principle decouple the event source from its subscribers/handlers/hooks and so two can vary without affecting each other.

Example : http://agafix.org/a-practical-guide-to-event-driven-programming-with-php/

Senthil
  • 1,499
  • 16
  • 17