mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +09:00
Merge pull request #186 from kijin/pr/triggers-from-everywhere
애드온 등에서 트리거에 콜백 함수를 등록할 수 있도록 허용
This commit is contained in:
commit
66994d35dc
3 changed files with 41 additions and 2 deletions
|
|
@ -1207,9 +1207,9 @@ class ModuleHandler extends Handler
|
|||
|
||||
$oModuleModel = getModel('module');
|
||||
$triggers = $oModuleModel->getTriggers($trigger_name, $called_position);
|
||||
if(!$triggers || count($triggers) < 1)
|
||||
if(!$triggers)
|
||||
{
|
||||
return new Object();
|
||||
$triggers = array();
|
||||
}
|
||||
|
||||
//store before trigger call time
|
||||
|
|
@ -1252,6 +1252,17 @@ class ModuleHandler extends Handler
|
|||
unset($oModule);
|
||||
}
|
||||
|
||||
$trigger_functions = $oModuleModel->getTriggerFunctions($trigger_name, $called_position);
|
||||
foreach($trigger_functions as $item)
|
||||
{
|
||||
$item($obj);
|
||||
|
||||
if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool())
|
||||
{
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
return new Object();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,19 @@ class moduleController extends module
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add trigger callback function
|
||||
*
|
||||
* @param string $trigger_name
|
||||
* @param string $called_position
|
||||
* @param callable $callback_function
|
||||
*/
|
||||
function addTriggerFunction($trigger_name, $called_position, $callback_function)
|
||||
{
|
||||
$GLOBALS['__trigger_functions__'][$trigger_name][$called_position][] = $callback_function;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add module trigger
|
||||
* module trigger is to call a trigger to a target module
|
||||
|
|
|
|||
|
|
@ -625,6 +625,21 @@ class moduleModel extends module
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get trigger functions
|
||||
*/
|
||||
function getTriggerFunctions($trigger_name, $called_position)
|
||||
{
|
||||
if(isset($GLOBALS['__trigger_functions__'][$trigger_name][$called_position]))
|
||||
{
|
||||
return $GLOBALS['__trigger_functions__'][$trigger_name][$called_position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a list of all triggers on the trigger_name
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue