webman icon indicating copy to clipboard operation
webman copied to clipboard

多级控制器方法名支持驼峰命名的处理办法,希望下个版本加入

Open xmier opened this issue 11 months ago • 2 comments

改 app里kebab2camel方法中正则表达式 /-([a-z]+)/ 为 /_-/

public static function kebab2camel($name, bool $big = true) { $name = preg_replace_callback('/-([a-z]+)/', function($m) { return ucfirst($m[1]); }, $name); return $big ? ucfirst($name) : $name; }

xmier avatar Jul 28 '23 02:07 xmier

image 上面正则被改变了看图

xmier avatar Jul 28 '23 02:07 xmier

上述方法没想到action,以下方法解决 public static function kebab2camel($name, bool $big = true) { if ($big) { $name = preg_replace_callback('/_-/', function ($m) { return ucfirst($m[1]); }, $name); } else { $name = strtolower(preg_replace('/(.)(?=[A-Z])/u', '$1' . '_', $name)); } return $big ? ucfirst($name) : $name; } image

xmier avatar Jul 28 '23 03:07 xmier