| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
This PR refactors the Parser::parseResponse method to return a more standardized format using stdClass instead of a mixed-type array. The change replaces the old three-element array format [message, code, response] with a two-element array [message, statusObject] where the status object contains code, details, and metadata fields.
Key Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/grpc/src/Parser.php | Refactored parseResponse method to return structured stdClass status object instead of mixed array elements |
| CHANGELOG-3.2.md | Added changelog entry documenting the improvement |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| return [ | ||
| self::deserializeMessage($deserialize, $response->data ?? ''), | ||
| self::statusFromResponse($response), | ||
| $response, | ||
| ]; |
There was a problem hiding this comment.
Critical error handling logic has been removed without replacement. The old implementation checked for:
The new implementation only calls statusFromResponse() which only extracts grpc-status-details-bin header. This means:
The method now deserializes the response data unconditionally, even when there are errors, which could lead to deserialization failures or incorrect behavior. The error handling logic should be restored to properly validate the response before attempting deserialization.
Sorry, something went wrong.
- Replace Grpc\StringifyAble with stdClass for better standardization - Update return type annotation to be more explicit about the structure - Standardize all return paths to use consistent stdClass status object - Improve code readability and maintainability
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…s codes and messages
…alize parameters in UnaryCall class
…streamId directly
…ethod in UnaryCall class
There was a problem hiding this comment.
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
| if (in_array($lowerKey, ['content-type', 'content-length', 'te'])) { | ||
| continue; | ||
| } | ||
| // 处理-bin结尾 metadata |
There was a problem hiding this comment.
[nitpick] The comment contains Chinese characters which may not be clear to all contributors. Consider translating to English: "Handle -bin suffixed metadata"
| // 处理-bin结尾 metadata | |
| // Handle -bin suffixed metadata |
Sorry, something went wrong.
| $status = new stdClass(); | ||
| $status->code = 0; | ||
| $status->details = 'OK'; | ||
| $status->metadata = []; |
There was a problem hiding this comment.
The metadata is initialized as an empty array on line 57, but should be initialized to match the documented return type. According to the PHPDoc annotations, metadata should be typed as null|Http2Response in the return type (lines 23, 35, 50), not as an array. Either change line 57 to $status->metadata = null; or update the PHPDoc to reflect that metadata is an array of parsed headers.
| $status->metadata = []; | |
| $status->metadata = null; |
Sorry, something went wrong.
| if (str_starts_with($lowerKey, 'grpc-') && $lowerKey !== 'grpc-status-details-bin') { | ||
| continue; | ||
| } | ||
| // 忽略http2预留伪头 |
There was a problem hiding this comment.
[nitpick] The comment contains Chinese characters which may not be clear to all contributors. Consider translating to English: "Ignore HTTP/2 reserved pseudo-headers"
| // 忽略http2预留伪头 | |
| // Ignore HTTP/2 reserved pseudo-headers |
Sorry, something went wrong.
| if (str_starts_with($lowerKey, ':')) { | ||
| continue; | ||
| } | ||
| // 忽略 HTTP/2 传输层头部 |
There was a problem hiding this comment.
[nitpick] The comment contains Chinese characters which may not be clear to all contributors. Consider translating to English: "Ignore HTTP/2 transport layer headers"
| // 忽略 HTTP/2 传输层头部 | |
| // Ignore HTTP/2 transport layer headers |
Sorry, something went wrong.
| }, $this->options['retry_interval'] ?? 100); | ||
| return Parser::parseResponse($this->recv($streamId), $deserialize); | ||
|
|
||
| return new UnaryCall($this, $streamId, $deserialize); |
There was a problem hiding this comment.
This change breaks existing tests. The method now returns a UnaryCall object instead of directly parsing and returning the response. However, BaseClientTest.php expects _simpleRequest to return a numeric value (stream ID) in tests like testGrpcClientReconnect() which calls $this->assertGreaterThan(0, $client->sayHello()). Since sayHello() returns the result of _simpleRequest, these tests will fail. The tests need to be updated to call ->wait() on the returned UnaryCall object, or test coverage should be added for the new return behavior.
Sorry, something went wrong.
| $status->code = 0; | ||
| $status->details = 'OK'; | ||
| $status->metadata = []; | ||
| $status->rawResponse = $response; |
There was a problem hiding this comment.
The rawResponse property is being added to the status object but is not documented in the return type annotation. The PHPDoc at line 35 and 50 should include rawResponse in the stdClass structure definition: stdClass{code:int,details:string,metadata:array,rawResponse:null|Http2Response}
Sorry, something went wrong.
|
|
||
| foreach ($response->headers as $key => $value) { | ||
| $lowerKey = strtolower($key); | ||
| // 忽略grpc官方预留,将grpc-status-details-bin保留,可解析为Google\Rpc\Status |
There was a problem hiding this comment.
[nitpick] The comment contains Chinese characters which may not be clear to all contributors. Consider translating to English: "Ignore official gRPC reserved headers, keep grpc-status-details-bin which can be parsed as Google\Rpc\Status"
| // 忽略grpc官方预留,将grpc-status-details-bin保留,可解析为Google\Rpc\Status | |
| // Ignore official gRPC reserved headers, keep grpc-status-details-bin which can be parsed as Google\Rpc\Status |
Sorry, something went wrong.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
Summary
Changes Made
Test Plan