Quellcode durchsuchen

switched to lustringutils

tags/0.1.3
Robin Thoni vor 9 Jahren
Ursprung
Commit
58b5740fef
1 geänderte Dateien mit 5 neuen und 14 gelöschten Zeilen
  1. 5
    14
      src/Generator/LuGenerator.php

+ 5
- 14
src/Generator/LuGenerator.php Datei anzeigen

@@ -6,6 +6,7 @@ use PDO;
6 6
 use Twig_Autoloader;
7 7
 use Twig_Environment;
8 8
 use Twig_Loader_Filesystem;
9
+use Luticate\Utils\LuStringUtils;
9 10
 
10 11
 class LuGenerator {
11 12
     private $_pdo;
@@ -87,8 +88,8 @@ class LuGenerator {
87 88
             {
88 89
                 $vars[$key] = array(
89 90
                     "as_it" => $value,
90
-                    "camel_upper" => $this->snakeToCamelCase($value, true),
91
-                    "camel_lower" => $this->snakeToCamelCase($value, false)
91
+                    "camel_upper" => LuStringUtils::stringSnakeToCamelCase($value, true),
92
+                    "camel_lower" => LuStringUtils::stringSnakeToCamelCase($value, false)
92 93
                 );
93 94
             }
94 95
         }
@@ -141,16 +142,6 @@ WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'informat
141 142
             return $this->printError($columnsQuery, "Failed to get columns from " . $table_name);
142 143
     }
143 144
 
144
-    function snakeToCamelCase($string, $capitalizeFirstCharacter) {
145
-        $str = preg_replace_callback("/_[a-zA-Z]/", function($matches)
146
-        {
147
-            return strtoupper($matches[0][1]);
148
-        }, $string);
149
-        if ($capitalizeFirstCharacter)
150
-            $str[0] = strtoupper($str[0]);
151
-        return $str;
152
-    }
153
-
154 145
     public function sqlTypeToPhpType($type)
155 146
     {
156 147
         if ($type == "character" || $type == "character varying" || $type == "char"
@@ -347,7 +338,7 @@ ORDER BY parameters.ordinal_position;");
347 338
                 if (is_null($columns))
348 339
                     continue;
349 340
                 $columns = $this->sqlTypesToPhpTypes($columns);
350
-                $baseName = $this->snakeToCamelCase($table_name, true);
341
+                $baseName = LuStringUtils::stringSnakeToCamelCase($table_name, true);
351 342
                 $modelName = $baseName . "Model";
352 343
                 $modelUserName = $baseName;
353 344
                 $dboName = $baseName . "Dbo";
@@ -383,7 +374,7 @@ ORDER BY parameters.ordinal_position;");
383 374
                     continue;
384 375
                 $args["in"] = $this->sqlTypesToPhpTypes($args["in"]);
385 376
                 $args["out"] = $this->sqlTypesToPhpTypes($args["out"]);
386
-                $sp_model_name = $this->snakeToCamelCase($sp_name, true);
377
+                $sp_model_name = LuStringUtils::stringSnakeToCamelCase($sp_name, true);
387 378
                 $this->generateSp($sp, $args, $sp_dir . $sp_model_name . ".php");
388 379
             }
389 380
         }

Laden…
Abbrechen
Speichern