feat: harden validation edge cases, add immutable with*() builders, and unify transport HTTP handling - #637
Merged
Conversation
…nd unify transport HTTP handling
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.
Summary
Implements the remaining backwards-compatible validation, transport consistency, and developer experience improvements:
ReCaptcha::verify()):setScoreThreshold(0.0)null-coercion bypass whenscoreis omitted (null) from the API response so it properly recordsReCaptcha::E_SCORE_THRESHOLD_NOT_MET.setChallengeTimeout()fail closed (ReCaptcha::E_CHALLENGE_TIMEOUT) whenchallenge_tsis missing or unparseable instead of silently skipping timeout enforcement.with*()Builder Methods (ReCaptcha):withExpectedHostname(),withExpectedApkPackageName(),withExpectedAction(),withScoreThreshold(), andwithChallengeTimeout()that clone theReCaptchainstance before applying expectations—allowing safe singleton injection in DI containers and persistent worker runtimes (FrankenPHP, RoadRunner, Swoole, Laravel Octane) while remaining 100% backwards-compatible withset*().CurlPost: Lazily initialize and reuse theCurlHandleacrosssubmit()calls for TLS session/keep-alive reuse, handlecurl_init()failure cleanly, and validateCURLINFO_HTTP_CODE === 200(returningReCaptcha::E_BAD_RESPONSEon non-200 responses, matchingSocketPost).Post: Enable'ignore_errors' => trueand validate the HTTP 200 status line viahttp_get_last_response_headers()to returnReCaptcha::E_BAD_RESPONSEon non-200 HTTP responses without emitting PHP warnings.SocketPost: Loopfwrite()until all request bytes are written on the TLS socket stream and fail cleanly withReCaptcha::E_CONNECTION_FAILED(closing the socket handle) iffwrite()fails or writes 0 bytes.src/autoload.phpverification.roave/backward-compatibility-check:^8.22in.github/workflows/php.yml.