本文整理匯總了PHP中LogicHook::setBean方法的典型用法代碼示例。如果您正苦於以下問題:PHP LogicHook::setBean方法的具體用法?PHP LogicHook::setBean怎麽用?PHP LogicHook::setBean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LogicHook
的用法示例。
在下文中一共展示了LogicHook::setBean方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: LogicHook
/**
* Trigger custom logic for this module that is defined for the provided hook
* The custom logic file is located under custom/modules/[CURRENT_MODULE]/logic_hooks.php.
* That file should define the $hook_version that should be used.
* It should also define the $hook_array. The $hook_array will be a two dimensional array
* the first dimension is the name of the event, the second dimension is the information needed
* to fire the hook. Each entry in the top level array should be defined on a single line to make it
* easier to automatically replace this file. There should be no contents of this file that are not replacable.
*
* $hook_array['before_save'][] = Array(1, testtype, 'custom/modules/Leads/test12.php', 'TestClass', 'lead_before_save_1');
* This sample line creates a before_save hook. The hooks are procesed in the order in which they
* are added to the array. The second dimension is an array of:
* processing index (for sorting before exporting the array)
* A logic type hook
* label/type
* php file to include
* php class the method is in
* php method to call
*
* The method signature for version 1 hooks is:
* function NAME(&$bean, $event, $arguments)
* $bean - $this bean passed in by reference.
* $event - The string for the current event (i.e. before_save)
* $arguments - An array of arguments that are specific to the event.
*/
function call_custom_logic($event, $arguments = null)
{
if (!isset($this->processed) || $this->processed == false) {
//add some logic to ensure we do not get into an infinite loop
if (!empty($this->logicHookDepth[$event])) {
if ($this->logicHookDepth[$event] > 10) {
return;
}
} else {
$this->logicHookDepth[$event] = 0;
}
//we have to put the increment operator here
//otherwise we may never increase the depth for that event in the case
//where one event will trigger another as in the case of before_save and after_save
//Also keeping the depth per event allow any number of hooks to be called on the bean
//and we only will return if one event gets caught in a loop. We do not increment globally
//for each event called.
$this->logicHookDepth[$event]++;
//method defined in 'include/utils/LogicHook.php'
$logicHook = new LogicHook();
$logicHook->setBean($this);
$logicHook->call_custom_logic($this->module_dir, $event, $arguments);
}
}
示例2: handleException
/**
* Handle exception
* @param Exception $e
*/
protected function handleException(Exception $e)
{
$GLOBALS['log']->fatal('Exception in Controller: ' . $e->getMessage());
$logicHook = new LogicHook();
if (isset($this->bean)) {
$logicHook->setBean($this->bean);
$logicHook->call_custom_logic($this->bean->module_dir, "handle_exception", $e);
} else {
$logicHook->call_custom_logic('', "handle_exception", $e);
}
}
示例3: array
/**
* Trigger custom logic for this module that is defined for the provided hook
* The custom logic file is located under custom/modules/[CURRENT_MODULE]/logic_hooks.php.
* That file should define the $hook_version that should be used.
* It should also define the $hook_array. The $hook_array will be a two dimensional array
* the first dimension is the name of the event, the second dimension is the information needed
* to fire the hook. Each entry in the top level array should be defined on a single line to make it
* easier to automatically replace this file. There should be no contents of this file that are not replacable.
*
* $hook_array['before_save'][] = Array(1, testtype, 'custom/modules/Leads/test12.php', 'TestClass', 'lead_before_save_1');
* This sample line creates a before_save hook. The hooks are procesed in the order in which they
* are added to the array. The second dimension is an array of:
* processing index (for sorting before exporting the array)
* A logic type hook
* label/type
* php file to include
* php class the method is in
* php method to call
*
* The method signature for version 1 hooks is:
* function NAME(&$bean, $event, $arguments)
* $bean - $this bean passed in by reference.
* $event - The string for the current event (i.e. before_save)
* $arguments - An array of arguments that are specific to the event.
*/
function call_custom_logic($event, $arguments = array())
{
if (!isset($this->processed) || $this->processed == false) {
//add some logic to ensure we do not get into an infinite loop
if (!empty($this->logicHookDepth[$event])) {
if ($this->logicHookDepth[$event] > $this->max_logic_depth) {
return;
}
} else {
$this->logicHookDepth[$event] = 0;
}
//we have to put the increment operator here
//otherwise we may never increase the depth for that event in the case
//where one event will trigger another as in the case of before_save and after_save
//Also keeping the depth per event allow any number of hooks to be called on the bean
//and we only will return if one event gets caught in a loop. We do not increment globally
//for each event called.
$this->logicHookDepth[$event]++;
//method defined in 'include/utils/LogicHook.php'
$logicHook = new LogicHook();
$logicHook->setBean($this);
$logicHook->call_custom_logic($this->module_dir, $event, $arguments);
$this->logicHookDepth[$event]--;
//Fire dependency manager dependencies here for some custom logic types.
if (in_array($event, array('after_relationship_add', 'after_relationship_delete', 'before_delete'))) {
$this->updateRelatedCalcFields(isset($arguments['link']) ? $arguments['link'] : "");
}
}
}
示例4: testprocess_hooks
public function testprocess_hooks()
{
//execute the method and test if it doesn't throws an exception
$LogicHook = new LogicHook();
$LogicHook->setBean(new Account());
$hooks = $LogicHook->loadHooks('');
try {
$LogicHook->process_hooks($hooks, 'after_ui_footer', array());
$this->assertTrue(true);
} catch (Exception $e) {
$this->fail();
}
}
示例5: handleException
/**
* Handle exception
* @param Exception $e
*/
protected function handleException(Exception $e)
{
$GLOBALS['log']->fatal('Exception in Controller: ' . $e);
$logicHook = new LogicHook();
SugarMetric_Manager::getInstance()->handleException($e);
if (isset($this->bean)) {
$logicHook->setBean($this->bean);
$logicHook->call_custom_logic($this->bean->module_dir, "handle_exception", $e);
} else {
$logicHook->call_custom_logic('', "handle_exception", $e);
}
}
示例6: instance
/**
* Static Function which returns and instance of LogicHook
*
* @param SugarBean|null $bean
*
* @return LogicHook
*/
public static function instance(SugarBean $bean = null)
{
if (is_null(static::$instance)) {
static::$instance = new static();
}
static::$instance->setBean($bean);
return static::$instance;
}