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

#[prop] attribute should rename fields to camelCase by default #189

Open
ju1ius opened this issue Nov 23, 2022 · 2 comments
Open

#[prop] attribute should rename fields to camelCase by default #189

ju1ius opened this issue Nov 23, 2022 · 2 comments

Comments

@ju1ius
Copy link
Contributor

ju1ius commented Nov 23, 2022

Currently, the #[prop] attribute does not handle case conversion, so we must resort to:

#[php_class]
struct Foo {
  #[prop(rename = "isBar")]
  pub is_bar: bool,
}

which can quickly become tedious.

The #[php_class] attribute should accept a rename_fields argument similiar to rename_methods for #[php_impl], and default to camelCase.

The #[prop(rename)] argument should be kept around for corner-cases like:

#[php_class]
struct Request {
  #[prop(rename = "isXMLHttpRequest")]
  pub is_xml_http_request: bool,
}

Although on might argue that it should be #[prop(name = ..)] and not #[prop(rename = ..)]...

For ergonomics, it could even be made into a global, project-wide, configuration option?

@ju1ius
Copy link
Contributor Author

ju1ius commented Nov 23, 2022

Thinking about it, it should look more like :

#[php_class(field_case = "snake", method_case = "camel", constant_case = "upper")]
struct Foo;

This would ease the burden of verbose repeated configuration.

@Dennis-Zhang-SH
Copy link

Well I think you could simply rename your function and use #[allow(non_snake_case)]
:)

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

2 participants