File tree 1 file changed +7
-5
lines changed
src/Symfony/Component/Validator/Constraints
1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 14
14
use Symfony \Component \Validator \Constraint ;
15
15
use Symfony \Component \Validator \ConstraintValidator ;
16
16
use Symfony \Component \Validator \Exception \UnexpectedTypeException ;
17
+ use Symfony \Component \HttpClient \HttpClient ;
17
18
use Symfony \Contracts \HttpClient \Exception \ExceptionInterface ;
18
19
use Symfony \Contracts \HttpClient \HttpClientInterface ;
19
20
@@ -30,12 +31,13 @@ class NotPwnedValidator extends ConstraintValidator
30
31
private const RANGE_API = 'https://api.pwnedpasswords.com/range/%s ' ;
31
32
private $ httpClient ;
32
33
33
- /**
34
- * @param callable(string):string|null $httpClient
35
- */
36
- public function __construct (HttpClientInterface $ httpClient )
34
+ public function __construct (HttpClientInterface $ httpClient = null )
37
35
{
38
- $ this ->httpClient = $ httpClient ;
36
+ if (null === $ httpClient && !class_exists (HttpClient::class)) {
37
+ throw new \LogicException (sprintf ('The "%s" class requires the "HttpClient" component. Try running "composer require symfony/http-client". ' , self ::class));
38
+ }
39
+
40
+ $ this ->httpClient = $ httpClient ?? HttpClient::create ();
39
41
}
40
42
41
43
/**
You can’t perform that action at this time.
0 commit comments