56 lines
6.8 KiB
PHP
56 lines
6.8 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace DigiComp\HetznerDnsApi\Normalizer;
|
||
|
|
||
|
use DigiComp\HetznerDnsApi\Runtime\Normalizer\CheckArray;
|
||
|
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 JaneObjectNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
|
||
|
{
|
||
|
use DenormalizerAwareTrait;
|
||
|
use NormalizerAwareTrait;
|
||
|
use CheckArray;
|
||
|
protected $normalizers = array('DigiComp\\HetznerDnsApi\\Model\\BaseRecord' => 'DigiComp\\HetznerDnsApi\\Normalizer\\BaseRecordNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\ExistingRecord' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ExistingRecordNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\Record' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\BaseRecordBulk' => 'DigiComp\\HetznerDnsApi\\Normalizer\\BaseRecordBulkNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\ExistingRecordBulk' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ExistingRecordBulkNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordBulk' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordBulkNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordResponse' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordResponseNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\BasePrimaryServer' => 'DigiComp\\HetznerDnsApi\\Normalizer\\BasePrimaryServerNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\ExistingPrimaryServer' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ExistingPrimaryServerNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\PrimaryServer' => 'DigiComp\\HetznerDnsApi\\Normalizer\\PrimaryServerNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\PrimaryServerResponse' => 'DigiComp\\HetznerDnsApi\\Normalizer\\PrimaryServerResponseNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\BaseZone' => 'DigiComp\\HetznerDnsApi\\Normalizer\\BaseZoneNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\BaseZoneTxtVerification' => 'DigiComp\\HetznerDnsApi\\Normalizer\\BaseZoneTxtVerificationNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\Zone' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ZoneNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\ZoneResponse' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ZoneResponseNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\Meta' => 'DigiComp\\HetznerDnsApi\\Normalizer\\MetaNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\Pagination' => 'DigiComp\\HetznerDnsApi\\Normalizer\\PaginationNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\ZonesGetResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ZonesGetResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\ZonesPostResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ZonesPostResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\ZonesZoneIDGetResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ZonesZoneIDGetResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\ZonesZoneIDPutResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ZonesZoneIDPutResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\ZonesZoneIDImportPostResponse201' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ZonesZoneIDImportPostResponse201Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\ZonesFileValidatePostResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\ZonesFileValidatePostResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordsGetResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordsGetResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordsPostResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordsPostResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordsRecordIDGetResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordsRecordIDGetResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordsRecordIDPutResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordsRecordIDPutResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordsBulkPostBody' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordsBulkPostBodyNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordsBulkPostResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordsBulkPostResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordsBulkPutBody' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordsBulkPutBodyNormalizer', 'DigiComp\\HetznerDnsApi\\Model\\RecordsBulkPutResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\RecordsBulkPutResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\PrimaryServersGetResponse200' => 'DigiComp\\HetznerDnsApi\\Normalizer\\PrimaryServersGetResponse200Normalizer', 'DigiComp\\HetznerDnsApi\\Model\\P
|
||
|
public function supportsDenormalization($data, $type, $format = null) : bool
|
||
|
{
|
||
|
return array_key_exists($type, $this->normalizers);
|
||
|
}
|
||
|
public function supportsNormalization($data, $format = null) : bool
|
||
|
{
|
||
|
return is_object($data) && array_key_exists(get_class($data), $this->normalizers);
|
||
|
}
|
||
|
/**
|
||
|
* @return array|string|int|float|bool|\ArrayObject|null
|
||
|
*/
|
||
|
public function normalize($object, $format = null, array $context = array())
|
||
|
{
|
||
|
$normalizerClass = $this->normalizers[get_class($object)];
|
||
|
$normalizer = $this->getNormalizer($normalizerClass);
|
||
|
return $normalizer->normalize($object, $format, $context);
|
||
|
}
|
||
|
/**
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function denormalize($data, $class, $format = null, array $context = array())
|
||
|
{
|
||
|
$denormalizerClass = $this->normalizers[$class];
|
||
|
$denormalizer = $this->getNormalizer($denormalizerClass);
|
||
|
return $denormalizer->denormalize($data, $class, $format, $context);
|
||
|
}
|
||
|
private function getNormalizer(string $normalizerClass)
|
||
|
{
|
||
|
return $this->normalizersCache[$normalizerClass] ?? $this->initNormalizer($normalizerClass);
|
||
|
}
|
||
|
private function initNormalizer(string $normalizerClass)
|
||
|
{
|
||
|
$normalizer = new $normalizerClass();
|
||
|
$normalizer->setNormalizer($this->normalizer);
|
||
|
$normalizer->setDenormalizer($this->denormalizer);
|
||
|
$this->normalizersCache[$normalizerClass] = $normalizer;
|
||
|
return $normalizer;
|
||
|
}
|
||
|
}
|