97 lines
3.9 KiB
PHP
97 lines
3.9 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 PrimaryServerNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
|
||
|
{
|
||
|
use DenormalizerAwareTrait;
|
||
|
use NormalizerAwareTrait;
|
||
|
use CheckArray;
|
||
|
public function supportsDenormalization($data, $type, $format = null) : bool
|
||
|
{
|
||
|
return $type === 'DigiComp\\HetznerDnsApi\\Model\\PrimaryServer';
|
||
|
}
|
||
|
public function supportsNormalization($data, $format = null) : bool
|
||
|
{
|
||
|
return is_object($data) && get_class($data) === 'DigiComp\\HetznerDnsApi\\Model\\PrimaryServer';
|
||
|
}
|
||
|
/**
|
||
|
* @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\PrimaryServer();
|
||
|
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('zone_id', $data) && $data['zone_id'] !== null) {
|
||
|
$object->setZoneId($data['zone_id']);
|
||
|
}
|
||
|
elseif (\array_key_exists('zone_id', $data) && $data['zone_id'] === null) {
|
||
|
$object->setZoneId(null);
|
||
|
}
|
||
|
if (\array_key_exists('address', $data) && $data['address'] !== null) {
|
||
|
$object->setAddress($data['address']);
|
||
|
}
|
||
|
elseif (\array_key_exists('address', $data) && $data['address'] === null) {
|
||
|
$object->setAddress(null);
|
||
|
}
|
||
|
if (\array_key_exists('port', $data) && $data['port'] !== null) {
|
||
|
$object->setPort($data['port']);
|
||
|
}
|
||
|
elseif (\array_key_exists('port', $data) && $data['port'] === null) {
|
||
|
$object->setPort(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->getZoneId()) {
|
||
|
$data['zone_id'] = $object->getZoneId();
|
||
|
}
|
||
|
if (null !== $object->getAddress()) {
|
||
|
$data['address'] = $object->getAddress();
|
||
|
}
|
||
|
if (null !== $object->getPort()) {
|
||
|
$data['port'] = $object->getPort();
|
||
|
}
|
||
|
return $data;
|
||
|
}
|
||
|
}
|