Created
November 3, 2011 18:12
-
-
Save croxton/1337243 to your computer and use it in GitHub Desktop.
Infomer Hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Informer { | |
static protected $hooks = array(); | |
protected $hook_event; | |
// -------------------------------------------------------------------- | |
// Hook management | |
/** | |
* _register hook | |
* | |
* @access private | |
* @param string | |
* @return void | |
*/ | |
private function _register_hook($hook) | |
{ | |
if( ! isset(self::$hooks[$hook])) | |
{ | |
require_once PATH_THIRD.'informer/hooks/'.$hook.'_pi'.EXT; | |
self::$hooks[] = $hook; | |
} | |
} | |
/** | |
* _unregister hook | |
* | |
* @access private | |
* @param string | |
* @return void | |
*/ | |
private function _unregister_hook($hook) | |
{ | |
if( isset(self::$hooks[$hook])) | |
{ | |
unset(self::$hooks[$hook]); | |
} | |
else | |
{ | |
throw new Exception('Informer: no such hook'); | |
} | |
} | |
/** | |
* __call magic method | |
* | |
* @access public | |
* @param string | |
* @param array | |
* @return array | |
*/ | |
public function __call($hook, $args) | |
{ | |
if ( ! in_array($hook, self::$hooks)) | |
{ | |
$this->_register_hook($hook); | |
} | |
$hook = ucfirst($hook); | |
$hook_obj =& new $hook(); | |
return call_user_func_array(array(&$hook_obj, $this->hook_event), $args); | |
} | |
// continued... | |
} | |
// -------------------------------------------------------------------------- | |
// ...call hooks like this... | |
$this->hook_event = 'validate_end'; | |
$this->{$hook}($data); | |
// -------------------------------------------------------------------------- | |
/** | |
* Informer_hook Class | |
* | |
* abstract for hooks | |
* | |
* @package Informer | |
*/ | |
abstract class Informer_hook { | |
protected $EE; | |
public function __construct() | |
{ | |
$this->EE =& get_instance(); | |
} | |
abstract public function form_start(&$data); | |
abstract public function validate_end(&$data); | |
abstract public function form_end(&$data); | |
abstract public function email_start(&$config, &$report); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment