add create:seed command

This commit is contained in:
uctoo 2021-06-06 17:09:31 +08:00
parent 22ad849900
commit d757f3130e
2 changed files with 3 additions and 30 deletions

View File

@ -293,32 +293,4 @@ class Utils
}
}
}
/**
* 下划线转驼峰
* 思路:
* step1.原字符串转小写,原字符串中的分隔符用空格替换,在字符串开头加上分隔符
* step2.将字符串中每个单词的首字母转换为大写,再去空格,去字符串首部附加的分隔符.
* @param $uncamelized_words
* @param string $separator
* @return string
*/
public static function camelize($uncamelized_words,$separator='_')
{
$uncamelized_words = $separator. str_replace($separator, " ", strtolower($uncamelized_words));
return ltrim(str_replace(" ", "", ucwords($uncamelized_words)), $separator );
}
/**
* 驼峰命名转下划线命名
* 思路:
* @param $camelCaps
* @param string $separator
* @return string
*/
public static function uncamelize($camelCaps,$separator='_')
{
return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps));
}
}

View File

@ -13,6 +13,7 @@ use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
use think\helper\Str;
class CreateSeedCommand extends Command
{
@ -58,8 +59,8 @@ class CreateSeedCommand extends Command
{
$stub = file_get_contents(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'seed.stub');
$model = ucfirst(Utils::camelize($table));
$class = ucfirst(Utils::camelize($table)) . 'Seed';
$model = Str::studly($table);
$class = Str::studly($table) . 'Seed';
$stub = str_replace('{CLASS}', $class, $stub);
$stub = str_replace('{MODULE}', $module, $stub);