[eluser]Xeoncross[/eluser]
[quote author="Colin Williams" date="1218002434"]So, how does a plugin implement a hook. I don't think I've seen the whole process here. I see your controller invoking hooks, but what's the convention for implementing them?
I think a good usage example is needed here. Like, show something performing its core functionality, then show how a hook extends that functionality.[/quote]
Look at the SVN on the google code :lol:
Your config/hooks.php registers all the hooks just like they do now.
Code:
$hook['custom_hook_class'][] = array(
'function' => 'print_hello',
'filename' => 'custom_hook_class.php',
'filepath' => 'hooks',
'class' => 'custom_hook_class'
);
Your Controller (above) Calls them.
Then each hook is placed inside the app/hooks/ directory:
Code:
<?php
class custom_hook_class {
function custom_hook_class() {
print '<h1>This is '. __CLASS__. ':'. __FUNCTION__. '</h1>';
}
function print_hello() {
print '<h1>This is '. __CLASS__. ':'. __FUNCTION__. '</h1>';
}
}
?>
A hook can be a simple file containing functions (like CI plugins) or a class. Plus, everything is auto-loaded and saved so you don't need to worry about the extrahooks class creating multible objects just to run different functions or including files twice.
This system works EXACTLY like the default hooks setup. Only now:
1) Hooks can be passed data
2) Hooks can return data
3) Hooks can filter data (several hooks running after each other)
3) Hooks can be called/created everywhere in your system (Not just the 8 default places)