Last active
December 20, 2015 05:59
-
-
Save microweber/6082647 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
action_hook('before_user_login', 'my_user_login'); | |
function my_user_login($params) | |
{ | |
if($params == 'my_login'){ | |
return function () { return print 'my_login <br>'; }; | |
} | |
} | |
function user_login($params) | |
{ | |
$override = exec_action('before_user_login', $params); | |
if (is_array($override)) { | |
foreach ($override as $resp) { | |
if(is_object($resp)){ | |
return call_user_func($resp,$params); | |
} | |
} | |
} | |
return 'default login <br>'; | |
} | |
print user_login('my_login'); | |
print user_login('something'); | |
// action hook | |
function exec_action($api_function, $data = false) | |
{ | |
global $action_hook_index; | |
$hooks = $action_hook_index; | |
$return = array(); | |
if (isset($hooks[$api_function]) and is_array($hooks[$api_function]) and !empty($hooks[$api_function])) { | |
foreach ($hooks[$api_function] as $hook_key => $hook_value) { | |
if (function_exists($hook_value)) { | |
if ($data != false) { | |
$return[$hook_value] = $hook_value($data); | |
} else { | |
$return[$hook_value] = $hook_value(); | |
} | |
unset($hooks[$api_function][$hook_key]); | |
} else { | |
try { | |
if ($data != false) { | |
$return[$hook_value] = call_user_func($hook_value,$data); // As of PHP 5.3.0 | |
} else { | |
$return[$hook_value] = call_user_func($hook_value,false); | |
} | |
} catch (Exception $e) { | |
} | |
} | |
} | |
if(!empty($return)){ | |
return $return; | |
} | |
} | |
} | |
$action_hook_index = array(); | |
function action_hook($function_name, $next_function_name = false) | |
{ | |
global $action_hook_index; | |
if (is_bool($function_name)) { | |
$action_hook_index = ($action_hook_index); | |
return $action_hook_index; | |
} else { | |
if (!isset($action_hook_index[$function_name])) { | |
$action_hook_index[$function_name] = array(); | |
} | |
$action_hook_index[$function_name][] = $next_function_name; | |
// $index .= ' ' . $function_name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment