Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xmier opened this issue Jul 28, 2023 · 2 comments

Comments

@xmier
Copy link

xmier commented Jul 28, 2023

改 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
Copy link
Author

xmier commented Jul 28, 2023

image
上面正则被改变了看图

@xmier
Copy link
Author

xmier commented Jul 28, 2023

上述方法没想到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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant