8000 [PasswordHasher] Add union types · symfony/symfony@fe3fdfd · GitHub
[go: up one dir, main page]

Skip to content

Commit fe3fdfd

Browse files
[PasswordHasher] Add union types
1 parent f4ded44 commit fe3fdfd

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

src/Symfony/Component/PasswordHasher/Hasher/PasswordHasherFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface;
1717
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
1818
use Symfony\Component\Security\Core\Encoder\PasswordHasherAdapter;
19+
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
20+
use Symfony\Component\Security\Core\User\UserInterface;
1921

2022
/**
2123
* A generic hasher factory implementation.
@@ -38,7 +40,7 @@ public function __construct(array $passwordHashers)
3840
/**
3941
* {@inheritdoc}
4042
*/
41-
public function getPasswordHasher($user): PasswordHasherInterface
43+
public function getPasswordHasher(UserInterface|string|PasswordAuthenticatedUserInterface $user): PasswordHasherInterface
4244
{
4345
$hasherKey = null;
4446

src/Symfony/Component/PasswordHasher/Hasher/PasswordHasherFactoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ interface PasswordHasherFactoryInterface
2626
/**
2727
* Returns the password hasher to use for the given user.
2828
*
29-
* @param PasswordAuthenticatedUserInterface|UserInterface|string $user A PasswordAuthenticatedUserInterface/UserInterface instance or a class name
29+
* @param string|PasswordAuthenticatedUserInterface|UserInterface $user A PasswordAuthenticatedUserInterface/UserInterface instance or a class name
3030
*
3131
* @throws \RuntimeException When no password hasher could be found for the user
3232
*/
33-
public function getPasswordHasher($user): PasswordHasherInterface;
33+
public function getPasswordHasher(UserInterface|string|PasswordAuthenticatedUserInterface $user): PasswordHasherInterface;
3434
}

src/Symfony/Component/PasswordHasher/Hasher/UserPasswordHasher.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public function __construct(PasswordHasherFactoryInterface $hasherFactory)
3131
$this->hasherFactory = $hasherFactory;
3232
}
3333

34-
/**
35-
* @param PasswordAuthenticatedUserInterface $user
36-
*/
37-
public function hashPassword($user, string $plainPassword): string
34+
public function hashPassword(UserInterface|string|PasswordAuthenticatedUserInterface $user, string $plainPassword): string
3835
{
3936
if (!$user instanceof PasswordAuthenticatedUserInterface) {
4037
if (!$user instanceof UserInterface) {
@@ -53,10 +50,7 @@ public function hashPassword($user, string $plainPassword): string
5350
return $hasher->hash($plainPassword, $salt);
5451
}
5552

56-
/**
57-
* @param PasswordAuthenticatedUserInterface $user
58-
*/
59-
public function isPasswordValid($user, string $plainPassword): bool
53+
public function isPasswordValid(UserInterface|string|PasswordAuthenticatedUserInterface $user, string $plainPassword): bool
6054
{
6155
if (!$user instanceof PasswordAuthenticatedUserInterface) {
6256
if (!$user instanceof UserInterface) {
@@ -79,10 +73,7 @@ public function isPasswordValid($user, string $plainPassword): bool
7973
return $hasher->verify($user->getPassword(), $plainPassword, $salt);
8074
}
8175

82-
/**
83-
* @param PasswordAuthenticatedUserInterface $user
84-
*/
85-
public function needsRehash($user): bool
76+
public function needsRehash(UserInterface|string|PasswordAuthenticatedUserInterface $user): bool
8677
{
8778
if (null === $user->getPassword()) {
8879
return false;

0 commit comments

Comments
 (0)
0