How do you impliment a hook system in a PHP application to change the code before or after it executes. How would the basic architecture of a hookloader class be for a PHP
Here's another solution:
Run this wherever you want to create a hook:
x_do_action('header_scripts');
Then attach a function to the above by doing:
x_add_action('header_scripts','my_function_attach_header_scripts');
function my_function_attach_header_scripts($values) {
/* add my scripts here */
}
Add this to the top of your main PHP functions file, or equivalent
$x_events = array();
global $x_events;
function x_do_action($hook, $value = NULL) {
global $x_events;
if (isset($x_events[$hook])) {
foreach($x_events[$hook] as $function) {
if (function_exists($function)) { call_user_func($function, $value); }
}
}
}
function x_add_action($hook, $func, $val = NULL) {
global $x_events;
$x_events[$hook][] = $func;
}