Browse Source

changed to luticate2

develop
Robin Thoni 8 years ago
parent
commit
d202798b93

+ 3
- 2
composer.json View File

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

+ 21
- 47
src/Generator/LuGenerator.php View File

6
 use Twig_Autoloader;
6
 use Twig_Autoloader;
7
 use Twig_Environment;
7
 use Twig_Environment;
8
 use Twig_Loader_Filesystem;
8
 use Twig_Loader_Filesystem;
9
-use Luticate\Utils\LuStringUtils;
9
+use Luticate\Utils\Business\LuStringUtils;
10
 
10
 
11
 class LuGenerator {
11
 class LuGenerator {
12
     private $_pdo;
12
     private $_pdo;
13
 
13
 
14
     private $_config = array("dbo" =>
14
     private $_config = array("dbo" =>
15
         array(
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
         "sp" =>
19
         "sp" =>
25
             array(
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
         "dataaccess" =>
24
         "dataaccess" =>
30
             array(
25
             array(
31
-                "namespace" => 'App\Http\DataAccess',
32
-                "folder" => '../app/Http/DataAccess'
26
+                "namespace" => 'App\DataAccess',
27
+                "folder" => '../app/DataAccess'
33
             ),
28
             ),
34
         "business" =>
29
         "business" =>
35
             array(
30
             array(
36
-                "namespace" => 'App\Http\Business',
37
-                "folder" => '../app/Http/Business'
31
+                "namespace" => 'App\Business',
32
+                "folder" => '../app/Business'
38
             ),
33
             ),
39
         "controller" =>
34
         "controller" =>
40
             array(
35
             array(
41
-                "namespace" => 'App\Http\Controller',
42
-                "folder" => '../app/Http/Controller'
36
+                "namespace" => 'App\Controller',
37
+                "folder" => '../app/Controller'
43
             ),
38
             ),
44
         "mode" => 0775,
39
         "mode" => 0775,
45
         "ignore" => array(
40
         "ignore" => array(
88
             {
83
             {
89
                 $vars[$key] = array(
84
                 $vars[$key] = array(
90
                     "as_it" => $value,
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
     protected function buildTwig($templateFile, $destFile, $vars)
94
     protected function buildTwig($templateFile, $destFile, $vars)
100
     {
95
     {
101
         $vars["dbo_namespace"] = $this->_config["dbo"]["namespace"];
96
         $vars["dbo_namespace"] = $this->_config["dbo"]["namespace"];
102
-        $vars["models_namespace"] = $this->_config["models"]["namespace"];
103
         $vars["sp_namespace"] = $this->_config["sp"]["namespace"];
97
         $vars["sp_namespace"] = $this->_config["sp"]["namespace"];
104
         $vars["dataaccess_namespace"] = $this->_config["dataaccess"]["namespace"];
98
         $vars["dataaccess_namespace"] = $this->_config["dataaccess"]["namespace"];
105
         $vars["business_namespace"] = $this->_config["business"]["namespace"];
99
         $vars["business_namespace"] = $this->_config["business"]["namespace"];
110
         Twig_Autoloader::register();
104
         Twig_Autoloader::register();
111
         $loader = new Twig_Loader_Filesystem(__DIR__ );
105
         $loader = new Twig_Loader_Filesystem(__DIR__ );
112
         $twig = new Twig_Environment($loader, array());
106
         $twig = new Twig_Environment($loader, array());
113
-        $template = $twig->loadTemplate($templateFile . '.twig');
107
+        $template = $twig->loadTemplate('templates/' . $templateFile . '.twig');
114
         $content = $template->render($twig_vars);
108
         $content = $template->render($twig_vars);
115
         file_put_contents($destFile, $content);
109
         file_put_contents($destFile, $content);
116
     }
110
     }
183
         $this->buildTwig('dbo_array.php', $fileArray, $vars);
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
     public function getStoredProcedures()
180
     public function getStoredProcedures()
202
     {
181
     {
203
         $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
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
         $this->buildTwig('sp.php', $file, $vars);
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
         if (file_exists($file))
240
         if (file_exists($file))
262
             return;
241
             return;
263
         $vars = array(
242
         $vars = array(
264
             "data_access_name" => $dataAccessName,
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
             "dbo_name" => $dboName
246
             "dbo_name" => $dboName
268
         );
247
         );
269
         $this->buildTwig('dataaccess.php', $file, $vars);
248
         $this->buildTwig('dataaccess.php', $file, $vars);
312
     public function run()
291
     public function run()
313
     {
292
     {
314
         $dbo_dir = $this->_config["dbo"]["folder"] . "/";
293
         $dbo_dir = $this->_config["dbo"]["folder"] . "/";
315
-        $model_dir = $this->_config["models"]["folder"] . "/";
316
         $sp_dir = $this->_config["sp"]["folder"] . "/";
294
         $sp_dir = $this->_config["sp"]["folder"] . "/";
317
         $sp_src_dir = $this->_config["sp"]["folder"] . "/src/";
295
         $sp_src_dir = $this->_config["sp"]["folder"] . "/src/";
318
         $manager_dir = $this->_config["dataaccess"]["folder"] . "/";
296
         $manager_dir = $this->_config["dataaccess"]["folder"] . "/";
319
         $business_dir = $this->_config["business"]["folder"] . "/";
297
         $business_dir = $this->_config["business"]["folder"] . "/";
320
         $controller_dir = $this->_config["controller"]["folder"] . "/";
298
         $controller_dir = $this->_config["controller"]["folder"] . "/";
299
+        $connection_name = getenv("DB_CONNECTION_NAME");
321
 
300
 
322
         $mode = $this->_config["mode"];
301
         $mode = $this->_config["mode"];
323
 
302
 
324
         umask(0000);
303
         umask(0000);
325
         $this->mkdir($dbo_dir, $mode);
304
         $this->mkdir($dbo_dir, $mode);
326
-        $this->mkdir($model_dir, $mode);
327
         $this->mkdir($sp_dir, $mode);
305
         $this->mkdir($sp_dir, $mode);
328
         $this->mkdir($sp_src_dir, $mode);
306
         $this->mkdir($sp_src_dir, $mode);
329
         $this->mkdir($manager_dir, $mode);
307
         $this->mkdir($manager_dir, $mode);
342
                 if (is_null($columns))
320
                 if (is_null($columns))
343
                     continue;
321
                     continue;
344
                 $columns = $this->sqlTypesToPhpTypes($columns);
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
                 $dboName = $baseName . "Dbo";
324
                 $dboName = $baseName . "Dbo";
349
                 $dataAccessName = $baseName . "DataAccess";
325
                 $dataAccessName = $baseName . "DataAccess";
350
                 $businessName = $baseName . "Business";
326
                 $businessName = $baseName . "Business";
351
                 $controllerName = $baseName . "Controller";
327
                 $controllerName = $baseName . "Controller";
352
                 $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php", $dbo_dir . $dboName . "Array.php");
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
                     $manager_dir . $dataAccessName . ".php");
330
                     $manager_dir . $dataAccessName . ".php");
357
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,
331
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,
358
                     $business_dir . $businessName . ".php");
332
                     $business_dir . $businessName . ".php");
378
                     continue;
352
                     continue;
379
                 $args["in"] = $this->sqlTypesToPhpTypes($args["in"]);
353
                 $args["in"] = $this->sqlTypesToPhpTypes($args["in"]);
380
                 $args["out"] = $this->sqlTypesToPhpTypes($args["out"]);
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
                 $this->generateSp($sp, $args, $sp_dir . $sp_model_name . ".php", $sp_src_dir . $sp_name . ".sql");
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 View File

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 View File

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 View File

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 View File

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 View File

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

src/Generator/controller.php.twig → src/Generator/templates/controller.php.twig View File

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

+ 15
- 0
src/Generator/templates/dataaccess.php.twig View File

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 View File

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 View File

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

src/Generator/sp.php.twig → src/Generator/templates/sp.php.twig View File


Loading…
Cancel
Save