[英]Luracast Restler 3 logging onRespond
Follow up questions for this solution: https://stackoverflow.com/a/31883204/3548238跟进此解决方案的问题: https : //stackoverflow.com/a/31883204/3548238
For example something like this:例如这样的事情:
/**
*
* @status 200
*
* @description Get all logs
* @url GET logs
* @access protected
* @class AccessControl {@requires admin}
*
* @log false
*
* @throws RestException
*/
public function list_all_logs() {
...
...
You should be using onComplete
instead of onRespond
您应该使用onComplete
而不是onRespond
Why?为什么?
onRespond()
- fired before sending response onRespond()
- 在发送响应之前触发onComplete()
- fired after sending response onComplete()
- 发送响应后触发Here is the complete solution that answers all your questions, assuming you are adding @log false
comment to the api method you want to exclude这是回答您所有问题的完整解决方案,假设您在要排除的 api 方法中添加了@log false
注释
use Luracast\Restler\Restler;
use Luracast\Restler\User;
$r = new Restler();
$r->onComplete(function () use ($r) {
if (
!isset($r->apiMethodInfo->metadata['log']) ||
$r->apiMethodInfo->metadata['log'] == 'true'
) {
$success = $r->responseCode == 200;
$info = array(
'success' => $success,
'message' => $success ? '' : $r->exception->getErrorMessage()
);
print_r($info); //your logging function here!
}
});
$r->addAPIClass('Say');
$r->handle();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.