public function BlueprintManager::combineResponses in Subrequests 3.x
Same name and namespace in other branches
- 8.2 src/Blueprint/BlueprintManager.php \Drupal\subrequests\Blueprint\BlueprintManager::combineResponses()
Parameters
\Symfony\Component\HttpFoundation\Response[] $responses: The responses to combine.
string $format: The format to combine the responses on. Default is multipart/related.
Return value
\Symfony\Component\HttpFoundation\Response The combined response with a 207.
File
- src/
Blueprint/ BlueprintManager.php, line 52
Class
Namespace
Drupal\subrequests\BlueprintCode
public function combineResponses(array $responses, $format) {
$context = [
'sub-content-type' => $this
->negotiateSubContentType($responses),
];
// Set the content.
$normalized = $this->serializer
->normalize($responses, $format, $context);
$response = CacheableResponse::create($normalized['content'], 207, $normalized['headers']);
// Set the cacheability metadata.
$cacheable_responses = array_filter($responses, function ($response) {
return $response instanceof CacheableResponseInterface;
});
array_walk($cacheable_responses, function (CacheableResponseInterface $partial_response) use ($response) {
$response
->addCacheableDependency($partial_response
->getCacheableMetadata());
});
return $response;
}