sjwspud Posted July 12, 2009 Share Posted July 12, 2009 Got a quick question... I have been searching Google for quite some time now trying to completely figure out how to use a PHP hook system. I am in the process of writing my own open source bulletin board system and want to allow hooks to be used. What I basically want to do is add a hook system so users will be able to add plugins to the software to add different features basically and to even maybe alter current features in the software. I have been trying to find a tutorial that would explain how to do this, but can't seem to find a single tutorial that really explains the hook system. Could anyone direct me to a tutorial explaining the hook system? Thanks :-) Link to comment https://forums.phpfreaks.com/topic/165669-php-hook-system/ Share on other sites More sharing options...
trq Posted July 12, 2009 Share Posted July 12, 2009 Hooks are a very simple process, but they may not actually be what your after. In the case of hooks, you simply call hook functions at certain places during your applications process. A very simply example. <?php echo "start script"; echo "middle script"; echo "endscript"; ?> Now, lets say you wanted to make hooks available to start, middle, and end. <?php if (function_exists('start_hook')) { start_hook(); } echo "start script"; if (function_exists('middle_hook')) { middle_hook(); } echo "middle script"; if (function_exists('end_hook')) { end_hook(); } echo "endscript"; ?> Now your users simply need to create start_hook(), middle_hook() and end_hook() and place them in the correct location. This is a very simplified example, but should get you started. Link to comment https://forums.phpfreaks.com/topic/165669-php-hook-system/#findComment-873900 Share on other sites More sharing options...
sjwspud Posted July 12, 2009 Author Share Posted July 12, 2009 Hooks are a very simple process, but they may not actually be what your after. Seems pretty simple to use. You said they may not be what I am after...what would I need to do to allow plugins? Any ideas? Thanks for your quick response. :-) Link to comment https://forums.phpfreaks.com/topic/165669-php-hook-system/#findComment-873914 Share on other sites More sharing options...
trq Posted July 12, 2009 Share Posted July 12, 2009 Implementing a plugin system would entirely depend upon how your application is designed. At there simplest, hooks might do, otherwise you'll want to look more complex design patterns. Theres a few threads on these boards that go into a bit of detail on the subject, try searching. Link to comment https://forums.phpfreaks.com/topic/165669-php-hook-system/#findComment-873928 Share on other sites More sharing options...
ignace Posted July 12, 2009 Share Posted July 12, 2009 If you enter define:plugin as a search term into google you'll get an explanation of what a plugin actually is, simply put: it's something a system hasn't yet have. I never created a plugin system myself and my best guess would be that a plugin would be registered for a particular section in your website, then when you enter that particular section it calls all registered plugins (somewhat like an observer pattern, i guess) and passes it's contents. But, like I said I never created it myself before, maybe someone who wants to add something to that? Link to comment https://forums.phpfreaks.com/topic/165669-php-hook-system/#findComment-873947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.