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

[11.x] Fix for breaking change in #53543 when ::withoutWrapping() is called after instance creation #53685

Conversation

SanderMuller
Copy link
Contributor

@SanderMuller SanderMuller commented Nov 27, 2024

Fixes breaking change introduced in #53543

Comment finding the breaking change: #53543 (comment)

See failing test which is added to test the code below now is without a wrapper:

$resource = new PostResource(new Post([
    'id' => 5,
    'title' => 'Test Title',
]));
$resource::withoutWrapping();

This PR adds a check to determine if an explicit wrapper has been set on the instance, if not, use the logic from before #53543, this allows for static wrapper changes after the instance is created to have impact.

12.x consideration

It's worth considering making an intended breaking change in 12.x to no longer let static updates change the wrapper after instantiation, but this PR focuses on removing the breaking change I introduced with #53543

wrapper property consideration

Edit: this fix does introduce the side effect that manually setting $instance->wrapper = 'posts' will now have no effect, since that doesn't set the wrapperSet flag. Maybe the wrapper property should be protected/private with a getter (or async visibility in the future 👀)

Fixes
$resource = new PostResource(new Post([
    'id' => 5,
    'title' => 'Test Title',
]));
$resource::withoutWrapping();
@taylorotwell
Copy link
Member

Reverted the original PR. We're going to revisit API resources in general for 12.x in February.

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.

2 participants