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

Add property defaults assembler #564

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Jan 10, 2025

This PR introduces a new PropertyDefaultsAssembler:

The encoding library is less forgiving about missing information in requests than PHP's soap encoder.
This assembler allows you to e.g. set default property values for request objects, so that you only have to fill in the data you care about.

Example configuration:

$config
    ->addRule(
        new Rules\IsRequestRule(
            $meta,
            new Rules\MultiRule([
                new Rules\AssembleRule(new Assembler\ImmutableSetterAssembler()),
                new Rules\AssembleRule(new Assembler\RequestAssembler()),
                new Rules\AssembleRule(new Assembler\PropertyDefaultsAssembler())
            ])
        )
    )

It works together with the PropertyAssembler and will enhance the default value generation for :

  • mixed => null
  • string => ''
  • int => 0
  • float => 0.0
  • bool => false
  • array => []

Example:

    /**
     * @var int
     */
    private int $quantity = 0;

@veewee veewee merged commit 23cfd66 into phpro:v4.x Jan 10, 2025
6 checks passed
veewee added a commit that referenced this pull request Jan 30, 2025
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.

1 participant