Browse Source

Added class for model generation

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
57fd2dede1
3 changed files with 31 additions and 13 deletions
  1. 10
    4
      src/Generator/LuGenerator.php
  2. 12
    9
      src/Generator/model.php.twig
  3. 9
    0
      src/Generator/model_user.php.twig

+ 10
- 4
src/Generator/LuGenerator.php View File

163
         $this->buildTwig('dbo.php', $file, $vars);
163
         $this->buildTwig('dbo.php', $file, $vars);
164
     }
164
     }
165
 
165
 
166
-    public function generateModel($modelName, $dboName, $columns, $file, $namespace)
166
+    public function generateModel($modelName, $modelUserName, $dboName, $columns, $file, $fileUser, $namespace)
167
     {
167
     {
168
         $vars = array(
168
         $vars = array(
169
             "model_name" => $modelName,
169
             "model_name" => $modelName,
170
+            "model_user_name" => $modelUserName,
170
             "dbo_name" => $dboName,
171
             "dbo_name" => $dboName,
171
             "columns" => $columns,
172
             "columns" => $columns,
172
             "namespace" => $namespace
173
             "namespace" => $namespace
173
         );
174
         );
174
         $this->buildTwig('model.php', $file, $vars);
175
         $this->buildTwig('model.php', $file, $vars);
176
+
177
+        if (file_exists($fileUser))
178
+            return;
179
+        $this->buildTwig('model_user.php', $fileUser, $vars);
175
     }
180
     }
176
 
181
 
177
     public function getStoredProcedures()
182
     public function getStoredProcedures()
289
                     continue;
294
                     continue;
290
                 $columns = $this->sqlTypesToPhpTypes($columns);
295
                 $columns = $this->sqlTypesToPhpTypes($columns);
291
                 $baseName = $this->snakeToCamelCase($table_name, true);
296
                 $baseName = $this->snakeToCamelCase($table_name, true);
292
-                $modelName = $baseName;
297
+                $modelName = $baseName . "Model";
298
+                $modelUserName = $baseName;
293
                 $dboName = $baseName . "Dbo";
299
                 $dboName = $baseName . "Dbo";
294
                 $dataAccessName = $baseName . "DataAccess";
300
                 $dataAccessName = $baseName . "DataAccess";
295
                 $businessName = $baseName . "Business";
301
                 $businessName = $baseName . "Business";
296
                 $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php",
302
                 $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php",
297
                     $this->_config["dbo"]["namespace"]);
303
                     $this->_config["dbo"]["namespace"]);
298
-                $this->generateModel($modelName, $dboName, $columns, $model_dir . $modelName . ".php",
299
-                    $this->_config["models"]["namespace"]);
304
+                $this->generateModel($modelName, $modelUserName, $dboName, $columns, $model_dir . $modelName . ".php",
305
+                    $model_dir . $modelUserName . ".php", $this->_config["models"]["namespace"]);
300
                 $this->generateDataAccess($dataAccessName, $modelName, $dboName,
306
                 $this->generateDataAccess($dataAccessName, $modelName, $dboName,
301
                     $manager_dir . $dataAccessName . ".php", $this->_config["dataaccess"]["namespace"]);
307
                     $manager_dir . $dataAccessName . ".php", $this->_config["dataaccess"]["namespace"]);
302
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,
308
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,

+ 12
- 9
src/Generator/model.php.twig View File

1
 {{ "<?php" }}
1
 {{ "<?php" }}
2
 
2
 
3
 /**
3
 /**
4
-* AUTO GENERATED BY LUTICATE GENERATOR
5
-* ANY CHANGES WILL BE OVERWRITTEN
4
+ * AUTO GENERATED BY LUTICATE GENERATOR
5
+ * ANY CHANGES WILL BE OVERWRITTEN
6
+ * DO NOT DIRECTLY USE THIS FILE
7
+ * USE {{ model_user_name.camel_upper }}.php
8
+ * TO MAKE YOUR CHANGES AND DATABASE ACCESS
6
 */
9
 */
7
 
10
 
8
 namespace {{ namespace.as_it }};
11
 namespace {{ namespace.as_it }};
31
 
34
 
32
     /**
35
     /**
33
      * @param $dbo \App\Http\DBO\{{ dbo_name.camel_upper }}
36
      * @param $dbo \App\Http\DBO\{{ dbo_name.camel_upper }}
34
-     * @param $dam LuModel|null
35
-     * @return {{ model_name.camel_upper }}
37
+     * @param $model LuModel|null
38
+     * @return {{ model_user_name.camel_upper }}
36
      */
39
      */
37
-    public function fromDbo($dbo, $dam = null)
40
+    public function fromDbo($dbo, $model = null)
38
     {
41
     {
39
-        if (is_null($dam))
40
-            $dam = new {{ model_name.camel_upper }}();
42
+        if (is_null($model))
43
+            $model = new {{ model_user_name.camel_upper }}();
41
 
44
 
42
 {% for column in columns %}
45
 {% for column in columns %}
43
-        $dam->{{ column.name.as_it }} = $dbo->get{{ column.name.camel_upper }}();
46
+        $model->{{ column.name.as_it }} = $dbo->get{{ column.name.camel_upper }}();
44
 {% endfor %}
47
 {% endfor %}
45
 
48
 
46
-        return $dam;
49
+        return $model;
47
     }
50
     }
48
 }
51
 }

+ 9
- 0
src/Generator/model_user.php.twig View File

1
+{{ "<?php" }}
2
+
3
+namespace {{ namespace.as_it }};
4
+
5
+use App\Http\DBO\{{ dbo_name.camel_upper }};
6
+
7
+class {{ model_user_name.camel_upper }} extends {{ model_name.camel_upper }}
8
+{
9
+}

Loading…
Cancel
Save