174 lines
No EOL
7.6 KiB
PHP
174 lines
No EOL
7.6 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 ZoneResponseNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
|
|
{
|
|
use DenormalizerAwareTrait;
|
|
use NormalizerAwareTrait;
|
|
use CheckArray;
|
|
public function supportsDenormalization($data, $type, $format = null) : bool
|
|
{
|
|
return $type === 'DigiComp\\HetznerDnsApi\\Model\\ZoneResponse';
|
|
}
|
|
public function supportsNormalization($data, $format = null) : bool
|
|
{
|
|
return is_object($data) && get_class($data) === 'DigiComp\\HetznerDnsApi\\Model\\ZoneResponse';
|
|
}
|
|
/**
|
|
* @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\ZoneResponse();
|
|
if (null === $data || false === \is_array($data)) {
|
|
return $object;
|
|
}
|
|
if (\array_key_exists('id', $data) && $data['id'] !== null) {
|
|
$object->setId($data['id']);
|
|
}
|
|
elseif (\array_key_exists('id', $data) && $data['id'] === null) {
|
|
$object->setId(null);
|
|
}
|
|
if (\array_key_exists('created', $data) && $data['created'] !== null) {
|
|
$object->setCreated(\DateTime::createFromFormat('Y-m-d H:m:i O T', $data['created']));
|
|
}
|
|
elseif (\array_key_exists('created', $data) && $data['created'] === null) {
|
|
$object->setCreated(null);
|
|
}
|
|
if (\array_key_exists('modified', $data) && $data['modified'] !== null) {
|
|
$object->setModified(\DateTime::createFromFormat('Y-m-d H:m:i O T', $data['modified']));
|
|
}
|
|
elseif (\array_key_exists('modified', $data) && $data['modified'] === null) {
|
|
$object->setModified(null);
|
|
}
|
|
if (\array_key_exists('legacy_dns_host', $data) && $data['legacy_dns_host'] !== null) {
|
|
$object->setLegacyDnsHost($data['legacy_dns_host']);
|
|
}
|
|
elseif (\array_key_exists('legacy_dns_host', $data) && $data['legacy_dns_host'] === null) {
|
|
$object->setLegacyDnsHost(null);
|
|
}
|
|
if (\array_key_exists('legacy_ns', $data) && $data['legacy_ns'] !== null) {
|
|
$values = array();
|
|
foreach ($data['legacy_ns'] as $value) {
|
|
$values[] = $value;
|
|
}
|
|
$object->setLegacyNs($values);
|
|
}
|
|
elseif (\array_key_exists('legacy_ns', $data) && $data['legacy_ns'] === null) {
|
|
$object->setLegacyNs(null);
|
|
}
|
|
if (\array_key_exists('name', $data) && $data['name'] !== null) {
|
|
$object->setName($data['name']);
|
|
}
|
|
elseif (\array_key_exists('name', $data) && $data['name'] === null) {
|
|
$object->setName(null);
|
|
}
|
|
if (\array_key_exists('ns', $data) && $data['ns'] !== null) {
|
|
$values_1 = array();
|
|
foreach ($data['ns'] as $value_1) {
|
|
$values_1[] = $value_1;
|
|
}
|
|
$object->setNs($values_1);
|
|
}
|
|
elseif (\array_key_exists('ns', $data) && $data['ns'] === null) {
|
|
$object->setNs(null);
|
|
}
|
|
if (\array_key_exists('owner', $data) && $data['owner'] !== null) {
|
|
$object->setOwner($data['owner']);
|
|
}
|
|
elseif (\array_key_exists('owner', $data) && $data['owner'] === null) {
|
|
$object->setOwner(null);
|
|
}
|
|
if (\array_key_exists('paused', $data) && $data['paused'] !== null) {
|
|
$object->setPaused($data['paused']);
|
|
}
|
|
elseif (\array_key_exists('paused', $data) && $data['paused'] === null) {
|
|
$object->setPaused(null);
|
|
}
|
|
if (\array_key_exists('permission', $data) && $data['permission'] !== null) {
|
|
$object->setPermission($data['permission']);
|
|
}
|
|
elseif (\array_key_exists('permission', $data) && $data['permission'] === null) {
|
|
$object->setPermission(null);
|
|
}
|
|
if (\array_key_exists('project', $data) && $data['project'] !== null) {
|
|
$object->setProject($data['project']);
|
|
}
|
|
elseif (\array_key_exists('project', $data) && $data['project'] === null) {
|
|
$object->setProject(null);
|
|
}
|
|
if (\array_key_exists('registrar', $data) && $data['registrar'] !== null) {
|
|
$object->setRegistrar($data['registrar']);
|
|
}
|
|
elseif (\array_key_exists('registrar', $data) && $data['registrar'] === null) {
|
|
$object->setRegistrar(null);
|
|
}
|
|
if (\array_key_exists('status', $data) && $data['status'] !== null) {
|
|
$object->setStatus($data['status']);
|
|
}
|
|
elseif (\array_key_exists('status', $data) && $data['status'] === null) {
|
|
$object->setStatus(null);
|
|
}
|
|
if (\array_key_exists('ttl', $data) && $data['ttl'] !== null) {
|
|
$object->setTtl($data['ttl']);
|
|
}
|
|
elseif (\array_key_exists('ttl', $data) && $data['ttl'] === null) {
|
|
$object->setTtl(null);
|
|
}
|
|
if (\array_key_exists('verified', $data) && $data['verified'] !== null) {
|
|
$object->setVerified(\DateTime::createFromFormat('Y-m-d H:m:i O T', $data['verified']));
|
|
}
|
|
elseif (\array_key_exists('verified', $data) && $data['verified'] === null) {
|
|
$object->setVerified(null);
|
|
}
|
|
if (\array_key_exists('records_count', $data) && $data['records_count'] !== null) {
|
|
$object->setRecordsCount($data['records_count']);
|
|
}
|
|
elseif (\array_key_exists('records_count', $data) && $data['records_count'] === null) {
|
|
$object->setRecordsCount(null);
|
|
}
|
|
if (\array_key_exists('is_secondary_dns', $data) && $data['is_secondary_dns'] !== null) {
|
|
$object->setIsSecondaryDns($data['is_secondary_dns']);
|
|
}
|
|
elseif (\array_key_exists('is_secondary_dns', $data) && $data['is_secondary_dns'] === null) {
|
|
$object->setIsSecondaryDns(null);
|
|
}
|
|
if (\array_key_exists('txt_verification', $data) && $data['txt_verification'] !== null) {
|
|
$object->setTxtVerification($this->denormalizer->denormalize($data['txt_verification'], 'DigiComp\\HetznerDnsApi\\Model\\BaseZoneTxtVerification', 'json', $context));
|
|
}
|
|
elseif (\array_key_exists('txt_verification', $data) && $data['txt_verification'] === null) {
|
|
$object->setTxtVerification(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->getName()) {
|
|
$data['name'] = $object->getName();
|
|
}
|
|
if (null !== $object->getTtl()) {
|
|
$data['ttl'] = $object->getTtl();
|
|
}
|
|
return $data;
|
|
}
|
|
} |