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

fix: allow unions with several object classes #69

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

nikophil
Copy link
Collaborator

@nikophil nikophil commented Mar 18, 2024

before this PR, an error would have occurred when trying to map a property which is an union of several objects.

This code:

private Foo|Bar $prop

was generating this mapper:

if (\AutoMapper\MapperContext::isAllowedAttribute($context, 'prop', isset($value->prop))) {
    $value_1 = $value->prop;
    if (is_object($value->prop)) {
        // map form Foo
    }
    if (is_object($value->prop)) {
        // map form Bar
    }
    $result['prop'] = $value_1;
}

so it never tried to handle case when $prop is Bar

now, it adds an instanceof:

if (\AutoMapper\MapperContext::isAllowedAttribute($context, 'prop', isset($value->prop))) {
    $value_1 = $value->prop;
    if (is_object($value->prop) && $value->prop instanceof Foo) {
        // map form Foo
    }
    if (is_object($value->prop) && $value6->prop instanceof Bar) {
        // map form Bar
    }
    $result['prop'] = $value_1;
}

@nikophil nikophil requested review from joelwurtz and Korbeil and removed request for joelwurtz March 18, 2024 13:40
@nikophil nikophil marked this pull request as ready for review March 18, 2024 13:45
@Korbeil Korbeil merged commit 64c021c into jolicode:main Mar 18, 2024
6 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

2 participants