77use Astral \Serialize \Casts \InputValue \InputObjectBestMatchChildCast ;
88use Astral \Serialize \Casts \InputValue \InputValueEnumCast ;
99use Astral \Serialize \Casts \InputValue \InputValueNullCast ;
10+ use Astral \Serialize \Casts \Normalizer \ArrayNormalizerCast ;
11+ use Astral \Serialize \Casts \Normalizer \JsonNormalizerCast ;
1012use Astral \Serialize \Casts \OutValue \OutArrayChildCast ;
1113use Astral \Serialize \Casts \OutValue \OutValueEnumCast ;
1214use Astral \Serialize \Casts \OutValue \OutValueGetterCast ;
1315use Astral \Serialize \Contracts \Attribute \DataCollectionCastInterface ;
1416use Astral \Serialize \Contracts \Attribute \InputValueCastInterface ;
1517use Astral \Serialize \Contracts \Attribute \OutValueCastInterface ;
18+ use Astral \Serialize \Contracts \Normalizer \NormalizerCastInterface ;
1619use Astral \Serialize \Enums \CacheDriverEnum ;
1720use Astral \Serialize \Exceptions \NotFoundAttributePropertyResolver ;
1821use Astral \Serialize \Support \Caching \MemoryCache ;
@@ -40,6 +43,12 @@ class ConfigManager
4043 OutValueGetterCast::class,
4144 ];
4245
46+ /** @var (NormalizerCastInterface|string)[] $normalizerCasts */
47+ private array $ normalizerCasts = [
48+ // JsonNormalizerCast::class,
49+ ArrayNormalizerCast::class,
50+ ];
51+
4352 /** @var CacheDriverEnum|class-string $cacheDriver */
4453 private string |CacheDriverEnum $ cacheDriver = MemoryCache::class;
4554
@@ -52,13 +61,30 @@ public function __construct()
5261 foreach ($ this ->outputValueCasts as $ key => $ cast ) {
5362 $ this ->outputValueCasts [$ key ] = new $ cast ();
5463 }
64+
65+ foreach ($ this ->normalizerCasts as $ key => $ cast ) {
66+ $ this ->normalizerCasts [$ key ] = new $ cast ();
67+ }
5568 }
5669
5770 public static function getInstance (): ConfigManager
5871 {
5972 return self ::$ instance ??= new self ();
6073 }
6174
75+ /**
76+ * @throws NotFoundAttributePropertyResolver
77+ */
78+ public function addNormalizerCasts (NormalizerCastInterface |string $ resolverClass ): static
79+ {
80+ if (is_string ($ resolverClass ) && !is_subclass_of ($ resolverClass , NormalizerCastInterface::class)) {
81+ throw new NotFoundAttributePropertyResolver ('Resolver class must be an instance of NormalizerCastInterface ' );
82+ }
83+ $ this ->attributePropertyResolver [] = (is_string ($ resolverClass ) ? new $ resolverClass () : $ resolverClass );
84+
85+ return $ this ;
86+ }
87+
6288 /**
6389 * @throws NotFoundAttributePropertyResolver
6490 */
@@ -113,6 +139,11 @@ public function getOutValueCasts(): array
113139 return $ this ->outputValueCasts ;
114140 }
115141
142+ public function getNormalizerCasts (): array
143+ {
144+ return $ this ->normalizerCasts ;
145+ }
146+
116147 public function getCacheDriver (): string
117148 {
118149 if ($ this ->cacheDriver instanceof CacheDriverEnum) {
0 commit comments