Browse Source

switched to lustringutils

tags/0.1.3
Robin Thoni 9 years ago
parent
commit
58b5740fef
1 changed files with 5 additions and 14 deletions
  1. 5
    14
      src/Generator/LuGenerator.php

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

6
 use Twig_Autoloader;
6
 use Twig_Autoloader;
7
 use Twig_Environment;
7
 use Twig_Environment;
8
 use Twig_Loader_Filesystem;
8
 use Twig_Loader_Filesystem;
9
+use Luticate\Utils\LuStringUtils;
9
 
10
 
10
 class LuGenerator {
11
 class LuGenerator {
11
     private $_pdo;
12
     private $_pdo;
87
             {
88
             {
88
                 $vars[$key] = array(
89
                 $vars[$key] = array(
89
                     "as_it" => $value,
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
             return $this->printError($columnsQuery, "Failed to get columns from " . $table_name);
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
     public function sqlTypeToPhpType($type)
145
     public function sqlTypeToPhpType($type)
155
     {
146
     {
156
         if ($type == "character" || $type == "character varying" || $type == "char"
147
         if ($type == "character" || $type == "character varying" || $type == "char"
347
                 if (is_null($columns))
338
                 if (is_null($columns))
348
                     continue;
339
                     continue;
349
                 $columns = $this->sqlTypesToPhpTypes($columns);
340
                 $columns = $this->sqlTypesToPhpTypes($columns);
350
-                $baseName = $this->snakeToCamelCase($table_name, true);
341
+                $baseName = LuStringUtils::stringSnakeToCamelCase($table_name, true);
351
                 $modelName = $baseName . "Model";
342
                 $modelName = $baseName . "Model";
352
                 $modelUserName = $baseName;
343
                 $modelUserName = $baseName;
353
                 $dboName = $baseName . "Dbo";
344
                 $dboName = $baseName . "Dbo";
383
                     continue;
374
                     continue;
384
                 $args["in"] = $this->sqlTypesToPhpTypes($args["in"]);
375
                 $args["in"] = $this->sqlTypesToPhpTypes($args["in"]);
385
                 $args["out"] = $this->sqlTypesToPhpTypes($args["out"]);
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
                 $this->generateSp($sp, $args, $sp_dir . $sp_model_name . ".php");
378
                 $this->generateSp($sp, $args, $sp_dir . $sp_model_name . ".php");
388
             }
379
             }
389
         }
380
         }

Loading…
Cancel
Save