我创建了一个调用第三方api的捆绑包。
现在,我想在Symfony Profiler中显示接收到的数据。
我创建了一个CustomDataCollector(http://symfony.com/doc/current/profiler/data_collector.html)。一切正常。但是,如何获取或“保存”该API的响应?
我创建了一个使用curl调用api的服务,如下所示:
$raw_response = curl_exec($ch);
$response = json_decode($raw_response);
if (property_exists($response, 'error') && $response->errors) {
return ['status'=>false, 'msg'=> (string)$response->errors[0]->description ] ;
} else {
return ['status'=>true, 'msg' =>'Send Successfully' ];
}
我建议您将logger
服务用于不需要特定收集器的简单用例。您可以为日志记录提供其他上下文:
/** LoggerInterface */
$container->get('logger')->error('There was an error on the API call.', array(
'description' => $response->errors[0]->description
);
logger
默认情况下,数据保存到配置文件中。对于更高级的用例,您可能正在寻找处理器:http : //symfony.com/doc/current/logging/processors.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句