Ver código fonte

changed to luticate2

develop
Robin Thoni 8 anos atrás
pai
commit
d202798b93

+ 3
- 2
composer.json Ver arquivo

@@ -12,9 +12,10 @@
12 12
       "url":  "https://git.rthoni.com/luticate/api-utils.git"
13 13
     }],
14 14
     "require": {
15
-      "vlucas/phpdotenv": "~1.0",
16 15
       "twig/twig": "1.x",
17
-      "luticate/utils": "0.1.x"
16
+      "luticate/utils": "dev-develop"
17
+    },
18
+    "require-dev": {
18 19
     },
19 20
     "autoload": {
20 21
       "psr-4": {

+ 21
- 47
src/Generator/LuGenerator.php Ver arquivo

@@ -6,40 +6,35 @@ use PDO;
6 6
 use Twig_Autoloader;
7 7
 use Twig_Environment;
8 8
 use Twig_Loader_Filesystem;
9
-use Luticate\Utils\LuStringUtils;
9
+use Luticate\Utils\Business\LuStringUtils;
10 10
 
11 11
 class LuGenerator {
12 12
     private $_pdo;
13 13
 
14 14
     private $_config = array("dbo" =>
15 15
         array(
16
-            "namespace" => 'App\Http\DBO',
17
-            "folder" => '../app/Http/DBO'
16
+            "namespace" => 'App\Dbo',
17
+            "folder" => '../app/Dbo'
18 18
         ),
19
-        "models" =>
20
-            array(
21
-                "namespace" => 'App\Http\DataAccess\Models',
22
-                "folder" => '../app/Http/DataAccess/Models'
23
-            ),
24 19
         "sp" =>
25 20
             array(
26
-                "namespace" => 'App\Http\DataAccess\SP',
27
-                "folder" => '../app/Http/DataAccess/SP'
21
+                "namespace" => 'App\DataAccess\SP',
22
+                "folder" => '../app/DataAccess/SP'
28 23
             ),
29 24
         "dataaccess" =>
30 25
             array(
31
-                "namespace" => 'App\Http\DataAccess',
32
-                "folder" => '../app/Http/DataAccess'
26
+                "namespace" => 'App\DataAccess',
27
+                "folder" => '../app/DataAccess'
33 28
             ),
34 29
         "business" =>
35 30
             array(
36
-                "namespace" => 'App\Http\Business',
37
-                "folder" => '../app/Http/Business'
31
+                "namespace" => 'App\Business',
32
+                "folder" => '../app/Business'
38 33
             ),
39 34
         "controller" =>
40 35
             array(
41
-                "namespace" => 'App\Http\Controller',
42
-                "folder" => '../app/Http/Controller'
36
+                "namespace" => 'App\Controller',
37
+                "folder" => '../app/Controller'
43 38
             ),
44 39
         "mode" => 0775,
45 40
         "ignore" => array(
@@ -88,8 +83,8 @@ class LuGenerator {
88 83
             {
89 84
                 $vars[$key] = array(
90 85
                     "as_it" => $value,
91
-                    "camel_upper" => LuStringUtils::stringSnakeToCamelCase($value, true),
92
-                    "camel_lower" => LuStringUtils::stringSnakeToCamelCase($value, false)
86
+                    "camel_upper" => LuStringUtils::snakeToCamelCase($value, true),
87
+                    "camel_lower" => LuStringUtils::snakeToCamelCase($value, false)
93 88
                 );
94 89
             }
95 90
         }
@@ -99,7 +94,6 @@ class LuGenerator {
99 94
     protected function buildTwig($templateFile, $destFile, $vars)
100 95
     {
101 96
         $vars["dbo_namespace"] = $this->_config["dbo"]["namespace"];
102
-        $vars["models_namespace"] = $this->_config["models"]["namespace"];
103 97
         $vars["sp_namespace"] = $this->_config["sp"]["namespace"];
104 98
         $vars["dataaccess_namespace"] = $this->_config["dataaccess"]["namespace"];
105 99
         $vars["business_namespace"] = $this->_config["business"]["namespace"];
@@ -110,7 +104,7 @@ class LuGenerator {
110 104
         Twig_Autoloader::register();
111 105
         $loader = new Twig_Loader_Filesystem(__DIR__ );
112 106
         $twig = new Twig_Environment($loader, array());
113
-        $template = $twig->loadTemplate($templateFile . '.twig');
107
+        $template = $twig->loadTemplate('templates/' . $templateFile . '.twig');
114 108
         $content = $template->render($twig_vars);
115 109
         file_put_contents($destFile, $content);
116 110
     }
@@ -183,21 +177,6 @@ WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'informat
183 177
         $this->buildTwig('dbo_array.php', $fileArray, $vars);
184 178
     }
185 179
 
186
-    public function generateModel($modelName, $modelUserName, $dboName, $columns, $file, $fileUser)
187
-    {
188
-        $vars = array(
189
-            "model_name" => $modelName,
190
-            "model_user_name" => $modelUserName,
191
-            "dbo_name" => $dboName,
192
-            "columns" => $columns
193
-        );
194
-        $this->buildTwig('model.php', $file, $vars);
195
-
196
-        if (file_exists($fileUser))
197
-            return;
198
-        $this->buildTwig('model_user.php', $fileUser, $vars);
199
-    }
200
-
201 180
     public function getStoredProcedures()
202 181
     {
203 182
         $spQuery = $this->_pdo->prepare("SELECT r.routine_name AS sp_name, r.data_type AS data_type, proc.proretset AS proretset, proc.prosrc AS prosrc
@@ -256,14 +235,14 @@ ORDER BY parameters.ordinal_position;");
256 235
         $this->buildTwig('sp.php', $file, $vars);
257 236
     }
258 237
 
259
-    public function generateDataAccess($dataAccessName, $modelName, $modelUserName, $dboName, $file)
238
+    public function generateDataAccess($table_name, $connection_name, $dataAccessName, $dboName, $file)
260 239
     {
261 240
         if (file_exists($file))
262 241
             return;
263 242
         $vars = array(
264 243
             "data_access_name" => $dataAccessName,
265
-            "model_name" => $modelName,
266
-            "model_user_name" => $modelUserName,
244
+            "connection_name" => $connection_name,
245
+            "table_name" => $table_name,
267 246
             "dbo_name" => $dboName
268 247
         );
269 248
         $this->buildTwig('dataaccess.php', $file, $vars);
@@ -312,18 +291,17 @@ ORDER BY parameters.ordinal_position;");
312 291
     public function run()
313 292
     {
314 293
         $dbo_dir = $this->_config["dbo"]["folder"] . "/";
315
-        $model_dir = $this->_config["models"]["folder"] . "/";
316 294
         $sp_dir = $this->_config["sp"]["folder"] . "/";
317 295
         $sp_src_dir = $this->_config["sp"]["folder"] . "/src/";
318 296
         $manager_dir = $this->_config["dataaccess"]["folder"] . "/";
319 297
         $business_dir = $this->_config["business"]["folder"] . "/";
320 298
         $controller_dir = $this->_config["controller"]["folder"] . "/";
299
+        $connection_name = getenv("DB_CONNECTION_NAME");
321 300
 
322 301
         $mode = $this->_config["mode"];
323 302
 
324 303
         umask(0000);
325 304
         $this->mkdir($dbo_dir, $mode);
326
-        $this->mkdir($model_dir, $mode);
327 305
         $this->mkdir($sp_dir, $mode);
328 306
         $this->mkdir($sp_src_dir, $mode);
329 307
         $this->mkdir($manager_dir, $mode);
@@ -342,17 +320,13 @@ ORDER BY parameters.ordinal_position;");
342 320
                 if (is_null($columns))
343 321
                     continue;
344 322
                 $columns = $this->sqlTypesToPhpTypes($columns);
345
-                $baseName = LuStringUtils::stringSnakeToCamelCase($table_name, true);
346
-                $modelName = $baseName . "Model";
347
-                $modelUserName = $baseName;
323
+                $baseName = LuStringUtils::snakeToCamelCase($table_name, true);
348 324
                 $dboName = $baseName . "Dbo";
349 325
                 $dataAccessName = $baseName . "DataAccess";
350 326
                 $businessName = $baseName . "Business";
351 327
                 $controllerName = $baseName . "Controller";
352 328
                 $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php", $dbo_dir . $dboName . "Array.php");
353
-                $this->generateModel($modelName, $modelUserName, $dboName, $columns, $model_dir . $modelName . ".php",
354
-                    $model_dir . $modelUserName . ".php");
355
-                $this->generateDataAccess($dataAccessName, $modelName, $modelUserName, $dboName,
329
+                $this->generateDataAccess($table_name, $connection_name, $dataAccessName, $dboName,
356 330
                     $manager_dir . $dataAccessName . ".php");
357 331
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,
358 332
                     $business_dir . $businessName . ".php");
@@ -378,7 +352,7 @@ ORDER BY parameters.ordinal_position;");
378 352
                     continue;
379 353
                 $args["in"] = $this->sqlTypesToPhpTypes($args["in"]);
380 354
                 $args["out"] = $this->sqlTypesToPhpTypes($args["out"]);
381
-                $sp_model_name = LuStringUtils::stringSnakeToCamelCase($sp_name, true);
355
+                $sp_model_name = LuStringUtils::snakeToCamelCase($sp_name, true);
382 356
                 $this->generateSp($sp, $args, $sp_dir . $sp_model_name . ".php", $sp_src_dir . $sp_name . ".sql");
383 357
             }
384 358
         }

+ 0
- 14
src/Generator/dataaccess.php.twig Ver arquivo

@@ -1,14 +0,0 @@
1
-{{ "<?php" }}
2
-
3
-namespace {{ dataaccess_namespace.as_it }};
4
-
5
-use Luticate\Utils\LuDataAccess;
6
-use {{ models_namespace.as_it }}\{{ model_user_name.as_it }};
7
-use {{ dbo_namespace.as_it }}\{{ dbo_name.as_it }};
8
-
9
-class {{ data_access_name.as_it }} extends LuDataAccess {
10
-    protected static function getModel()
11
-    {
12
-        return new {{ model_user_name.as_it }}();
13
-    }
14
-}

+ 0
- 60
src/Generator/dbo.php.twig Ver arquivo

@@ -1,60 +0,0 @@
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 }} extends LuDbo {
13
-
14
-    public function jsonSerialize()
15
-    {
16
-        return array(
17
-{% for column in columns %}
18
-            "{{ column.name.camel_upper }}" => $this->_{{ column.name.camel_lower }}{{ loop.last ? "" : "," }}
19
-{% endfor %}
20
-        );
21
-    }
22
-
23
-    public static function jsonDeserialize($json)
24
-    {
25
-        $dbo = new {{ dbo_name.camel_upper }}();
26
-{% for column in columns %}
27
-        if (isset($json["{{ column.name.camel_upper }}"])) {
28
-            $dbo->set{{ column.name.camel_upper }}($json["{{ column.name.camel_upper }}"]);
29
-        }
30
-{% endfor %}
31
-        return $dbo;
32
-    }
33
-
34
-    public static function generateSample()
35
-    {
36
-        $dbo = new {{ dbo_name.camel_upper }}();
37
-{% for column in columns %}
38
-        $dbo->set{{ column.name.camel_upper }}({% if column.data_type.php.as_it == "double" %}42.42{%
39
-elseif column.data_type.php.as_it == "integer" %}42{%
40
-elseif column.data_type.php.as_it == "boolean" %}true{%
41
-else %}"sample string"{% endif %});
42
-{% endfor %}
43
-        return $dbo;
44
-    }
45
-{% for column in columns %}
46
-
47
-    /**
48
-     * @var {{ column.data_type.php.as_it }}
49
-     */
50
-    protected $_{{ column.name.camel_lower }};
51
-    public function get{{ column.name.camel_upper }}()
52
-    {
53
-        return $this->_{{ column.name.camel_lower }};
54
-    }
55
-    public function set{{ column.name.camel_upper }}($value)
56
-    {
57
-        $this->_{{ column.name.camel_lower }} = $value;
58
-    }
59
-{% endfor %}
60
-}

+ 0
- 51
src/Generator/model.php.twig Ver arquivo

@@ -1,51 +0,0 @@
1
-{{ "<?php" }}
2
-
3
-/**
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
9
-*/
10
-
11
-namespace {{ models_namespace.as_it }};
12
-
13
-use Luticate\Utils\LuModel;
14
-use {{ dbo_namespace.as_it }}\{{ dbo_name.camel_upper }};
15
-
16
-class {{ model_name.camel_upper }} extends LuModel
17
-{
18
-    function __construct()
19
-    {
20
-        parent::__construct();
21
-        $this->timestamps = false;
22
-    }
23
-
24
-    public function toDbo()
25
-    {
26
-        $dbo = new {{ dbo_name.camel_upper }}();
27
-
28
-{% for column in columns %}
29
-        $dbo->set{{ column.name.camel_upper }}($this->{{ column.name.as_it }});
30
-{% endfor %}
31
-
32
-        return $dbo;
33
-    }
34
-
35
-    /**
36
-     * @param $dbo {{ dbo_name.camel_upper }}
37
-     * @param $model LuModel|null
38
-     * @return {{ model_user_name.camel_upper }}
39
-     */
40
-    public function fromDbo($dbo, $model = null)
41
-    {
42
-        if (is_null($model))
43
-            $model = new {{ model_user_name.camel_upper }}();
44
-
45
-{% for column in columns %}
46
-        $model->{{ column.name.as_it }} = $dbo->get{{ column.name.camel_upper }}();
47
-{% endfor %}
48
-
49
-        return $model;
50
-    }
51
-}

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

@@ -1,9 +0,0 @@
1
-{{ "<?php" }}
2
-
3
-namespace {{ models_namespace.as_it }};
4
-
5
-use {{ dbo_namespace.as_it }}\{{ dbo_name.camel_upper }};
6
-
7
-class {{ model_user_name.camel_upper }} extends {{ model_name.camel_upper }}
8
-{
9
-}

src/Generator/business.php.twig → src/Generator/templates/business.php.twig Ver arquivo

@@ -2,7 +2,7 @@
2 2
 
3 3
 namespace {{ business_namespace.as_it }};
4 4
 
5
-use Luticate\Utils\LuBusiness;
5
+use Luticate\Utils\Business\LuBusiness;
6 6
 use {{ dataaccess_namespace.as_it }}\{{ data_access_name.as_it }};
7 7
 use {{ dbo_namespace.as_it }}\{{ dbo_name.as_it }};
8 8
 

src/Generator/controller.php.twig → src/Generator/templates/controller.php.twig Ver arquivo

@@ -2,7 +2,7 @@
2 2
 
3 3
 namespace {{ controller_namespace.as_it }};
4 4
 
5
-use Luticate\Utils\LuController;
5
+use Luticate\Utils\Controller\LuController;
6 6
 use {{ business_namespace.as_it }}\{{ business_name.as_it }};
7 7
 use {{ dbo_namespace.as_it }}\{{ dbo_name.as_it }};
8 8
 

+ 15
- 0
src/Generator/templates/dataaccess.php.twig Ver arquivo

@@ -0,0 +1,15 @@
1
+{{ "<?php" }}
2
+
3
+namespace {{ dataaccess_namespace.as_it }};
4
+
5
+use Luticate\Utils\DataAccess\LuDataAccess;
6
+use {{ dbo_namespace.as_it }}\{{ dbo_name.as_it }};
7
+use {{ dbo_namespace.as_it }}\{{ dbo_name.as_it }}Array;
8
+
9
+class {{ data_access_name.as_it }} extends LuDataAccess {
10
+    protected static $_connection = "{{ connection_name.as_it }}";
11
+    protected static $_table = "{{ table_name.as_it }}";
12
+    protected static $_dboClass = {{ dbo_name.as_it }}::class;
13
+    protected static $_dboArrayClass = {{ dbo_name.as_it }}Array::class;
14
+
15
+}

+ 33
- 0
src/Generator/templates/dbo.php.twig Ver arquivo

@@ -0,0 +1,33 @@
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\Dbo\LuDbo;
11
+
12
+class {{ dbo_name.camel_upper }} extends LuDbo {
13
+
14
+{% for column in columns %}
15
+
16
+    /**
17
+     * @var $_{{ column.name.camel_lower }} {{ column.data_type.php.as_it }}
18
+     */
19
+    protected $_{{ column.name.camel_lower }};
20
+{% endfor %}
21
+
22
+{% for column in columns %}
23
+
24
+    public function get{{ column.name.camel_upper }}()
25
+    {
26
+        return $this->_{{ column.name.camel_lower }};
27
+    }
28
+    public function set{{ column.name.camel_upper }}($value)
29
+    {
30
+        $this->_{{ column.name.camel_lower }} = $value;
31
+    }
32
+{% endfor %}
33
+}

src/Generator/dbo_array.php.twig → src/Generator/templates/dbo_array.php.twig Ver arquivo

@@ -7,7 +7,7 @@
7 7
 
8 8
 namespace {{ dbo_namespace.as_it }};
9 9
 
10
-use Luticate\Utils\LuDbo;
10
+use Luticate\Utils\Dbo\LuDbo;
11 11
 
12 12
 class {{ dbo_name.camel_upper }}Array extends LuDbo {
13 13
 
@@ -31,7 +31,7 @@ class {{ dbo_name.camel_upper }}Array extends LuDbo {
31 31
 
32 32
     public static function jsonDeserialize($json)
33 33
     {
34
-        $dbo = new {{ dbo_name.camel_upper }}Array();
34
+        $dbo = new static();
35 35
         $array = [];
36 36
         foreach ($json as $data) {
37 37
             $array[] = {{ dbo_name.camel_upper }}::jsonDeserialize($data);

src/Generator/sp.php.twig → src/Generator/templates/sp.php.twig Ver arquivo


Carregando…
Cancelar
Salvar