Skip to content

Commit ca1bd25

Browse files
committed
fix: fixed object normalization
1 parent 46aad19 commit ca1bd25

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hostinger/api-php-sdk",
3-
"version": "0.0.34",
3+
"version": "0.0.35",
44
"description": "Hostinger API PHP SDK",
55
"keywords": [
66
"hostinger",

src/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Configuration
2020

2121
protected string $host = 'https://developers.hostinger.com';
2222

23-
protected string $userAgent = 'hostinger-php-sdk/0.0.34';
23+
protected string $userAgent = 'hostinger-php-sdk/0.0.35';
2424

2525
protected bool $debug = false;
2626

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Hostinger\Normalizers;
6+
7+
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
8+
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
9+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
10+
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
11+
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
12+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
13+
14+
class ArrayToObjectNormalizer implements DenormalizerInterface, DenormalizerAwareInterface, NormalizerInterface, NormalizerAwareInterface
15+
{
16+
use DenormalizerAwareTrait;
17+
use NormalizerAwareTrait;
18+
19+
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
20+
{
21+
return (object) $data;
22+
}
23+
24+
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
25+
{
26+
return is_array($data);
27+
}
28+
29+
public function getSupportedTypes(?string $format): array
30+
{
31+
return [
32+
'object' => true,
33+
'*' => false, // Supports any class but with lower priority
34+
];
35+
}
36+
37+
public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
38+
{
39+
return (array) $object;
40+
}
41+
42+
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
43+
{
44+
return true;
45+
}
46+
}

src/ObjectSerializer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Hostinger;
1414

15+
use Hostinger\Normalizers\ArrayToObjectNormalizer;
1516
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1617
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1718
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
@@ -59,6 +60,7 @@ private static function createSerializer(): Serializer
5960

6061
// Configure normalizers
6162
$normalizers = [
63+
new ArrayToObjectNormalizer(),
6264
new DateTimeNormalizer([
6365
DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339,
6466
DateTimeNormalizer::TIMEZONE_KEY => 'UTC',

0 commit comments

Comments
 (0)