Hooks
Hooks are a way to tie into the bootstrap when it's run. Phork comes with CommonHooks and CacheHooks, Phork/it comes with AccessHooks, and additional hooks can be added to each site in the phork/sites/[sitetype]/hooks/ directory. They're run using the CoreEvent class, and they can be called at the following points:
- Pre run - This hook point is before the controller is determined.
- Pre initialize - This hook point is before the controller is initialized.
- Post initialize - This hook point is after the controller is initialized.
- Post run - This hook point is after the controller has been run.
Hooks should be registered in the site's bootstrap file at phork/sites/[sitetype]/bootstraps/SiteBootstrap.class.php and should be passed the same parameters as call_user_func_array(), which is a callback function, and (optionally) the array of arguments to pass to the callback function.
Example (from the bootstrap)
//add the hook to always verify the form post and to track page history
if (AppLoader::includeHooks('CommonHooks')) {
$objCommonHooks = new CommonHooks();
$this->registerPreRunHook(array($objCommonHooks, 'verifyToken'));
$this->registerPostRunHook(array($objCommonHooks, 'trackHistory'), array(5, array('css', 'js', 'xml', 'json')));
}
//add the hooks to handle full page caching
if (AppLoader::includeHooks('CacheHooks')) {
$objCacheHooks = new CacheHooks();
$this->registerPreRunHook(array($objCacheHooks, 'serveCache'));
$this->registerPostRunHook(array($objCacheHooks, 'saveCache'));
}