Invoke macro methods call for Hyperf\HttpServer\Response#7731
Conversation
|
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.
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 <copilot@github.com>

No description provided.