Browse Source

added controller generator

tags/0.1.0
Robin Thoni 8 years ago
parent
commit
6cfafde061
3 changed files with 52 additions and 2 deletions
  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 View File

35
                 "namespace" => 'App\Http\Business',
35
                 "namespace" => 'App\Http\Business',
36
                 "folder" => '../app/Http/Business'
36
                 "folder" => '../app/Http/Business'
37
             ),
37
             ),
38
+        "controller" =>
39
+            array(
40
+                "namespace" => 'App\Http\Controller',
41
+                "folder" => '../app/Http/Controller'
42
+            ),
38
         "mode" => 0775,
43
         "mode" => 0775,
39
         "ignore" => array(
44
         "ignore" => array(
40
             "tables" => array(),
45
             "tables" => array(),
41
-            "sp" => array()
46
+            "sp" => array(),
47
+            "controllers" => array()
42
         )
48
         )
43
     );
49
     );
44
     /**
50
     /**
96
         $vars["sp_namespace"] = $this->_config["sp"]["namespace"];
102
         $vars["sp_namespace"] = $this->_config["sp"]["namespace"];
97
         $vars["dataaccess_namespace"] = $this->_config["dataaccess"]["namespace"];
103
         $vars["dataaccess_namespace"] = $this->_config["dataaccess"]["namespace"];
98
         $vars["business_namespace"] = $this->_config["business"]["namespace"];
104
         $vars["business_namespace"] = $this->_config["business"]["namespace"];
105
+        $vars["controller_namespace"] = $this->_config["controller"]["namespace"];
99
 
106
 
100
         $twig_vars = $this->buildTwigVars($vars);
107
         $twig_vars = $this->buildTwigVars($vars);
101
 
108
 
269
         $this->buildTwig('business.php', $file, $vars);
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
     public function mkdir($dir, $dir_mode)
291
     public function mkdir($dir, $dir_mode)
273
     {
292
     {
274
         if (!file_exists($dir))
293
         if (!file_exists($dir))
292
         $sp_dir = $this->_config["sp"]["folder"] . "/";
311
         $sp_dir = $this->_config["sp"]["folder"] . "/";
293
         $manager_dir = $this->_config["dataaccess"]["folder"] . "/";
312
         $manager_dir = $this->_config["dataaccess"]["folder"] . "/";
294
         $business_dir = $this->_config["business"]["folder"] . "/";
313
         $business_dir = $this->_config["business"]["folder"] . "/";
314
+        $controller_dir = $this->_config["controller"]["folder"] . "/";
295
 
315
 
296
         $mode = $this->_config["mode"];
316
         $mode = $this->_config["mode"];
297
 
317
 
301
         $this->mkdir($sp_dir, $mode);
321
         $this->mkdir($sp_dir, $mode);
302
         $this->mkdir($manager_dir, $mode);
322
         $this->mkdir($manager_dir, $mode);
303
         $this->mkdir($business_dir, $mode);
323
         $this->mkdir($business_dir, $mode);
324
+        $this->mkdir($controller_dir, $mode);
304
 
325
 
305
         $tables = $this->getTables();
326
         $tables = $this->getTables();
306
         if (!is_null($tables)) {
327
         if (!is_null($tables)) {
320
                 $dboName = $baseName . "Dbo";
341
                 $dboName = $baseName . "Dbo";
321
                 $dataAccessName = $baseName . "DataAccess";
342
                 $dataAccessName = $baseName . "DataAccess";
322
                 $businessName = $baseName . "Business";
343
                 $businessName = $baseName . "Business";
344
+                $controllerName = $baseName . "Controller";
323
                 $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php");
345
                 $this->generateDbo($dboName, $columns, $dbo_dir . $dboName . ".php");
324
                 $this->generateModel($modelName, $modelUserName, $dboName, $columns, $model_dir . $modelName . ".php",
346
                 $this->generateModel($modelName, $modelUserName, $dboName, $columns, $model_dir . $modelName . ".php",
325
                     $model_dir . $modelUserName . ".php");
347
                     $model_dir . $modelUserName . ".php");
327
                     $manager_dir . $dataAccessName . ".php");
349
                     $manager_dir . $dataAccessName . ".php");
328
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,
350
                 $this->generateBusiness($businessName, $dataAccessName, $dboName,
329
                     $business_dir . $businessName . ".php");
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
         $sps = $this->getStoredProcedures();
360
         $sps = $this->getStoredProcedures();

+ 14
- 0
src/Generator/controller.php.twig View File

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

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

Loading…
Cancel
Save