Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 58cb5ff

Browse files
committed
new ReCaptchaBuilder class constants: DEFAULT_API_VERSION and DEFAULT_CURL_TIMEOUT
1 parent 62f9e6e commit 58cb5ff

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/ReCaptchaBuilder.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,22 @@
1212

1313
use Exception;
1414

15+
/**
16+
* Class ReCaptchaBuilder
17+
* @package Biscolab\ReCaptcha
18+
*/
1519
class ReCaptchaBuilder {
1620

21+
/**
22+
* @var string
23+
*/
24+
const DEFAULT_API_VERSION = 'v2';
25+
26+
/**
27+
* @var int
28+
*/
29+
const DEFAULT_CURL_TIMEOUT = 10;
30+
1731
/**
1832
* The Site key
1933
* please visit https://developers.google.com/recaptcha/docs/start
@@ -53,7 +67,20 @@ class ReCaptchaBuilder {
5367
*/
5468
protected $api_url = 'https://www.google.com/recaptcha/api/siteverify';
5569

56-
public function __construct($api_site_key, $api_secret_key, $version = 'v2', $curl_timeout = 3) {
70+
/**
71+
* ReCaptchaBuilder constructor.
72+
*
73+
* @param string $api_site_key
74+
* @param string $api_secret_key
75+
* @param null|string $version
76+
* @param int|null $curl_timeout
77+
*/
78+
public function __construct(
79+
string $api_site_key,
80+
string $api_secret_key,
81+
?string $version = self::DEFAULT_API_VERSION,
82+
?int $curl_timeout = self::DEFAULT_CURL_TIMEOUT
83+
) {
5784

5885
$this->setApiSiteKey($api_site_key);
5986
$this->setApiSecretKey($api_secret_key);
@@ -88,6 +115,7 @@ public function setApiSecretKey(string $api_secret_key): ReCaptchaBuilder {
88115

89116
/**
90117
* @param int $curl_timeout
118+
*
91119
* @return ReCaptchaBuilder
92120
*/
93121
public function setCurlTimeout(int $curl_timeout): ReCaptchaBuilder {
@@ -141,9 +169,10 @@ public function setSkipByIp(bool $skip_by_ip): ReCaptchaBuilder {
141169
* @return array|mixed
142170
*/
143171
public function getIpWhitelist() {
172+
144173
$whitelist = config('recaptcha.skip_ip', []);
145174

146-
if(!is_array($whitelist)) {
175+
if (!is_array($whitelist)) {
147176
$whitelist = explode(',', $whitelist);
148177
}
149178

@@ -214,7 +243,9 @@ function biscolabLaravelReCaptcha(token) {
214243
$js_callback_catch = ($js_callback_catch) ? "{$js_callback_catch}(err)" : '';
215244

216245
$validate_function = "
217-
fetch('/" . config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name', 'token') . "=' + token, {
246+
fetch('/" . config('recaptcha.default_validation_route',
247+
'biscolab-recaptcha/validate') . "?" . config('recaptcha.default_token_parameter_name',
248+
'token') . "=' + token, {
218249
headers: {
219250
\"X-Requested-With\": \"XMLHttpRequest\",
220251
\"X-CSRF-TOKEN\": csrfToken.content

0 commit comments

Comments
 (0)