本文整理汇总了PHP中RedBeanPHP\OODBBean::setErrorHandlingFUSE方法的典型用法代码示例。如果您正苦于以下问题:PHP OODBBean::setErrorHandlingFUSE方法的具体用法?PHP OODBBean::setErrorHandlingFUSE怎么用?PHP OODBBean::setErrorHandlingFUSE使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\OODBBean
的用法示例。
在下文中一共展示了OODBBean::setErrorHandlingFUSE方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setErrorHandlingFUSE
/**
* Sets the error mode for FUSE.
* What to do if a FUSE model method does not exist?
* You can set the following options:
*
* OODBBean::C_ERR_IGNORE (default), ignores the call, returns NULL
* OODBBean::C_ERR_LOG, logs the incident using error_log
* OODBBean::C_ERR_NOTICE, triggers a E_USER_NOTICE
* OODBBean::C_ERR_WARN, triggers a E_USER_WARNING
* OODBBean::C_ERR_EXCEPTION, throws an exception
* OODBBean::C_ERR_FUNC, allows you to specify a custom handler (function)
* OODBBean::C_ERR_FATAL, triggers a E_USER_ERROR
*
* Custom handler method signature: handler( array (
* 'message' => string
* 'bean' => OODBBean
* 'method' => string
* ) )
*
* This method returns the old mode and handler as an array.
*
* @param integer $mode mode, determines how to handle errors
* @param callable|NULL $func custom handler (if applicable)
*
* @return array
*/
public static function setErrorHandlingFUSE($mode, $func = NULL)
{
return OODBBean::setErrorHandlingFUSE($mode, $func);
}
示例2: testModelErrorHandling
/**
* Test error handling options FUSE.
*/
public function testModelErrorHandling()
{
$test = R::dispense('feed');
$test->nonExistantMethod();
pass();
$old = R::setErrorHandlingFUSE(OODBBean::C_ERR_LOG);
asrt(is_array($old), TRUE);
asrt(count($old), 2);
asrt($old[0], FALSE);
asrt($old[1], NULL);
$test->nonExistantMethod();
//we cant really test this... :(
pass();
$old = R::setErrorHandlingFUSE(OODBBean::C_ERR_NOTICE);
asrt(is_array($old), TRUE);
asrt(count($old), 2);
asrt($old[0], OODBBean::C_ERR_LOG);
asrt($old[1], NULL);
set_error_handler(function ($error, $str) {
asrt($str, 'FUSE: method does not exist in model: nonExistantMethod');
}, E_USER_NOTICE);
$test->nonExistantMethod();
restore_error_handler();
$old = OODBBean::setErrorHandlingFUSE(OODBBean::C_ERR_WARN);
asrt(is_array($old), TRUE);
asrt(count($old), 2);
asrt($old[0], OODBBean::C_ERR_NOTICE);
asrt($old[1], NULL);
set_error_handler(function ($error, $str) {
asrt($str, 'FUSE: method does not exist in model: nonExistantMethod');
}, E_USER_WARNING);
$test->nonExistantMethod();
restore_error_handler();
$old = OODBBean::setErrorHandlingFUSE(OODBBean::C_ERR_FATAL);
asrt(is_array($old), TRUE);
asrt(count($old), 2);
asrt($old[0], OODBBean::C_ERR_WARN);
asrt($old[1], NULL);
set_error_handler(function ($error, $str) {
asrt($str, 'FUSE: method does not exist in model: nonExistantMethod');
}, E_USER_ERROR);
$test->nonExistantMethod();
restore_error_handler();
$old = OODBBean::setErrorHandlingFUSE(OODBBean::C_ERR_EXCEPTION);
asrt(is_array($old), TRUE);
asrt(count($old), 2);
asrt($old[0], OODBBean::C_ERR_FATAL);
asrt($old[1], NULL);
try {
$test->nonExistantMethod();
fail();
} catch (\Exception $e) {
pass();
}
global $test_bean;
$test_bean = $test;
global $has_executed_error_func_fuse;
$has_executed_error_func_fuse = FALSE;
$old = OODBBean::setErrorHandlingFUSE(OODBBean::C_ERR_FUNC, function ($info) {
global $has_executed_error_func_fuse;
global $test_bean;
$has_executed_error_func_fuse = TRUE;
asrt(is_array($info), TRUE);
asrt($info['method'], 'nonExistantMethod');
asrt(json_encode($info['bean']->export()), json_encode($test_bean->export()));
asrt($info['message'], 'FUSE: method does not exist in model: nonExistantMethod');
});
asrt(is_array($old), TRUE);
asrt(count($old), 2);
asrt($old[0], OODBBean::C_ERR_EXCEPTION);
asrt($old[1], NULL);
$test->nonExistantMethod();
asrt($has_executed_error_func_fuse, TRUE);
$old = OODBBean::setErrorHandlingFUSE(OODBBean::C_ERR_IGNORE);
asrt(is_array($old), TRUE);
asrt(count($old), 2);
asrt($old[0], OODBBean::C_ERR_FUNC);
asrt(is_callable($old[1]), TRUE);
$old = OODBBean::setErrorHandlingFUSE(OODBBean::C_ERR_IGNORE);
asrt(is_array($old), TRUE);
asrt(count($old), 2);
asrt($old[0], OODBBean::C_ERR_IGNORE);
asrt($old[1], NULL);
try {
OODBBean::setErrorHandlingFUSE(900);
fail();
} catch (\Exception $e) {
pass();
asrt($e->getMessage(), 'Invalid error mode selected');
}
try {
OODBBean::setErrorHandlingFUSE(OODBBean::C_ERR_FUNC, 'hello');
fail();
} catch (\Exception $e) {
pass();
asrt($e->getMessage(), 'Invalid error handler');
}
//.........这里部分代码省略.........