@@ -69,6 +69,13 @@ class IsTrueValidator extends ConstraintValidator
6969 */
7070 protected $ recaptchaVerifyServer ;
7171
72+ /**
73+ * The timeout for the reCAPTCHA verification.
74+ *
75+ * @var int|null
76+ */
77+ private $ timeout ;
78+
7279 /**
7380 * @param bool $enabled
7481 * @param string $privateKey
@@ -78,6 +85,7 @@ class IsTrueValidator extends ConstraintValidator
7885 * @param AuthorizationCheckerInterface|null $authorizationChecker
7986 * @param array $trustedRoles
8087 * @param string $apiHost
88+ * @param int|null $timeout
8189 */
8290 public function __construct (
8391 $ enabled ,
@@ -87,7 +95,8 @@ public function __construct(
8795 $ verifyHost ,
8896 AuthorizationCheckerInterface $ authorizationChecker = null ,
8997 array $ trustedRoles = array (),
90- $ apiHost = 'www.google.com ' )
98+ $ apiHost = 'www.google.com ' ,
99+ $ timeout = null )
91100 {
92101 $ this ->enabled = $ enabled ;
93102 $ this ->privateKey = $ privateKey ;
@@ -97,6 +106,7 @@ public function __construct(
97106 $ this ->authorizationChecker = $ authorizationChecker ;
98107 $ this ->trustedRoles = $ trustedRoles ;
99108 $ this ->recaptchaVerifyServer = 'https:// ' .$ apiHost ;
109+ $ this ->timeout = $ timeout ;
100110 }
101111
102112 /**
@@ -123,9 +133,9 @@ public function validate($value, Constraint $constraint)
123133
124134 // Verify user response with Google
125135 if (null !== $ this ->httpProxy ['host ' ] && null !== $ this ->httpProxy ['port ' ]) {
126- $ requestMethod = new ProxyPost ($ this ->httpProxy , $ this ->recaptchaVerifyServer );
136+ $ requestMethod = new ProxyPost ($ this ->httpProxy , $ this ->recaptchaVerifyServer , $ this -> timeout );
127137 } else {
128- $ requestMethod = new Post ($ this ->recaptchaVerifyServer );
138+ $ requestMethod = new Post ($ this ->recaptchaVerifyServer , $ this -> timeout );
129139 }
130140 $ recaptcha = new ReCaptcha ($ this ->privateKey , $ requestMethod );
131141 $ response = $ recaptcha ->verify ($ answer , $ remoteip );
0 commit comments