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

Support for default values #54

Merged

Conversation

jan888adams
Copy link
Contributor

@jan888adams jan888adams commented Sep 28, 2023

This merge request introduces the option to specify a default value for a property in case the source value is null. The key changes include:

Configuration.php:

Users can now use the keyword 'source' to define the source property and 'default' to specify a default value. If no default value is needed, the old syntax can still be used.

NeustaConverterExtension.php:

Modified NeustaConverterExtension.php to pass the default value property to the DefaultMappingPopulator by reading the default property.

PropertyMappingPopulator.php:

In PropertyMappingPopulator.php, a new constructor parameter of type 'mixed' has been added, allowing any type (string, bool, int, null, etc.) to be passed as the default value. When the source property returns null, it will be replaced with the provided default value.

Example Configuration:

neusta_converter:
  converter:
    person.converter:
      target_factory: AppBundle\Factory\PersonFactory
      properties:
        firstname:
          default: John
        lastname: 
          source: name
          default: Doe
        email: ~
        phone: phoneNumber

Resolves Default value (PropertyMappingPopulator) #49 issue.

@jan888adams jan888adams changed the title Add default value for PropertyMappingPopulator Default value for PropertyMappingPopulator Sep 28, 2023
src/Resolver/DefaultValueResolver.php Outdated Show resolved Hide resolved
src/DependencyInjection/Configuration.php Outdated Show resolved Hide resolved
@jan888adams jan888adams force-pushed the default-value-property-mapping-populator branch from 0a7ec21 to e238339 Compare October 9, 2023 05:12
@jan888adams jan888adams force-pushed the default-value-property-mapping-populator branch from e238339 to 01d1660 Compare October 9, 2023 05:26
@jan888adams jan888adams changed the title Default value for PropertyMappingPopulator Support for default values when the source property returns null Oct 9, 2023
@jan888adams jan888adams changed the title Support for default values when the source property returns null Support for default values Oct 9, 2023
docs/usage.md Outdated Show resolved Hide resolved
src/DependencyInjection/Configuration.php Show resolved Hide resolved
@jan888adams jan888adams marked this pull request as ready for review October 10, 2023 07:05
@jan888adams jan888adams marked this pull request as draft October 10, 2023 07:40
@jan888adams jan888adams marked this pull request as ready for review October 10, 2023 08:05
jan888adams and others added 6 commits October 10, 2023 10:09
@jan888adams jan888adams force-pushed the default-value-property-mapping-populator branch from c66c745 to 9e42a6c Compare October 10, 2023 08:09
Copy link
Collaborator

@mike4git mike4git left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with - especially the new syntax

@mike4git mike4git merged commit b4e2755 into teamneusta:main Oct 16, 2023
5 checks passed
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

Successfully merging this pull request may close these issues.

None yet

4 participants