Skip to content

Commit 8668cdf

Browse files
committed
added basic json model normalizer
1 parent e94623e commit 8668cdf

File tree

5 files changed

+358
-18
lines changed

5 files changed

+358
-18
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
php: ['8.1', '8.2']
13+
php: ['8.1', '8.2', '8.3']
1414

1515
name: Tests PHP ${{ matrix.php }}
1616
steps:

.php-cs-fixer.php

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
'no_superfluous_phpdoc_tags' => false,
2727
'yoda_style' => ['equal' => false, 'identical'=>false, 'less_and_greater' => false],
2828
'no_unused_imports' => true,
29+
'trailing_comma_in_multiline' => [
30+
'after_heredoc' => true,
31+
'elements' => ['array_destructuring', 'arrays', 'match']
32+
]
2933
])
3034
->setUsingCache(false)
3135
->setFinder($finder)

src/DBAL/Type/JsonModelType.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
use Doctrine\DBAL\Platforms\AbstractPlatform;
88
use Doctrine\DBAL\Types\ConversionException;
99
use Doctrine\DBAL\Types\JsonType;
10-
use Symfony\Component\Serializer\Debug\TraceableNormalizer;
11-
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
10+
use Pfilsx\PostgreSQLDoctrine\Normalizer\JsonModelNormalizer;
11+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
12+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1213

1314
abstract class JsonModelType extends JsonType
1415
{
15-
private AbstractObjectNormalizer|TraceableNormalizer|null $normalizer = null;
16+
/**
17+
* @var null|DenormalizerInterface|JsonModelNormalizer|NormalizerInterface
18+
*/
19+
private mixed $normalizer = null;
1620

1721
abstract public static function getTypeName(): string;
1822

@@ -55,12 +59,18 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mix
5559
);
5660
}
5761

58-
public function setObjectNormalizer(AbstractObjectNormalizer|TraceableNormalizer $normalizer): void
62+
/**
63+
* @param DenormalizerInterface|JsonModelNormalizer|NormalizerInterface $normalizer
64+
*/
65+
public function setObjectNormalizer(mixed $normalizer): void
5966
{
6067
$this->normalizer = $normalizer;
6168
}
6269

63-
protected function getObjectNormalizer(): AbstractObjectNormalizer|TraceableNormalizer
70+
/**
71+
* @return DenormalizerInterface|JsonModelNormalizer|NormalizerInterface
72+
*/
73+
protected function getObjectNormalizer(): mixed
6474
{
6575
if ($this->normalizer === null) {
6676
throw new \RuntimeException('JsonModelType requires object normalizer to be set');

src/DBAL/Type/JsonModelTypeRegistry.php

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66

77
use Doctrine\DBAL\Exception;
88
use Doctrine\DBAL\Types\Type;
9-
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
10-
use Symfony\Component\Serializer\Debug\TraceableNormalizer;
11-
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
12-
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
13-
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
9+
use Pfilsx\PostgreSQLDoctrine\Normalizer\JsonModelNormalizer;
10+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
11+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1412

1513
final class JsonModelTypeRegistry
1614
{
17-
private static AbstractObjectNormalizer|TraceableNormalizer $objectNormalizer;
15+
/**
16+
* @var null|DenormalizerInterface|JsonModelNormalizer|NormalizerInterface
17+
*/
18+
private static mixed $objectNormalizer = null;
1819

1920
private static array $typesMap = [];
2021

@@ -45,15 +46,18 @@ public static function hasType(string $name): bool
4546
return array_key_exists($name, self::$typesMap);
4647
}
4748

48-
public static function getObjectNormalizer(): AbstractObjectNormalizer|TraceableNormalizer
49+
/**
50+
* @return DenormalizerInterface|JsonModelNormalizer|NormalizerInterface
51+
*/
52+
public static function getObjectNormalizer(): mixed
4953
{
50-
return self::$objectNormalizer ??= new ObjectNormalizer(
51-
nameConverter: new CamelCaseToSnakeCaseNameConverter(),
52-
propertyTypeExtractor: new ReflectionExtractor()
53-
);
54+
return self::$objectNormalizer ??= new JsonModelNormalizer();
5455
}
5556

56-
public static function setObjectNormalizer(AbstractObjectNormalizer|TraceableNormalizer $objectNormalizer): void
57+
/**
58+
* @param DenormalizerInterface|JsonModelNormalizer|NormalizerInterface $objectNormalizer
59+
*/
60+
public static function setObjectNormalizer(mixed $objectNormalizer): void
5761
{
5862
self::$objectNormalizer = $objectNormalizer;
5963
}

0 commit comments

Comments
 (0)