class OffsetPageNormalizer in JSON:API 8
The normalizer used for JSON API pagination.
@internal
Hierarchy
- class \Drupal\jsonapi\Normalizer\OffsetPageNormalizer implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
Expanded class hierarchy of OffsetPageNormalizer
1 string reference to 'OffsetPageNormalizer'
1 service uses OffsetPageNormalizer
File
- src/
Normalizer/ OffsetPageNormalizer.php, line 14
Namespace
Drupal\jsonapi\NormalizerView source
class OffsetPageNormalizer implements DenormalizerInterface {
/**
* The interface or class that this Normalizer supports.
*
* @var string
*/
protected $supportedInterfaceOrClass = OffsetPage::class;
/**
* {@inheritdoc}
*/
public function supportsDenormalization($data, $type, $format = NULL) {
return $type == $this->supportedInterfaceOrClass;
}
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = []) {
$expanded = $this
->expand($data);
return new OffsetPage($expanded[OffsetPage::OFFSET_KEY], $expanded[OffsetPage::SIZE_KEY]);
}
/**
* {@inheritdoc}
*/
protected function expand($data) {
if (!is_array($data)) {
throw new BadRequestHttpException('The page parameter needs to be an array.');
}
$expanded = $data + [
OffsetPage::OFFSET_KEY => OffsetPage::DEFAULT_OFFSET,
OffsetPage::SIZE_KEY => OffsetPage::SIZE_MAX,
];
if ($expanded[OffsetPage::SIZE_KEY] > OffsetPage::SIZE_MAX) {
$expanded[OffsetPage::SIZE_KEY] = OffsetPage::SIZE_MAX;
}
return $expanded;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OffsetPageNormalizer:: |
protected | property | The interface or class that this Normalizer supports. | |
OffsetPageNormalizer:: |
public | function | Denormalizes data back into an object of the given class. | |
OffsetPageNormalizer:: |
protected | function | ||
OffsetPageNormalizer:: |
public | function | Checks whether the given class is supported for denormalization by this normalizer. |