ResourceResponseSubscriber
class ResourceResponseSubscriber implements EventSubscriberInterface (View source)
| internal | JSON:API maintains no PHP API. The API is the HTTP API. This class may change at any time and could break any dependencies on it. |
Response subscriber that serializes and removes ResourceResponses' data.
Properties
| protected SerializerInterface | $serializer | The serializer. |
Methods
Constructs a ResourceResponseSubscriber object.
{@inheritdoc}
Serializes ResourceResponse responses' data, and removes that data.
Renders a resource response body.
Generates a top-level JSON:API normalization context.
Flattens a fully rendered resource response.
Details
__construct(SerializerInterface $serializer)
Constructs a ResourceResponseSubscriber object.
static
getSubscribedEvents()
{@inheritdoc}
onResponse(FilterResponseEvent $event)
Serializes ResourceResponse responses' data, and removes that data.
protected
renderResponseBody(Request $request, ResourceResponse $response, SerializerInterface $serializer, string|null $format)
Renders a resource response body.
Serialization can invoke rendering (e.g., generating URLs), but the serialization API does not provide a mechanism to collect the bubbleable metadata associated with that (e.g., language and other contexts), so instead, allow those to "leak" and collect them here in a render context.
static protected array
generateContext(Request $request)
Generates a top-level JSON:API normalization context.
static protected CacheableResponse|Response
flattenResponse(ResourceResponse $response, Request $request)
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 deserializing the PHP data when reading this response object from cache, which can be very costly, and is unnecessary.