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] Support attributes in app()->call() #52428

Merged
merged 3 commits into from
Aug 17, 2024

Conversation

innocenzi
Copy link
Contributor

@innocenzi innocenzi commented Aug 8, 2024

This pull request is a follow-up of #51934. It adds support for the same features on app()->call(), therefore supporting parameters injected to routes, handle methods, etc.

Important note

Since the resolution of the dependencies of closures happens outside of the container itself (in BoundMethod), we don't have access to methods that are needed for this to work.

Specifically:

  • resolveFromAttribute
  • fireAfterResolvingAttributeCallbacks

These cannot be copied to BoundMethod because they depend on properties of the container (contextualAttributes and afterResolvingAttributeCallbacks).

I couldn't find a clean solution for this that didn't involve a bigger refactor. For now, I made these methods public, but the pull request cannot be merged as-is, as we do not want them to be available to the public API.

Possible solutions

  • I thought of refactoring BoundMethod#addDependencyForCallParameter to use Container#resolveDependencies, but it doesn't support the $parameters array and its behavior is slightly different.
  • BoundMethod could be integrated into the Container itself (but we can't get rid of the class entirely, it is not marked as @internal, projects like Livewire use it).
  • We could invade methods of the container, but this is slow and hacky.

Any suggestion?

Copy link

github-actions bot commented Aug 8, 2024

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@taylorotwell taylorotwell marked this pull request as ready for review August 8, 2024 13:27
@taylorotwell
Copy link
Member

taylorotwell commented Aug 16, 2024

@innocenzi it looks like one area we may still be missing is routes. Those dependencies are resolved via the ResolvesRouteDependencies trait. 😵‍💫 So right now container attributes don't work on dependencies type-hinted on a closure route or I assume controller either.

@innocenzi
Copy link
Contributor Author

I'll look into that as well then 👍

@innocenzi
Copy link
Contributor Author

@taylorotwell I added support and tests for that, but the implementation suffers from the same issues as BoundMethod I'm afraid

@taylorotwell
Copy link
Member

@innocenzi thanks!

@taylorotwell taylorotwell merged commit 14ee5d4 into laravel:11.x Aug 17, 2024
29 checks passed
@innocenzi innocenzi deleted the feat/attributes-on-handle branch August 18, 2024 22:43
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