Skip to content

Invoke macro methods call for Hyperf\HttpServer\Response#7731

Merged
limingxinleo merged 7 commits into
hyperf:masterfrom
gokure:http-response-macro-call
May 9, 2026
Merged

Invoke macro methods call for Hyperf\HttpServer\Response#7731
limingxinleo merged 7 commits into
hyperf:masterfrom
gokure:http-response-macro-call

Conversation

@gokure
Copy link
Copy Markdown
Contributor

@gokure gokure commented Apr 1, 2026

No description provided.

@gokure
Copy link
Copy Markdown
Contributor Author

gokure commented Apr 28, 2026

could someone review it?

@gokure
Copy link
Copy Markdown
Contributor Author

gokure commented Apr 28, 2026

Why is this PR hidden?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 / __callStatic so they can be invoked from Response’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 $response is retrieved from Context as 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);
}
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
limingxinleo
limingxinleo previously approved these changes May 9, 2026
@limingxinleo limingxinleo merged commit 1b78bbe into hyperf:master May 9, 2026
60 checks passed
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.

3 participants