mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-04 17:44:38 +09:00
Allow triggers to call arbitrary functions
This commit is contained in:
parent
9f35a3c95b
commit
74ac1e5141
3 changed files with 46 additions and 2 deletions
|
|
@ -1207,9 +1207,9 @@ class ModuleHandler extends Handler
|
||||||
|
|
||||||
$oModuleModel = getModel('module');
|
$oModuleModel = getModel('module');
|
||||||
$triggers = $oModuleModel->getTriggers($trigger_name, $called_position);
|
$triggers = $oModuleModel->getTriggers($trigger_name, $called_position);
|
||||||
if(!$triggers || count($triggers) < 1)
|
if(!$triggers)
|
||||||
{
|
{
|
||||||
return new Object();
|
$triggers = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
//store before trigger call time
|
//store before trigger call time
|
||||||
|
|
@ -1252,6 +1252,17 @@ class ModuleHandler extends Handler
|
||||||
unset($oModule);
|
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();
|
return new Object();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,24 @@ class moduleController extends module
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add trigger callback function
|
||||||
|
*
|
||||||
|
* @param string $trigger_name
|
||||||
|
* @param string $called_position
|
||||||
|
* @param callable $callback_function
|
||||||
|
*/
|
||||||
|
function insertTriggerFunction($trigger_name, $called_position, $callback_function)
|
||||||
|
{
|
||||||
|
if(!isset($GLOBALS['__trigger_functions__']))
|
||||||
|
{
|
||||||
|
$GLOBALS['__trigger_functions__'] = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$GLOBALS['__trigger_functions__'][$trigger_name][$called_position][] = $callback_function;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add module trigger
|
* @brief Add module trigger
|
||||||
* module trigger is to call a trigger to a target module
|
* 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
|
* @brief Get a list of all triggers on the trigger_name
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue