@@ -21,11 +21,11 @@ class IsTrueValidator extends ConstraintValidator
2121 protected $ enabled ;
2222
2323 /**
24- * Recaptcha Private Key .
24+ * Recaptcha.
2525 *
26- * @var string
26+ * @var ReCaptcha
2727 */
28- protected $ privateKey ;
28+ protected $ recaptcha ;
2929
3030 /**
3131 * Request Stack.
@@ -34,13 +34,6 @@ class IsTrueValidator extends ConstraintValidator
3434 */
3535 protected $ requestStack ;
3636
37- /**
38- * HTTP Proxy informations.
39- *
40- * @var array
41- */
42- protected $ httpProxy ;
43-
4437 /**
4538 * Enable serverside host check.
4639 *
@@ -62,51 +55,28 @@ class IsTrueValidator extends ConstraintValidator
6255 */
6356 protected $ trustedRoles ;
6457
65- /**
66- * The reCAPTCHA verify server URL.
67- *
68- * @var string
69- */
70- protected $ recaptchaVerifyServer ;
71-
72- /**
73- * The timeout for the reCAPTCHA verification.
74- *
75- * @var int|null
76- */
77- private $ timeout ;
78-
7958 /**
8059 * @param bool $enabled
81- * @param string $privateKey
60+ * @param ReCaptcha $recaptcha
8261 * @param RequestStack $requestStack
83- * @param array $httpProxy
8462 * @param bool $verifyHost
8563 * @param AuthorizationCheckerInterface|null $authorizationChecker
8664 * @param array $trustedRoles
87- * @param string $apiHost
88- * @param int|null $timeout
8965 */
9066 public function __construct (
9167 $ enabled ,
92- $ privateKey ,
68+ ReCaptcha $ recaptcha ,
9369 RequestStack $ requestStack ,
94- array $ httpProxy ,
9570 $ verifyHost ,
9671 AuthorizationCheckerInterface $ authorizationChecker = null ,
97- array $ trustedRoles = array (),
98- $ apiHost = 'www.google.com ' ,
99- $ timeout = null )
72+ array $ trustedRoles = array ())
10073 {
10174 $ this ->enabled = $ enabled ;
102- $ this ->privateKey = $ privateKey ;
75+ $ this ->recaptcha = $ recaptcha ;
10376 $ this ->requestStack = $ requestStack ;
104- $ this ->httpProxy = $ httpProxy ;
10577 $ this ->verifyHost = $ verifyHost ;
10678 $ this ->authorizationChecker = $ authorizationChecker ;
10779 $ this ->trustedRoles = $ trustedRoles ;
108- $ this ->recaptchaVerifyServer = 'https:// ' .$ apiHost ;
109- $ this ->timeout = $ timeout ;
11080 }
11181
11282 /**
@@ -132,13 +102,7 @@ public function validate($value, Constraint $constraint)
132102 $ answer = $ masterRequest ->get ('g-recaptcha-response ' );
133103
134104 // Verify user response with Google
135- if (null !== $ this ->httpProxy ['host ' ] && null !== $ this ->httpProxy ['port ' ]) {
136- $ requestMethod = new ProxyPost ($ this ->httpProxy , $ this ->recaptchaVerifyServer , $ this ->timeout );
137- } else {
138- $ requestMethod = new Post ($ this ->recaptchaVerifyServer , $ this ->timeout );
139- }
140- $ recaptcha = new ReCaptcha ($ this ->privateKey , $ requestMethod );
141- $ response = $ recaptcha ->verify ($ answer , $ remoteip );
105+ $ response = $ this ->recaptcha ->verify ($ answer , $ remoteip );
142106
143107 if (!$ response ->isSuccess ()) {
144108 $ this ->context ->addViolation ($ constraint ->message );
0 commit comments