Explorar el Código

Added class for model generation

tags/0.1.0
Robin Thoni hace 9 años
padre
commit
57fd2dede1
Se han modificado 3 ficheros con 31 adiciones y 13 borrados
  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 Ver fichero

@@ -163,15 +163,20 @@ WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'informat
163 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 168
         $vars = array(
169 169
             "model_name" => $modelName,
170
+            "model_user_name" => $modelUserName,
170 171
             "dbo_name" => $dboName,
171 172
             "columns" => $columns,
172 173
             "namespace" => $namespace
173 174
         );
174 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 182
     public function getStoredProcedures()
@@ -289,14 +294,15 @@ ORDER BY parameters.ordinal_position;");
289 294
                     continue;
290 295
                 $columns = $this->sqlTypesToPhpTypes($columns);
291 296
                 $baseName = $this->snakeToCamelCase($table_name, true);
292
-                $modelName = $baseName;
297
+                $modelName = $baseName . "Model";
298
+                $modelUserName = $baseName;
293 299
                 $dboName = $baseName . "Dbo";
294 300
                 $dataAccessName = $baseName . "DataAccess";
295 301
                 $businessName = $baseName . "Business";
296 302
                 $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php",
297 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 306
                 $this->generateDataAccess($dataAccessName, $modelName, $dboName,
301 307
                     $manager_dir . $dataAccessName . ".php", $this->_config["dataaccess"]["namespace"]);
302 308
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,

+ 12
- 9
src/Generator/model.php.twig Ver fichero

@@ -1,8 +1,11 @@
1 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 11
 namespace {{ namespace.as_it }};
@@ -31,18 +34,18 @@ class {{ model_name.camel_upper }} extends LuModel
31 34
 
32 35
     /**
33 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 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 47
 {% endfor %}
45 48
 
46
-        return $dam;
49
+        return $model;
47 50
     }
48 51
 }

+ 9
- 0
src/Generator/model_user.php.twig Ver fichero

@@ -0,0 +1,9 @@
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…
Cancelar
Guardar