Skip to content

Support toggling underscore detection on all attributes in normalizer #12212

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

Closed
atrauzzi opened this issue Oct 11, 2014 · 0 comments
Closed

Support toggling underscore detection on all attributes in normalizer #12212

atrauzzi opened this issue Oct 11, 2014 · 0 comments

Comments

@atrauzzi
Copy link

I noticed that the GetSetMethodNormalizer that comes with Serializer doesn't support toggling the detection and conversion of underscores from all fields provided.

I've mitigated this by creating my own subclass as follows:

class GetSetMethodNormalizer extends Base {

    protected function formatAttribute($attributeName) {
        return preg_replace_callback(
            '/(^|_|\.)+(.)/',
            function ($match) {
                return ('.' === $match[1] ? '_' : '') . strtoupper($match[2]);
            },
            $attributeName
        );
    }

}

This appears to have handled things so far, but I'm wondering if it might be nice to formalize this as a setting in GetSetMethodNormalizer?

fabpot added a commit that referenced this issue Feb 3, 2015
This PR was merged into the 2.7 branch.

Discussion
----------

[Serializer] Name converter support

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #12212
| License       | MIT
| Doc PR        | symfony/symfony-docs#4692

This PR adds support for custom property naming strategies to the serializer and provides a built-in NameConverter using this new system: (CamelCase to underscore).
It handles normalization and denormalization (convert `fooBar` to `foo_bar` when serializing, then from `foo_bar` to `fooBar` when deserializing). It also has a flag to convert only some attributes.

The `setCamelizedAttributes()` is deprecated in favor of this new method (more flexible, allows to rename all attributes of a class and support deserialization) and now uses it internally.

Commits
-------

86b84a5 [Serializer] Update changelog
e14854f [Serializer] Name converter support
@fabpot fabpot closed this as completed Feb 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants