Invoke macro methods call for Hyperf\HttpServer\Response#7731
Merged
Conversation
Contributor
Author
|
could someone review it? |
Contributor
Author
|
Why is this PR hidden? |
There was a problem hiding this comment.
Pull request overview
Enables Hyperf\HttpServer\Response to correctly invoke methods registered via Macroable when they are called through __call() / __callStatic().
Changes:
- Aliases
Macroable::__call/__callStaticso they can be invoked fromResponse’s own magic methods. - Adds
hasMacro()checks to route dynamic calls to macro implementations before falling back to the wrapped PSR-7 response.
Comments suppressed due to low confidence (1)
src/http-server/src/Response.php:83
- In
__callStatic(), the forwarding call uses$response::{$method}(...$parameters)even though$responseis retrieved fromContextas an object. In PHP 8+, this will fatally error for non-static PSR-7 response methods (e.g.,withHeader,withStatus). Use an instance call ($response->{$method}(...$parameters)) or otherwise ensure the context value is a class-string with static methods.
$response = Context::get(PsrResponseInterface::class);
if (! method_exists($response, $method)) {
throw new BadMethodCallException(sprintf('Call to undefined static method %s::%s()', self::class, $method));
}
return $response::{$method}(...$parameters);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
59
to
+76
| @@ -64,6 +71,10 @@ public function __call($method, $parameters) | |||
|
|
|||
| public static function __callStatic($method, $parameters) | |||
| { | |||
| if (static::hasMacro($method)) { | |||
| return static::macroCallStatic($method, $parameters); | |||
| } | |||
There was a problem hiding this comment.
This change introduces new behavior where macros are now invoked from Response::__call() / Response::__callStatic() when hasMacro() is true. Please add PHPUnit coverage to verify (1) instance macros are executed and receive arguments, (2) static macros are executed, and (3) non-macro calls still forward to the underlying PSR-7 response.
Co-authored-by: Copilot <[email protected]>
limingxinleo
previously approved these changes
May 9, 2026
limingxinleo
approved these changes
May 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.