|
@@ -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
|
}
|