[英]Luracast Restler 3 logging onRespond
跟進此解決方案的問題: https : //stackoverflow.com/a/31883204/3548238
例如這樣的事情:
/**
*
* @status 200
*
* @description Get all logs
* @url GET logs
* @access protected
* @class AccessControl {@requires admin}
*
* @log false
*
* @throws RestException
*/
public function list_all_logs() {
...
...
您應該使用onComplete
而不是onRespond
為什么?
onRespond()
- 在發送響應之前觸發onComplete()
- 發送響應后觸發這是回答您所有問題的完整解決方案,假設您在要排除的 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.