@@ -19,6 +19,56 @@ public static function tableName()
1919 return <?= var_export ($ tableName ) ?> ;
2020 }
2121
22+ public function rules()
23+ {
24+ return [
25+ <?php
26+ $ safeAttributes = [];
27+ $ requiredAttributes = [];
28+ $ integerAttributes = [];
29+ $ stringAttributes = [];
30+
31+ foreach ($ attributes as $ attribute ) {
32+ if ($ attribute ['readOnly ' ]) {
33+ continue ;
34+ }
35+ if ($ attribute ['required ' ]) {
36+ $ requiredAttributes [$ attribute ['name ' ]] = $ attribute ['name ' ];
37+ }
38+ switch ($ attribute ['type ' ]) {
39+ case 'integer ' :
40+ $ integerAttributes [$ attribute ['name ' ]] = $ attribute ['name ' ];
41+ break ;
42+ case 'string ' :
43+ $ stringAttributes [$ attribute ['name ' ]] = $ attribute ['name ' ];
44+ break ;
45+ default :
46+ case 'array ' :
47+ $ safeAttributes [$ attribute ['name ' ]] = $ attribute ['name ' ];
48+ break ;
49+ }
50+ }
51+ if (!empty ($ stringAttributes )) {
52+ echo " [[' " . implode ("', ' " , $ stringAttributes ) . "'], 'trim'], \n" ;
53+ }
54+ if (!empty ($ requiredAttributes )) {
55+ echo " [[' " . implode ("', ' " , $ requiredAttributes ) . "'], 'required'], \n" ;
56+ }
57+ if (!empty ($ stringAttributes )) {
58+ echo " [[' " . implode ("', ' " , $ stringAttributes ) . "'], 'string'], \n" ;
59+ }
60+ if (!empty ($ integerAttributes )) {
61+ echo " [[' " . implode ("', ' " , $ integerAttributes ) . "'], 'integer'], \n" ;
62+ }
63+ if (!empty ($ safeAttributes )) {
64+ echo " // TODO define more concreate validation rules! \n" ;
65+ echo " [[' " . implode ("',' " , $ safeAttributes ) . "'], 'safe'], \n" ;
66+ }
67+
68+ ?>
69+ ];
70+ }
71+
2272<?php foreach ($ relations as $ relationName => $ relation ): ?>
2373 public function get<?= ucfirst ($ relationName ) ?> ()
2474 {
0 commit comments