Skip to content
WJunction - Webmaster Forum

Implementing a Hook/AddOn System in PHP?

Status
Not open for further replies.
I was wondering how to do this, and I understand how I'd get it to dynamically add addons, etc. I was wondering if anyone could maybe post the basic logic of a hook system, and addon system similiar to that of vBulletin?
 

5 comments

Yeah, I thought about going through other people's code, and working out how they do it. Only thing is, I know that if I do look through it, I'll end up using bits of their code. That's why i want just the logic, So i can learn to code it myself :)

Yah, im wierd like that :P
 
not really hard to do

create a class class called hooks and a folder called hooks

PHP:
class Hooks
{
    public function run($hooks)
    {
         //each hooks should be in the directory called hooks and asub folder
         /*
              Hooks
                  - startup
                  - before_db
         */
         //$Hooks->run('before_db') would run threw all the php files on the startup_db folder and include them, all you have to do is run the specific folder at the specific time in your system.
    }
}
 
I prefer to do something like

PHP:
class Hooks
{
    public static function run($hook,$vars)
    {
          extract($vars);
foreach .... {
inclde('hooks/'.$name.'.php');
}
return compact($vars);
    }
}
 
I Usually use a registry system so i would not need to use vars this is why, in the hook i would do

Code:
$Data =& Registry::get('Data');
$Data->SiteData += Registry::get('Database')->simpleAssoc("title",'site_data');
 
Status
Not open for further replies.

About the author

T
Active Member · Joined
Picked up photoshop about half a year ago. Now i do graphics design :) Graphics/Web Design
885
Messages
0
Reactions
16
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom