100 lines
No EOL
4.1 KiB
PHP
100 lines
No EOL
4.1 KiB
PHP
<?php
|
|
|
|
namespace DigiComp\HetznerDnsApi\Normalizer;
|
|
|
|
use Jane\Component\JsonSchemaRuntime\Reference;
|
|
use DigiComp\HetznerDnsApi\Runtime\Normalizer\CheckArray;
|
|
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|
class PaginationNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
|
|
{
|
|
use DenormalizerAwareTrait;
|
|
use NormalizerAwareTrait;
|
|
use CheckArray;
|
|
public function supportsDenormalization($data, $type, $format = null) : bool
|
|
{
|
|
return $type === 'DigiComp\\HetznerDnsApi\\Model\\Pagination';
|
|
}
|
|
public function supportsNormalization($data, $format = null) : bool
|
|
{
|
|
return is_object($data) && get_class($data) === 'DigiComp\\HetznerDnsApi\\Model\\Pagination';
|
|
}
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function denormalize($data, $class, $format = null, array $context = array())
|
|
{
|
|
if (isset($data['$ref'])) {
|
|
return new Reference($data['$ref'], $context['document-origin']);
|
|
}
|
|
if (isset($data['$recursiveRef'])) {
|
|
return new Reference($data['$recursiveRef'], $context['document-origin']);
|
|
}
|
|
$object = new \DigiComp\HetznerDnsApi\Model\Pagination();
|
|
if (\array_key_exists('page', $data) && \is_int($data['page'])) {
|
|
$data['page'] = (double) $data['page'];
|
|
}
|
|
if (\array_key_exists('per_page', $data) && \is_int($data['per_page'])) {
|
|
$data['per_page'] = (double) $data['per_page'];
|
|
}
|
|
if (\array_key_exists('last_page', $data) && \is_int($data['last_page'])) {
|
|
$data['last_page'] = (double) $data['last_page'];
|
|
}
|
|
if (\array_key_exists('total_entries', $data) && \is_int($data['total_entries'])) {
|
|
$data['total_entries'] = (double) $data['total_entries'];
|
|
}
|
|
if (null === $data || false === \is_array($data)) {
|
|
return $object;
|
|
}
|
|
if (\array_key_exists('page', $data) && $data['page'] !== null) {
|
|
$object->setPage($data['page']);
|
|
}
|
|
elseif (\array_key_exists('page', $data) && $data['page'] === null) {
|
|
$object->setPage(null);
|
|
}
|
|
if (\array_key_exists('per_page', $data) && $data['per_page'] !== null) {
|
|
$object->setPerPage($data['per_page']);
|
|
}
|
|
elseif (\array_key_exists('per_page', $data) && $data['per_page'] === null) {
|
|
$object->setPerPage(null);
|
|
}
|
|
if (\array_key_exists('last_page', $data) && $data['last_page'] !== null) {
|
|
$object->setLastPage($data['last_page']);
|
|
}
|
|
elseif (\array_key_exists('last_page', $data) && $data['last_page'] === null) {
|
|
$object->setLastPage(null);
|
|
}
|
|
if (\array_key_exists('total_entries', $data) && $data['total_entries'] !== null) {
|
|
$object->setTotalEntries($data['total_entries']);
|
|
}
|
|
elseif (\array_key_exists('total_entries', $data) && $data['total_entries'] === null) {
|
|
$object->setTotalEntries(null);
|
|
}
|
|
return $object;
|
|
}
|
|
/**
|
|
* @return array|string|int|float|bool|\ArrayObject|null
|
|
*/
|
|
public function normalize($object, $format = null, array $context = array())
|
|
{
|
|
$data = array();
|
|
if (null !== $object->getPage()) {
|
|
$data['page'] = $object->getPage();
|
|
}
|
|
if (null !== $object->getPerPage()) {
|
|
$data['per_page'] = $object->getPerPage();
|
|
}
|
|
if (null !== $object->getLastPage()) {
|
|
$data['last_page'] = $object->getLastPage();
|
|
}
|
|
if (null !== $object->getTotalEntries()) {
|
|
$data['total_entries'] = $object->getTotalEntries();
|
|
}
|
|
return $data;
|
|
}
|
|
} |