Browse Source

added ignore list

tags/0.1.0
Robin Thoni 8 years ago
parent
commit
4437df6315
2 changed files with 41 additions and 8 deletions
  1. 27
    5
      src/Generator/LuGenerator.php
  2. 14
    3
      test/generate.php

+ 27
- 5
src/Generator/LuGenerator.php View File

@@ -35,7 +35,11 @@ class LuGenerator {
35 35
                 "namespace" => 'App\Http\Business',
36 36
                 "folder" => '../app/Http/Business'
37 37
             ),
38
-        "mode" => 0775
38
+        "mode" => 0775,
39
+        "ignore" => array(
40
+            "tables" => array(),
41
+            "sp" => array()
42
+        )
39 43
     );
40 44
     /**
41 45
      * @return array
@@ -52,11 +56,11 @@ class LuGenerator {
52 56
         $this->_config = $config;
53 57
     }
54 58
 
55
-    public function __construct($db_connection, $db_database, $db_host, $db_port, $db_username, $db_password)
59
+    public function __construct()
56 60
     {
57
-        $dsn = $db_connection . ":dbname=" . $db_database . ";host="
58
-            . $db_host . ";port=" . $db_port;
59
-        $this->_pdo = new PDO($dsn, $db_username, $db_password);
61
+        $dsn = getenv("DB_CONNECTION") . ":dbname=" . getenv("DB_DATABASE") . ";host="
62
+            . getenv("DB_HOST") . ";port=" . getenv("DB_PORT");
63
+        $this->_pdo = new PDO($dsn, getenv("DB_USERNAME"), getenv("DB_PASSWORD"));
60 64
     }
61 65
 
62 66
     protected function printError($query, $message)
@@ -269,6 +273,16 @@ ORDER BY parameters.ordinal_position;");
269 273
             mkdir($dir, $dir_mode, true);
270 274
     }
271 275
 
276
+    public function matchIgnore($ignore, $name)
277
+    {
278
+        foreach ($this->_config["ignore"][$ignore] as $reg)
279
+        {
280
+            if (preg_match($reg, $name))
281
+                return true;
282
+        }
283
+        return false;
284
+    }
285
+
272 286
     public function run()
273 287
     {
274 288
         $dbo_dir = $this->_config["dbo"]["folder"] . "/";
@@ -290,6 +304,10 @@ ORDER BY parameters.ordinal_position;");
290 304
         if (!is_null($tables)) {
291 305
             foreach ($tables as $table) {
292 306
                 $table_name = $table["table_name"];
307
+                if ($this->matchIgnore("tables", $table_name)) {
308
+                    echo "Table $table_name ignored\n";
309
+                    continue;
310
+                }
293 311
                 $columns = $this->getColumns($table_name);
294 312
                 if (is_null($columns))
295 313
                     continue;
@@ -315,6 +333,10 @@ ORDER BY parameters.ordinal_position;");
315 333
             foreach ($sps as $sp)
316 334
             {
317 335
                 $sp_name = $sp["sp_name"];
336
+                if ($this->matchIgnore("sp", $sp_name)) {
337
+                    echo "Stored procedure $sp_name ignored\n";
338
+                    continue;
339
+                }
318 340
                 $args = $this->getStoredProceduresArguments($sp);
319 341
                 if (is_null($args))
320 342
                     continue;

+ 14
- 3
test/generate.php View File

@@ -12,8 +12,9 @@ require_once('../vendor/autoload.php');
12 12
 
13 13
 Dotenv::load("..");
14 14
 
15
-$gen = new LuGenerator(getenv("DB_CONNECTION"), getenv("DB_DATABASE"), getenv("DB_HOST"),
16
-    getenv("DB_PORT"), getenv("DB_USERNAME"), getenv("DB_PASSWORD"));
15
+$gen = new LuGenerator();
16
+
17
+echo "\n\nDEFAULT\n\n";
17 18
 
18 19
 $gen->run();
19 20
 
@@ -42,6 +43,16 @@ $gen->setConfig(array("dbo" =>
42 43
             "namespace" => 'Luticate\Package\Business',
43 44
             "folder" => 'generated/Package/Business'
44 45
         ),
45
-    "mode" => 0777
46
+    "mode" => 0777,
47
+    "ignore" => array(
48
+        "tables" => array(
49
+            "/luticate_users_groups/"
50
+        ),
51
+        "sp" => array(
52
+            "/^sp_lu_get/"
53
+        )
54
+    )
46 55
 ));
56
+
57
+echo "\n\nCONFIG\n\n";
47 58
 $gen->run();

Loading…
Cancel
Save