1. 云栖社区>
  2. PHP教程>
  3. 正文

Symfony: Log outgoing responses with kernel events

作者:用户 来源:互联网 时间:2017-12-01 17:16:44

Symfony: Log outgoing responses with kernel events - 摘要: 本文讲的是Symfony: Log outgoing responses with kernel events, One of the nicest features of Symfony2 is the Request/Response paradigm for processing a HTTP request and then sending

One of the nicest features of Symfony2 is the Request/Response paradigm for processing a HTTP request and then sending a response back to a client. At a high level, Symfony’sHttpFoundationcomponent provides an object oriented abstraction to easily deal with HTTP requests and generate responses to send back to a client. Assuming application code correctly uses HttpFoundation, it will only interact with request variables through the Request class, as opposed to $_REQUEST, and only send output using the Response class, as opposed to an “echo”. Because of this contract, the framework as a whole makes it easy to manipulate responses before they’re sent back to a client.

A typical use case that leverages this would be logging API responses before they’re sent back to a client. As much as an API might beRESTful, at some point it’s easier to debug things when you can see the responses that clients have been receiving. OK great so how do you do it? It’s actually pretty straightforward, just create a class to receive the “kernel.response” event and register it as a service with the appropriate tags:

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索,以便于您获取更多的相关知识。