Explorar el Código

added controller generator

tags/0.1.0
Robin Thoni hace 9 años
padre
commit
6cfafde061
Se han modificado 3 ficheros con 52 adiciones y 2 borrados
  1. 29
    1
      src/Generator/LuGenerator.php
  2. 14
    0
      src/Generator/controller.php.twig
  3. 9
    1
      test/generate.php

+ 29
- 1
src/Generator/LuGenerator.php Ver fichero

@@ -35,10 +35,16 @@ class LuGenerator {
35 35
                 "namespace" => 'App\Http\Business',
36 36
                 "folder" => '../app/Http/Business'
37 37
             ),
38
+        "controller" =>
39
+            array(
40
+                "namespace" => 'App\Http\Controller',
41
+                "folder" => '../app/Http/Controller'
42
+            ),
38 43
         "mode" => 0775,
39 44
         "ignore" => array(
40 45
             "tables" => array(),
41
-            "sp" => array()
46
+            "sp" => array(),
47
+            "controllers" => array()
42 48
         )
43 49
     );
44 50
     /**
@@ -96,6 +102,7 @@ class LuGenerator {
96 102
         $vars["sp_namespace"] = $this->_config["sp"]["namespace"];
97 103
         $vars["dataaccess_namespace"] = $this->_config["dataaccess"]["namespace"];
98 104
         $vars["business_namespace"] = $this->_config["business"]["namespace"];
105
+        $vars["controller_namespace"] = $this->_config["controller"]["namespace"];
99 106
 
100 107
         $twig_vars = $this->buildTwigVars($vars);
101 108
 
@@ -269,6 +276,18 @@ ORDER BY parameters.ordinal_position;");
269 276
         $this->buildTwig('business.php', $file, $vars);
270 277
     }
271 278
 
279
+    public function generateController($controllerName, $businessName, $dboName, $file)
280
+    {
281
+        if (file_exists($file))
282
+            return;
283
+        $vars = array(
284
+            "controller_name" => $controllerName,
285
+            "business_name" => $businessName,
286
+            "dbo_name" => $dboName
287
+        );
288
+        $this->buildTwig('controller.php', $file, $vars);
289
+    }
290
+
272 291
     public function mkdir($dir, $dir_mode)
273 292
     {
274 293
         if (!file_exists($dir))
@@ -292,6 +311,7 @@ ORDER BY parameters.ordinal_position;");
292 311
         $sp_dir = $this->_config["sp"]["folder"] . "/";
293 312
         $manager_dir = $this->_config["dataaccess"]["folder"] . "/";
294 313
         $business_dir = $this->_config["business"]["folder"] . "/";
314
+        $controller_dir = $this->_config["controller"]["folder"] . "/";
295 315
 
296 316
         $mode = $this->_config["mode"];
297 317
 
@@ -301,6 +321,7 @@ ORDER BY parameters.ordinal_position;");
301 321
         $this->mkdir($sp_dir, $mode);
302 322
         $this->mkdir($manager_dir, $mode);
303 323
         $this->mkdir($business_dir, $mode);
324
+        $this->mkdir($controller_dir, $mode);
304 325
 
305 326
         $tables = $this->getTables();
306 327
         if (!is_null($tables)) {
@@ -320,6 +341,7 @@ ORDER BY parameters.ordinal_position;");
320 341
                 $dboName = $baseName . "Dbo";
321 342
                 $dataAccessName = $baseName . "DataAccess";
322 343
                 $businessName = $baseName . "Business";
344
+                $controllerName = $baseName . "Controller";
323 345
                 $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php");
324 346
                 $this->generateModel($modelName, $modelUserName, $dboName, $columns, $model_dir . $modelName . ".php",
325 347
                     $model_dir . $modelUserName . ".php");
@@ -327,6 +349,12 @@ ORDER BY parameters.ordinal_position;");
327 349
                     $manager_dir . $dataAccessName . ".php");
328 350
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,
329 351
                     $business_dir . $businessName . ".php");
352
+                if ($this->matchIgnore("controllers", $controllerName)) {
353
+                    echo "Controller $controllerName ignored\n";
354
+                    continue;
355
+                }
356
+                $this->generateController($controllerName, $businessName, $dboName,
357
+                    $controller_dir . $controllerName . ".php");
330 358
             }
331 359
         }
332 360
         $sps = $this->getStoredProcedures();

+ 14
- 0
src/Generator/controller.php.twig Ver fichero

@@ -0,0 +1,14 @@
1
+{{ "<?php" }}
2
+
3
+namespace {{ controller_namespace.as_it }};
4
+
5
+use Luticate\Utils\LuController;
6
+use {{ business_namespace.as_it }}\{{ business_name.as_it }};
7
+use {{ dbo_namespace.as_it }}\{{ dbo_name.as_it }};
8
+
9
+class {{ controller_name.as_it }} extends LuController {
10
+    protected static function getBusiness()
11
+    {
12
+        return new {{ business_name.as_it }}();
13
+    }
14
+}

+ 9
- 1
test/generate.php Ver fichero

@@ -43,13 +43,21 @@ $gen->setConfig(array("dbo" =>
43 43
             "namespace" => 'Luticate\Package\Business',
44 44
             "folder" => 'generated/Package/Business'
45 45
         ),
46
+    "controller" =>
47
+        array(
48
+            "namespace" => 'Luticate\Package\Controller',
49
+            "folder" => 'generated/Package/Controller'
50
+        ),
46 51
     "mode" => 0777,
47 52
     "ignore" => array(
48 53
         "tables" => array(
49
-            "/luticate_users_groups/"
54
+            "/^luticate_users_groups$/"
50 55
         ),
51 56
         "sp" => array(
52 57
             "/^sp_lu_get/"
58
+        ),
59
+        "controllers" => array(
60
+            "/^LuticatePermissions(Groups|Users)Controller$/"
53 61
         )
54 62
     )
55 63
 ));

Loading…
Cancelar
Guardar