33namespace Nuxtifyts \PhpDto \Contexts ;
44
55use Nuxtifyts \PhpDto \Attributes \Property \Computed ;
6+ use Nuxtifyts \PhpDto \Attributes \Property \WithRefiner ;
7+ use Nuxtifyts \PhpDto \DataRefiners \DataRefiner ;
68use Nuxtifyts \PhpDto \Enums \Property \Type ;
79use Nuxtifyts \PhpDto \Exceptions \DeserializeException ;
810use Nuxtifyts \PhpDto \Exceptions \SerializeException ;
1214use Nuxtifyts \PhpDto \Support \Traits \HasSerializers ;
1315use Nuxtifyts \PhpDto \Support \Traits \HasTypes ;
1416use ReflectionProperty ;
17+ use ReflectionAttribute ;
1518
1619class PropertyContext
1720{
@@ -28,22 +31,25 @@ class PropertyContext
2831
2932 private(set) bool $ isComputed = false ;
3033
34+ /** @var list<DataRefiner> */
35+ private(set) array $ dataRefiners = [];
36+
3137 /**
3238 * @throws UnsupportedTypeException
3339 */
3440 final private function __construct (
35- protected readonly ReflectionProperty $ _reflectionProperty
41+ protected(set) readonly ReflectionProperty $ reflection
3642 ) {
37- $ this ->syncTypesFromReflectionProperty ($ this ->_reflectionProperty );
43+ $ this ->syncTypesFromReflectionProperty ($ this ->reflection );
3844 $ this ->syncPropertyAttributes ();
3945 }
4046
4147 public string $ propertyName {
42- get => $ this ->_reflectionProperty ->getName ();
48+ get => $ this ->reflection ->getName ();
4349 }
4450
4551 public string $ className {
46- get => $ this ->_reflectionProperty ->getDeclaringClass ()->getName ();
52+ get => $ this ->reflection ->getDeclaringClass ()->getName ();
4753 }
4854
4955 /** @var list<TypeContext<Type>> $arrayTypeContexts */
@@ -73,12 +79,17 @@ private static function getKey(ReflectionProperty $property): string
7379
7480 private function syncPropertyAttributes (): void
7581 {
76- $ this ->isComputed = !empty ($ this ->_reflectionProperty ->getAttributes (Computed::class));
82+ $ this ->isComputed = !empty ($ this ->reflection ->getAttributes (Computed::class));
83+
84+ foreach ($ this ->reflection ->getAttributes (WithRefiner::class) as $ withRefinerAttribute ) {
85+ /** @var ReflectionAttribute<WithRefiner> $withRefinerAttribute */
86+ $ this ->dataRefiners [] = $ withRefinerAttribute ->newInstance ()->getRefiner ();
87+ }
7788 }
7889
7990 public function getValue (object $ object ): mixed
8091 {
81- return $ this ->_reflectionProperty ->getValue ($ object );
92+ return $ this ->reflection ->getValue ($ object );
8293 }
8394
8495 /**
0 commit comments