Browse Source

dbo deserialize; dbo generate sample

tags/0.1.1
Robin Thoni 8 years ago
parent
commit
5060fdc3d8
2 changed files with 34 additions and 1 deletions
  1. 13
    1
      src/Generator/LuGenerator.php
  2. 21
    0
      src/Generator/dbo.php.twig

+ 13
- 1
src/Generator/LuGenerator.php View File

@@ -153,8 +153,20 @@ WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'informat
153 153
 
154 154
     public function sqlTypeToPhpType($type)
155 155
     {
156
-        if ($type == "character" || $type == "character varying")
156
+        if ($type == "character" || $type == "character varying" || $type == "char"
157
+            || $type == "varchar" || $type == "bytea") {
157 158
             return "string";
159
+        }
160
+        if ($type == "bigint" || $type == "bigserial" || $type == "serial8" || $type == "serial2"
161
+            || $type == "serial4" || $type == "int8" || $type == "int2" || $type == "integer" || $type == "smallint") {
162
+            return "integer";
163
+        }
164
+        if ($type == "decimal" || $type == "real" || $type == "double precision" || $type == "float8") {
165
+            return "double";
166
+        }
167
+        if ($type == "bit" || $type == "bit varying" || $type == "varbit" || $type == "boolean" || $type == "bool") {
168
+            return "boolean";
169
+        }
158 170
         return $type;
159 171
     }
160 172
 

+ 21
- 0
src/Generator/dbo.php.twig View File

@@ -19,6 +19,27 @@ class {{ dbo_name.camel_upper }} extends LuDbo {
19 19
 {% endfor %}
20 20
         );
21 21
     }
22
+
23
+    public static function jsonDeserialize($json)
24
+    {
25
+        $dbo = new {{ dbo_name.camel_upper }}();
26
+{% for column in columns %}
27
+        $dbo->set{{ column.name.camel_upper }}($json["{{ column.name.camel_upper }}"]);
28
+{% endfor %}
29
+        return $dbo;
30
+    }
31
+
32
+    public static function generateSample()
33
+    {
34
+        $dbo = new {{ dbo_name.camel_upper }}();
35
+{% for column in columns %}
36
+        $dbo->set{{ column.name.camel_upper }}({% if column.data_type.php.as_it == "double" %}42.42{%
37
+elseif column.data_type.php.as_it == "integer" %}42{%
38
+elseif column.data_type.php.as_it == "boolean" %}true{%
39
+else %}"sample string"{% endif %});
40
+{% endfor %}
41
+        return $dbo;
42
+    }
22 43
 {% for column in columns %}
23 44
 
24 45
     /**

Loading…
Cancel
Save