Przeglądaj źródła

added dynamic namespace

tags/0.1.0
Robin Thoni 9 lat temu
rodzic
commit
14feb663ca

+ 34
- 28
src/Generator/LuGenerator.php Wyświetl plik

@@ -13,33 +13,29 @@ class LuGenerator {
13 13
     private $_config = array("dbo" =>
14 14
         array(
15 15
             "namespace" => 'App\Http\DBO',
16
-            "folder" => '../app/Http/DBO',
17
-            "mode" => 0775
16
+            "folder" => '../app/Http/DBO'
18 17
         ),
19 18
         "models" =>
20 19
             array(
21 20
                 "namespace" => 'App\Http\DataAccess\Models',
22
-                "folder" => '../app/Http/DataAccess/Models',
23
-                "mode" => 0775
21
+                "folder" => '../app/Http/DataAccess/Models'
24 22
             ),
25 23
         "sp" =>
26 24
             array(
27 25
                 "namespace" => 'App\Http\DataAccess\SP',
28
-                "folder" => '../app/Http/DataAccess/SP',
29
-                "mode" => 0775
26
+                "folder" => '../app/Http/DataAccess/SP'
30 27
             ),
31 28
         "dataaccess" =>
32 29
             array(
33 30
                 "namespace" => 'App\Http\DataAccess',
34
-                "folder" => '../app/Http/DataAccess',
35
-                "mode" => 0775
31
+                "folder" => '../app/Http/DataAccess'
36 32
             ),
37 33
         "business" =>
38 34
             array(
39 35
                 "namespace" => 'App\Http\Business',
40
-                "folder" => '../app/Http/Business',
41
-                "mode" => 0775
42
-            )
36
+                "folder" => '../app/Http/Business'
37
+            ),
38
+        "mode" => 0755
43 39
     );
