Question

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.

Était-ce utile?

La solution

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/

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top