Thread: Hook System
View Single Post
Old 11-05-2007, 06:19 PM   #7 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Okay using your basic concept, say I got a forum software(Working on a new PHP 5 OOP one), My Hook class would be basically a get hooks, check if hook is availible(login,etc.), then execute the hook.

Code:
class HookSystem
{
	private $hooks = array();
	private $page;
	function __construct($_cpage)
	{
		$this->page = $_cpage;
	}	
	function addhook($function_name,$type,...extra parameters...)
	{
		...update the array hooks with a new hook name
	}
	function checkhooks()
	{
		...runs a loop, check what type of hooks where 
	}
}
When running the class I could go about checking what page in viewing and then run the hooks for that page, and what type of hook it is(i.e,

registration -> form
registration -> header
registration -> captcha

)

It would ask what type of hook it is, then check if the hook is available based on something basic like my example say form, hook would be something similar to add a new field to the form with ease.

Code:
$page = htmlspecialchars($_GET['page']);
switch($page)
{
	case 'registration':
		$type = 'registration';
	break;
}
$hooks = new HookSystem($type);

function __form__($left,$right,$pos)
{	
	global $hooks;
	$hooks->addhook("__form__","registration","form",$left,$right,$pos);
}
__form__("Referrer","<input type='text' name='ref' />",3);
Just something simple like that, if you see what I'm getting at.(Most of it would be managed through MySQL database)
Nor is offline  
Reply With Quote