44 40
     /**
45 41
      * @return array
@@ -157,21 +153,23 @@ WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'informat
157 153
         return $array;
158 154
     }
159 155
 
160
-    public function generateDbo($name, $columns, $file)
156
+    public function generateDbo($name, $columns, $file, $namespace)
161 157
     {
162 158
         $vars = array(
163 159
             "dbo_name" => $name,
164
-            "columns" => $columns
160
+            "columns" => $columns,
161
+            "namespace" => $namespace
165 162
         );
166 163
         $this->buildTwig('dbo.php', $file, $vars);
167 164
     }
168 165
 
169
-    public function generateModel($modelName, $dboName, $columns, $file)
166
+    public function generateModel($modelName, $dboName, $columns, $file, $namespace)
170 167
     {
171 168
         $vars = array(
172 169
             "model_name" => $modelName,
173 170
             "dbo_name" => $dboName,
174
-            "columns" => $columns
171
+            "columns" => $columns,
172
+            "namespace" => $namespace
175 173
         );
176 174
         $this->buildTwig('model.php', $file, $vars);
177 175
     }
@@ -233,26 +231,28 @@ ORDER BY parameters.ordinal_position;");
233 231
         $this->buildTwig('sp.php', $file, $vars);
234 232
     }
235 233
 
236
-    public function generateDataAccess($dataAccessName, $modelName, $dboName, $file)
234
+    public function generateDataAccess($dataAccessName, $modelName, $dboName, $file, $namespace)
237 235
     {
238 236
         if (file_exists($file))
239 237
             return;
240 238
         $vars = array(
241 239
             "data_access_name" => $dataAccessName,
242 240
             "model_name" => $modelName,
243
-            "dbo_name" => $dboName
241
+            "dbo_name" => $dboName,
242
+            "namespace" => $namespace
244 243
         );
245 244
         $this->buildTwig('dataaccess.php', $file, $vars);
246 245
     }
247 246
 
248
-    public function generateBusiness($businessName, $dataAccessName, $dboName, $file)
247
+    public function generateBusiness($businessName, $dataAccessName, $dboName, $file, $namespace)
249 248
     {
250 249
         if (file_exists($file))
251 250
             return;
252 251
         $vars = array(
253 252
             "business_name" => $businessName,
254 253
             "data_access_name" => $dataAccessName,
255
-            "dbo_name" => $dboName
254
+            "dbo_name" => $dboName,
255
+            "namespace" => $namespace
256 256
         );
257 257
         $this->buildTwig('business.php', $file, $vars);
258 258
     }
@@ -271,11 +271,13 @@ ORDER BY parameters.ordinal_position;");
271 271
         $manager_dir = $this->_config["dataaccess"]["folder"] . "/";
272 272
         $business_dir = $this->_config["business"]["folder"] . "/";
273 273
 
274
-        $this->mkdir($dbo_dir, $this->_config["dbo"]["mode"]);
275
-        $this->mkdir($model_dir, $this->_config["models"]["mode"]);
276
-        $this->mkdir($sp_dir, $this->_config["sp"]["mode"]);
277
-        $this->mkdir($manager_dir, $this->_config["dataaccess"]["mode"]);
278
-        $this->mkdir($business_dir, $this->_config["business"]["mode"]);
274
+        $mode = $this->_config["mode"];
275
+
276
+        $this->mkdir($dbo_dir, $mode);
277
+        $this->mkdir($model_dir, $mode);
278
+        $this->mkdir($sp_dir, $mode);
279
+        $this->mkdir($manager_dir, $mode);
280
+        $this->mkdir($business_dir, $mode);
279 281
 
280 282
         $tables = $this->getTables();
281 283
         if (!is_null($tables)) {
@@ -290,10 +292,14 @@ ORDER BY parameters.ordinal_position;");
290 292
                 $dboName = $baseName . "Dbo";
291 293
                 $dataAccessName = $baseName . "DataAccess";
292 294
                 $businessName = $baseName . "Business";
293
-                $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php");
294
-                $this->generateModel($modelName, $dboName, $columns, $model_dir . $modelName . ".php");
295
-                $this->generateDataAccess($dataAccessName, $modelName, $dboName, $manager_dir . $dataAccessName . ".php");
296
-                $this->generateBusiness($businessName, $dataAccessName, $dboName, $business_dir . $businessName . ".php");
295
+                $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php",
296
+                    $this->_config["dbo"]["namespace"]);
297
+                $this->generateModel($modelName, $dboName, $columns, $model_dir . $modelName . ".php",
298
+                    $this->_config["models"]["namespace"]);
299
+                $this->generateDataAccess($dataAccessName, $modelName, $dboName,
300
+                    $manager_dir . $dataAccessName . ".php", $this->_config["dataaccess"]["namespace"]);
301
+                $this->generateBusiness($businessName, $dataAccessName, $dboName,
302
+                    $business_dir . $businessName . ".php", $this->_config["business"]["namespace"]);
297 303
             }
298 304
         }
299 305
         $sps = $this->getStoredProcedures();

+ 1
- 1
src/Generator/business.php.twig Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 {{ "<?php" }}
2 2
 
3
-namespace App\Http\Business;
3
+namespace {{ namespace.as_it }};
4 4
 
5 5
 use Luticate\Utils\LuBusiness;
6 6
 use App\Http\DataAccess\{{ data_access_name.as_it }};

+ 1
- 1
src/Generator/dataaccess.php.twig Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 {{ "<?php" }}
2 2
 
3
-namespace App\Http\DataAccess;
3
+namespace {{ namespace.as_it }};
4 4
 
5 5
 use Luticate\Utils\LuDataAccess;
6 6
 use App\Http\DataAccess\Models\{{ model_name.as_it }};

+ 1
- 1
src/Generator/dbo.php.twig Wyświetl plik

@@ -5,7 +5,7 @@
5 5
  * ANY CHANGES WILL BE OVERWRITTEN
6 6
  */
7 7
 
8
-namespace App\Http\DBO;
8
+namespace {{ namespace.as_it }};
9 9
 
10 10
 use Luticate\Utils\LuDbo;
11 11
 

+ 1
- 1
src/Generator/model.php.twig Wyświetl plik

@@ -5,7 +5,7 @@
5 5
 * ANY CHANGES WILL BE OVERWRITTEN
6 6
 */
7 7
 
8
-namespace App\Http\DataAccess\Models;
8
+namespace {{ namespace.as_it }};
9 9
 
10 10
 use Luticate\Utils\LuModel;
11 11
 use App\Http\DBO\{{ dbo_name.camel_upper }};

+ 1
- 1
src/Generator/sp.php.twig Wyświetl plik

@@ -1,6 +1,6 @@
1 1
 {{ "<?php" }}
2 2
 
3
-namespace App\Http\DataAccess\SP;
3
+namespace {{ namespace.as_it }};
4 4
 
5 5
 use Luticate\Utils\LuSpModel;
6 6
 use Illuminate\Support\Facades\DB;

Ładowanie…
Anuluj
Zapisz