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

[8.x] Avoid constructor call when fetching resource JSON options #40261

Merged
merged 3 commits into from
Jan 5, 2022
Merged

[8.x] Avoid constructor call when fetching resource JSON options #40261

merged 3 commits into from
Jan 5, 2022

Conversation

philcross
Copy link
Contributor

As described in #40258 when we use a type hinted constructor, or a constructor that accepts more than 1 required parameter on a singular resource and it's constructed through a collection resource, the collectsResources::jsonOptions() method fails because it passes in an empty array just to be able to call the non-static jsonOptions method on the singular resource.

I'm not sure if this is too much "magic", but it's the the only thing I can think of to maintain backwards compatibility with whats recently been added without reverting the original PR, so if you don't agree, please feel free to reject the PR.

This will work to fix the issue however, as the constructor is no longer called when creating a new instance of the singular resource, therefore bypassing any type hints or multiple required parameters. This should be safer than passing in an empty array, as by passing in an empty array it's assumed that the constructor does nothing other than set the $resource property as the passed in parameter.

Automated test has been added, and I've checked this solution locally in https://github.com/philcross/laravel-jsonOptions-bug which is a project to reproduce the bug.

@philcross
Copy link
Contributor Author

The test appears to be failing due to an unrelated reason - Error response from daemon: Get "https://mcr.microsoft.com/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) I'm unable to re-run the workflow

@taylorotwell taylorotwell merged commit 424f97a into laravel:8.x Jan 5, 2022
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