此解决方案的后续问题: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() {
...
...
答案 0 :(得分:1)
您应该使用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();