44
55use  BackedEnum ;
66use  Carbon \Carbon ;
7+ use  Kellton \Tools \Features \Data \Attributes \Validation \Rule ;
78use  Kellton \Tools \Features \Data \Attributes \Validation \ValidationAttribute ;
89use  Kellton \Tools \Features \Data \Definition ;
910use  Kellton \Tools \Features \Data \Exceptions \MissingConstructor ;
@@ -39,7 +40,9 @@ public function __construct(public readonly DefinitionService $definitionService
3940     */ 
4041    public  function  get (Definition $ definitionCollection 
4142    {
42-         return  $ definitionproperties ->mapWithKeys (fn  (Property $ property$ this resolve ($ propertyall ());
43+         $ data$ definitionproperties ->mapWithKeys (fn  (Property $ property$ this resolve ($ propertyall ());
44+ 
45+         return  $ data
4346    }
4447
4548    /** 
@@ -77,7 +80,7 @@ private function resolve(Property $property): Collection
7780            return  $ this getNestedRules ($ property$ propertyName
7881        }
7982
80-         return  collect ([$ propertyName$ this getRulesForProperty ($ property
83+         return  collect ([$ propertyName$ this getDataForProperty ($ property
8184    }
8285
8386    /** 
@@ -87,9 +90,14 @@ private function resolve(Property $property): Collection
8790     * 
8891     * @return Collection 
8992     */ 
90-     protected  function  getRulesForProperty (Property $ propertyCollection 
93+     protected  function  getDataForProperty (Property $ propertyCollection 
9194    {
92-         $ rulescollect ();
95+         $ datacollect ([
96+             'rules '  => collect (),
97+             'messages '  => collect (),
98+         ]);
99+ 
100+         $ rules$ dataget ('rules ' );
93101
94102        if  ($ propertyisNullable ) {
95103            $ rulesadd ('nullable ' );
@@ -108,9 +116,9 @@ protected function getRulesForProperty(Property $property): Collection
108116        }
109117
110118        $ this resolveTypes ($ property$ rules
111-         $ this resolveAttributeRules ($ property$ rules 
119+         $ this resolveAttributeRules ($ property$ data 
112120
113-         return  $ rules 
121+         return  $ data 
114122    }
115123
116124    /** 
@@ -132,7 +140,7 @@ protected function getNestedRules(Property $property, string $propertyName): Col
132140            default  => throw  new  TypeError ()
133141        };
134142
135-         $ parentRules$ this getRulesForProperty ($ property
143+         $ parentRules$ this getDataForProperty ($ property
136144
137145        $ definition$ this definitionService ->get ($ propertydataClass );
138146        $ rules$ this get ($ definition
@@ -179,17 +187,20 @@ private function resolveTypes(Property $property, Collection $rules): void
179187     * Resolve rules for the attributes. 
180188     * 
181189     * @param Property $property 
182-      * @param Collection $rules  
190+      * @param Collection $data  
183191     * 
184192     * @return void 
185193     */ 
186-     private  function  resolveAttributeRules (Property $ propertyCollection $ rules void 
194+     private  function  resolveAttributeRules (Property $ propertyCollection $ data void 
187195    {
188196        $ property
189197            ->attributes 
190198            ->filter (fn  (object $ attributeis_subclass_of ($ attribute
191-             ->each (function  (ValidationAttribute $ ruleuse  ($ rules
192-                 $ rulesadd ($ rulerule );
199+             ->each (function  (ValidationAttribute $ ruleuse  ($ data
200+                 $ dataget ('rules ' )->add ($ rulerule );
201+                 if  ($ ruleinstanceof  Rule && $ rulemessage  !== null ) {
202+                     $ dataget ('messages ' )->put ($ rulerule , $ rulemessage );
203+                 }
193204            });
194205    }
195206}
0 commit comments