Skip to content

Commit

Permalink
allow debug traceable normalizer in json model type
Browse files Browse the repository at this point in the history
  • Loading branch information
pfilsx committed Feb 24, 2023
1 parent 22280f1 commit d072c23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/DBAL/Type/JsonModelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\JsonType;
use Symfony\Component\Serializer\Debug\TraceableNormalizer;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;

abstract class JsonModelType extends JsonType
Expand Down Expand Up @@ -54,12 +55,12 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mix
);
}

public function setObjectNormalizer(AbstractObjectNormalizer $normalizer): void
public function setObjectNormalizer(AbstractObjectNormalizer|TraceableNormalizer $normalizer): void
{
$this->normalizer = $normalizer;
}

protected function getObjectNormalizer(): AbstractObjectNormalizer
protected function getObjectNormalizer(): AbstractObjectNormalizer|TraceableNormalizer
{
if ($this->normalizer === null) {
throw new \RuntimeException('JsonModelType requires object normalizer to be set');
Expand Down
7 changes: 4 additions & 3 deletions src/DBAL/Type/JsonModelTypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Types\Type;
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
use Symfony\Component\Serializer\Debug\TraceableNormalizer;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
Expand All @@ -21,8 +22,8 @@ final class JsonModelTypeRegistry
* @param string $name
* @param class-string $className
* @param bool $override
* @return void
* @throws Exception
* @return void
*/
public static function addType(string $name, string $className, bool $override = false): void
{
Expand All @@ -44,14 +45,14 @@ public static function hasType(string $name): bool
return array_key_exists($name, self::$typesMap);
}

public static function getObjectNormalizer(): AbstractObjectNormalizer
public static function getObjectNormalizer(): AbstractObjectNormalizer|TraceableNormalizer
{
return self::$objectNormalizer ??= new ObjectNormalizer(
nameConverter: new CamelCaseToSnakeCaseNameConverter(),
propertyTypeExtractor: new ReflectionExtractor()
);
}
public static function setObjectNormalizer(AbstractObjectNormalizer $objectNormalizer): void
public static function setObjectNormalizer(AbstractObjectNormalizer|TraceableNormalizer $objectNormalizer): void
{
self::$objectNormalizer = $objectNormalizer;
}
Expand Down

0 comments on commit d072c23

Please sign in to comment.