ResourceResponseSubscriber
class ResourceResponseSubscriber implements EventSubscriberInterface (View source)
Response subscriber that serializes and removes ResourceResponses' data.
Properties
| protected SerializerInterface | $serializer | The serializer. |
|
| protected RendererInterface | $renderer | The renderer. |
|
| protected RouteMatchInterface | $routeMatch | The current route match. |
Methods
Constructs a ResourceResponseSubscriber object.
Serializes ResourceResponse responses' data, and removes that data.
Determines the format to respond in.
Renders a resource response body.
{@inheritdoc}
Details
__construct(SerializerInterface $serializer, RendererInterface $renderer, RouteMatchInterface $route_match)
Constructs a ResourceResponseSubscriber object.
onResponse(ResponseEvent $event)
Serializes ResourceResponse responses' data, and removes that data.
string
getResponseFormat(RouteMatchInterface $route_match, Request $request)
Determines the format to respond in.
Respects the requested format if one is specified. However, it is common to forget to specify a response format in case of a POST or PATCH. Rather than simply throwing an error, we apply the robustness principle: when POSTing or PATCHing using a certain format, you probably expect a response in that same format.
protected
renderResponseBody(Request $request, ResourceResponseInterface $response, SerializerInterface $serializer, string|null $format)
Renders a resource response body.
During serialization, encoders and normalizers are able to explicitly bubble cacheability metadata via the 'cacheability' key-value pair in the received context. This bubbled cacheability metadata will be applied to the the response.
protected CacheableResponse|Response
flattenResponse(ResourceResponseInterface $response)
Flattens a fully rendered resource response.
Ensures that complex data structures in ResourceResponse::getResponseData() are not serialized. Not doing this means that caching this response object requires unserializing the PHP data when reading this response object from cache, which can be very costly, and is unnecessary.
static
getSubscribedEvents()
{@inheritdoc}