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

Allow guessing of property names #1

Open
mark-gerarts opened this issue Oct 17, 2017 · 2 comments
Open

Allow guessing of property names #1

mark-gerarts opened this issue Oct 17, 2017 · 2 comments

Comments

@mark-gerarts
Copy link
Owner

As it is now, the classes need to follow strict naming conventions in order to be mapped. A nice feature would be to be able to change this behaviour via the Options, making the mapper instead guess the source property name.

For example, when looking for the property firstName, the mapper would match the first occurrence of either [firstName, first_name, FirstName, ...].

Credit

@samrap
Copy link
Contributor

samrap commented Oct 23, 2017

I am currently reading through the source to wrap my head around the architecture of this package. I'd really like to be a major contributor to this down the line.

There are clearly some arguments for and against this feature so I definitely think it should be something that must be explicitly set in the Options. Maybe something like:

$config
    ->registerMapping(CrazySource::class, SomeOtherCrazyDestination::class)
    ->withoutNamingConventions();

The method withoutNamingConventions() could simply set the naming conventions to a NoNamingConventions implementation. The NoNamingConventions would then be responsible for converting the property name, perhaps stripping it of underscores and converting it to lowercase?

@mark-gerarts
Copy link
Owner Author

That's definitely a step in the right direction. Using a NoNamingConventions is an option, although it might be more fitting to put this logic in a NameResolver, either adding logic to the default one or creating a completely new one. The advantage here being that the NameResolver can already be overwritten in the Options.

That being said, I'm open for other ideas. I think the hardest part will be the actual guessing of source properties. If you wanna take a shot at this, then go ahead. I'll be more than happy to merge a good solution for this.

Thanks for your interest!

mark-gerarts pushed a commit that referenced this issue Jun 3, 2018
update local fork with latest changes from master
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

2 participants