File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Expand file tree Collapse file tree 3 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
use FriendlyCaptcha \SDK \{ClientConfig , VerifyResult , ErrorCodes };
8
8
9
- const VERSION = "0.1.1 " ;
9
+ const VERSION = "0.1.2 " ;
10
10
const EU_API_ENDPOINT = "https://eu.frcapi.com/api/v2/captcha/siteverify " ;
11
11
const GLOBAL_API_ENDPOINT = "https://global.frcapi.com/api/v2/captcha/siteverify " ;
12
12
@@ -54,6 +54,11 @@ public function verifyCaptchaResponse(?string $response): VerifyResult
54
54
$ requestFields ["sitekey " ] = $ this ->config ->sitekey ;
55
55
}
56
56
57
+ $ frcSdk = 'friendly-captcha-php@ ' . VERSION ;
58
+ if ($ this ->config ->sdkTrailer != "" ) {
59
+ $ frcSdk = $ frcSdk . "; " . $ this ->config ->sdkTrailer ;
60
+ }
61
+
57
62
$ payload = json_encode ($ requestFields );
58
63
if ($ payload === false ) {
59
64
// TODO: should we put `json_last_error()` somewhere on the object?
@@ -76,7 +81,7 @@ public function verifyCaptchaResponse(?string $response): VerifyResult
76
81
'Content-Type: application/json ' ,
77
82
'Content-Length: ' . strlen ($ payload ),
78
83
'X-Api-Key: ' . $ this ->config ->apiKey ,
79
- 'Frc-Sdk: ' . ' friendly-captcha-php@ ' . VERSION
84
+ 'Frc-Sdk: ' . $ frcSdk ,
80
85
)
81
86
);
82
87
curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ payload );
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ class ClientConfig
10
10
{
11
11
public $ apiKey = "" ;
12
12
public $ sitekey = "" ;
13
+ public $ sdkTrailer = "" ;
13
14
public $ siteverifyEndpoint = "global " ;
14
15
public $ strict = false ;
15
16
public $ timeout = 30 ;
@@ -37,6 +38,21 @@ public function setSitekey(string $sitekey): self
37
38
return $ this ;
38
39
}
39
40
41
+ /**
42
+ * An "Frc-Sdk" HTTP header is sent as part of the API request to identify the SDK being used to initiate the request.
43
+ * A downstream SDK might depend on *this* SDK, so this function is provided to allow the downstream SDK to append an
44
+ * identifier to uniquely identify it. For example, this library sends an "Frc-Sdk" header of
45
+ * `[email protected] `. If `friendly-captcha-wordpress` depends on it, it can add a trailer so that requests
46
+ * will use an "Frc-Sdk" header of `[email protected] ; [email protected] `.
47
+ *
48
+ * @param string $sdk an identifier that describes the component that depends on this SDK.
49
+ */
50
+ public function setSDKTrailer (string $ sdkTrailer ): self
51
+ {
52
+ $ this ->sdkTrailer = $ sdkTrailer ;
53
+ return $ this ;
54
+ }
55
+
40
56
/**
41
57
* @param string $siteverifyEndpoint a full URL, or the shorthands `"global"` or `"eu"`.
42
58
*/
Original file line number Diff line number Diff line change 7
7
use FriendlyCaptcha \SDK \{Client , ClientConfig };
8
8
use Exception ;
9
9
10
+ use PHPUnit \Framework \Attributes \DataProvider ;
10
11
use PHPUnit \Framework \TestCase ;
11
12
12
13
const MOCK_SERVER_URL = "http://localhost:1090 " ;
@@ -86,6 +87,7 @@ public static function sdkMockTestsProvider(): array
86
87
/**
87
88
* @dataProvider sdkMockTestsProvider
88
89
*/
90
+ #[DataProvider('sdkMockTestsProvider ' )]
89
91
public function testSDKTestServerCase ($ test ): void
90
92
{
91
93
$ opts = new ClientConfig ();
You can’t perform that action at this time.
0 commit comments