@@ -19,47 +19,68 @@ public function mainAction($arguments = [])
1919            return  1 ;
2020        }
2121
22-         $ namespaceisset ($ arguments0 ]) && $ arguments0 ] != 'none ' ) ? $ arguments0 ] : null ;
23-         $ traitisset ($ arguments1 ]) && $ arguments1 ] != 'none ' ) ? $ arguments1 ] : null ;
24-         $ extends'\Phalcon\Forms\Form ' ;
25-         $ extendsisset ($ arguments2 ]) ? ($ arguments2 ] == 'null '  ? $ extends$ arguments2 ] == 'none '  ? null  : $ arguments2 ])) : $ extends
22+         print_r ($ arguments
23+ 
24+         $ namespaceNameisset ($ arguments0 ]) && $ arguments0 ] != 'none ' ) ? $ arguments0 ] : null ;
25+         $ traitNameisset ($ arguments1 ]) && $ arguments1 ] != 'none ' ) ? $ arguments1 ] : null ;
26+         $ extendsName'\Phalcon\Forms\Form ' ;
27+         $ extendsNameisset ($ arguments2 ]) ? ($ arguments2 ] == 'null '  ? $ extendsName$ arguments2 ] == 'none '  ? null  : $ arguments2 ])) : $ extendsName
2628
2729        echo  "Generation started. " , PHP_EOL ;
2830
2931        $ tables$ this db ->listTables ();
3032        foreach  ($ tablesas  $ table
3133            echo  "Processing table ` {$ table`...  " ;
3234
33-             $ classPhalcon \Text::camelize ($ table
35+             $ classNamePhalcon \Text::camelize ($ table
36+ 
37+             $ classnew  \Nette \PhpGenerator \ClassType ($ className"Form " );
38+             if  ($ extendsNamenull ) {
39+                 $ classsetExtends ($ extendsName
40+             }
41+             if  ($ traitNamenull ) {
42+                 $ classaddTrait ($ traitName
43+             }
3444
35-             $ columns
3645            $ columnsList$ this db ->describeColumns ($ table
3746            foreach  ($ columnsListas  $ column
3847                if  ($ columnisPrimary ()) {
3948                    continue ;
4049                }
41-                 $ columns []  = [
50+                 $ columnInfo 
4251                    "name "  => lcfirst (\Phalcon \Text::camelize ($ columngetName ())),
4352                    "type "  => $ this getBestPhalconType ($ column
4453                    "size "  => $ columngetSize ()
4554                ];
55+                 $ method$ classaddMethod ($ columnInfo'name ' ] . "Field " );
56+                 $ methodsetVisibility ('private ' );
57+                 $ methodaddBody ('$element = new \Phalcon\Forms\Element \\'  . $ columnInfo'type ' ] . '(" '  . $ columnInfo'name ' ] . '"); ' );
58+                 $ methodaddBody ('$element->setLabel(" '  . $ columnInfo'name ' ] . '"); ' );
59+                 if  ($ columnInfo'type ' ] == 'Select ' ) {
60+                     $ methodaddBody ('$element->setOptions([]); ' );
61+                 }
62+ 
63+                 if  ($ columnInfo'type ' ] == 'Text '  && $ columnInfo'size ' ]) {
64+                     $ methodaddBody ('$element->addValidator(new \Phalcon\Validation\Validator\StringLength([ ' );
65+                     $ methodaddBody ('    "max" =>  '  . $ columnInfo'size ' ]);
66+                     $ methodaddBody ('])); ' );
67+                 }
68+                 $ methodaddBody ('return $element; ' );
4669            }
4770
48-             $ this view ->start ();
49-             $ this view ->setVar ("class " , $ class
50-             $ this view ->setVar ("namespace " , $ namespace
51-             $ this view ->setVar ("trait " , $ trait
52-             $ this view ->setVar ("extends " , $ extends
53-             $ this view ->setVar ("columns " , $ columns
54-             $ this view ->render ('main ' , 'DefaultForm ' );
55-             $ this view ->finish ();
71+             $ content"<?php "  . PHP_EOL  . PHP_EOL ;
72+             if  ($ namespaceNamenull ) {
73+                 $ content"namespace  "  . $ namespaceName"; "  . PHP_EOL  . PHP_EOL ;
74+             }
75+             $ contentstring )$ class
5676
57-             if  (file_put_contents ($ this outputFolder  . "/ "  . $ class "Form.php " , $ this -> view -> getContent () ) === false ) {
77+             if  (file_put_contents ($ this outputFolder  . "/ "  . $ className "Form.php " , $ content false ) {
5878                echo  "Impossible to write the file in the output folder. " , PHP_EOL ;
5979                echo  "Please check the permissions for ` {$ this outputFolder }`. " , PHP_EOL ;
6080                echo  "Script aborted. " ;
6181                return  1 ;
6282            }
83+ 
6384            echo  "done " , PHP_EOL ;
6485        }
6586
0 commit comments