class MultiresponseNormalizer in Subrequests 8
Same name and namespace in other branches
- 8.2 src/Normalizer/MultiresponseNormalizer.php \Drupal\subrequests\Normalizer\MultiresponseNormalizer
- 3.x src/Normalizer/MultiresponseNormalizer.php \Drupal\subrequests\Normalizer\MultiresponseNormalizer
Hierarchy
- class \Drupal\subrequests\Normalizer\MultiresponseNormalizer implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface
Expanded class hierarchy of MultiresponseNormalizer
1 string reference to 'MultiresponseNormalizer'
1 service uses MultiresponseNormalizer
File
- src/
Normalizer/ MultiresponseNormalizer.php, line 9
Namespace
Drupal\subrequests\NormalizerView source
class MultiresponseNormalizer implements NormalizerInterface {
/**
* {@inheritdoc}
*/
public function normalize($object, $format = NULL, array $context = []) {
$delimiter = $context['delimiter'];
$separator = sprintf("\r\n--%s\r\n", $delimiter);
// Join the content responses with the separator.
$content_items = array_map(function (Response $part_response) {
$part_response->headers
->set('Status', $part_response
->getStatusCode());
return sprintf("%s\r\n%s", $part_response->headers, $part_response
->getContent());
}, (array) $object);
return sprintf("--%s\r\n", $delimiter) . implode($separator, $content_items) . sprintf("\r\n--%s--", $delimiter);
}
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = NULL) {
if ($format !== 'multipart-related') {
return FALSE;
}
if (!is_array($data)) {
return FALSE;
}
$responses = array_filter($data, function ($response) {
return $response instanceof Response;
});
if (count($responses) !== count($data)) {
return FALSE;
}
return TRUE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MultiresponseNormalizer:: |
public | function | Normalizes an object into a set of arrays/scalars. | |
MultiresponseNormalizer:: |
public | function | Checks whether the given class is supported for normalization by this normalizer. |