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:

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'));
}