Sfoglia il codice sorgente

added dbo array deserialize

tags/0.1.4^0
Robin Thoni 8 anni fa
parent
commit
8eb56f03a1
2 ha cambiato i file con 53 aggiunte e 2 eliminazioni
  1. 3
    2
      src/Generator/LuGenerator.php
  2. 50
    0
      src/Generator/dbo_array.php.twig

+ 3
- 2
src/Generator/LuGenerator.php Vedi File

@@ -173,13 +173,14 @@ WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'informat
173 173
         return $array;
174 174
     }
175 175
 
176
-    public function generateDbo($name, $columns, $file)
176
+    public function generateDbo($name, $columns, $file, $fileArray)
177 177
     {
178 178
         $vars = array(
179 179
             "dbo_name" => $name,
180 180
             "columns" => $columns
181 181
         );
182 182
         $this->buildTwig('dbo.php', $file, $vars);
183
+        $this->buildTwig('dbo_array.php', $fileArray, $vars);
183 184
     }
184 185
 
185 186
     public function generateModel($modelName, $modelUserName, $dboName, $columns, $file, $fileUser)
@@ -345,7 +346,7 @@ ORDER BY parameters.ordinal_position;");
345 346
                 $dataAccessName = $baseName . "DataAccess";
346 347
                 $businessName = $baseName . "Business";
347 348
                 $controllerName = $baseName . "Controller";
348
-                $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php");
349
+                $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php", $dbo_dir . $dboName . "Array.php");
349 350
                 $this->generateModel($modelName, $modelUserName, $dboName, $columns, $model_dir . $modelName . ".php",
350 351
                     $model_dir . $modelUserName . ".php");
351 352
                 $this->generateDataAccess($dataAccessName, $modelName, $modelUserName, $dboName,

+ 50
- 0
src/Generator/dbo_array.php.twig Vedi File

@@ -0,0 +1,50 @@
1
+{{ "<?php" }}
2
+
3
+/**
4
+ * AUTO GENERATED BY LUTICATE GENERATOR
5
+ * ANY CHANGES WILL BE OVERWRITTEN
6
+ */
7
+
8
+namespace {{ dbo_namespace.as_it }};
9
+
10
+use Luticate\Utils\LuDbo;
11
+
12
+class {{ dbo_name.camel_upper }}Array extends LuDbo {
13
+
14
+    /**
15
+    * @var {{ dbo_name.camel_upper }}[]
16
+    */
17
+    protected $_array;
18
+    public function getArray()
19
+    {
20
+        return $this->_array;
21
+    }
22
+    public function setArray($value)
23
+    {
24
+        $this->_array = $value;
25
+    }
26
+
27
+    public function jsonSerialize()
28
+    {
29
+        return $this->_array;
30
+    }
31
+
32
+    public static function jsonDeserialize($json)
33
+    {
34
+        $dbo = new {{ dbo_name.camel_upper }}Array();
35
+        $array = [];
36
+        foreach ($json as $data) {
37
+            $array[] = {{ dbo_name.camel_upper }}::jsonDeserialize($data);
38
+        }
39
+        $dbo->setArray($array);
40
+        return $dbo;
41
+    }
42
+
43
+    public static function generateSample()
44
+    {
45
+        return [
46
+            {{ dbo_name.camel_upper }}::generateSample(),
47
+            {{ dbo_name.camel_upper }}::generateSample()
48
+        ];
49
+    }
50
+}

Loading…
Annulla
Salva