Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51ac9c3

Browse files
committed
Use default client if available
1 parent c3ac139 commit 51ac9c3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Symfony/Component/Validator/Constraints/NotPwnedValidator.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Validator\Constraint;
1515
use Symfony\Component\Validator\ConstraintValidator;
1616
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
17+
use Symfony\Component\HttpClient\HttpClient;
1718
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920

@@ -30,12 +31,13 @@ class NotPwnedValidator extends ConstraintValidator
3031
private const RANGE_API = 'https://api.pwnedpasswords.com/range/%s';
3132
private $httpClient;
3233

33-
/**
34-
* @param callable(string):string|null $httpClient
35-
*/
36-
public function __construct(HttpClientInterface $httpClient)
34+
public function __construct(HttpClientInterface $httpClient = null)
3735
{
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();
3941
}
4042

4143
/**

0 commit comments

Comments
 (0)