close
Phork Manual Table of Contents
Phork Framework User Guide 1.3.4

Hooks

Hooks are a way to tie into the bootstrap when it's run. Phork comes with CommonHooks and CacheHooks, 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
if (AppLoader::includeHooks('CommonHooks')) {
    $objCommonHooks = new CommonHooks();
    $this->registerPreRunHook(array($objCommonHooks, 'verifyToken'));
    $this->registerPostRunHook(array($objCommonHooks, 'trackHistory'), array(5, array('css', 'js', 'xml')));
}
    
//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'));
}