Merge branch '5.0'

* 5.0:
  Add missing annotation
  Fix merge
This commit is contained in:
Nicolas Grekas 2019-12-12 14:37:04 +01:00
commit a8b6ba3609
3 changed files with 24 additions and 7 deletions

View File

@ -51,7 +51,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
*/
public function loadUserByUsername(string $username)
{
$repository = $this->registry->getManager($this->managerName)->getRepository($this->classOrAlias);
$repository = $this->getRepository();
if (null !== $this->property) {
$user = $repository->findOneBy([$this->property => $username]);
} else {
@ -79,7 +79,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
}
$repository = $this->registry->getManager($this->managerName)->getRepository($this->classOrAlias);
$repository = $this->getRepository();
if ($repository instanceof UserProviderInterface) {
$refreshedUser = $repository->refreshUser($user);
} else {
@ -87,7 +87,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
// might have changed without proper persistence in the database.
// That's the case when the user has been changed by a form with
// validation errors.
if (!$id = $this->registry->getManager($this->managerName)->getClassMetadata($this->classOrAlias)->getIdentifierValues($user)) {
if (!$id = $this->getClassMetadata()->getIdentifierValues($user)) {
throw new \InvalidArgumentException('You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine.');
}
@ -118,19 +118,29 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
}
$repository = $this->registry->getManager($this->managerName)->getRepository($this->classOrAlias);
$repository = $this->getRepository();
if ($repository instanceof PasswordUpgraderInterface) {
$repository->upgradePassword($user, $newEncodedPassword);
}
}
private function getObjectManager()
{
return $this->registry->getManager($this->managerName);
}
private function getRepository()
{
return $this->getObjectManager()->getRepository($this->classOrAlias);
}
private function getClass(): string
{
if (null === $this->class) {
$class = $this->classOrAlias;
if (false !== strpos($class, ':')) {
$class = $this->registry->getManager($this->managerName)->getClassMetadata($this->classOrAlias)->getName();
$class = $this->getClassMetadata()->getName();
}
$this->class = $class;
@ -138,4 +148,9 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
return $this->class;
}
private function getClassMetadata()
{
return $this->getObjectManager()->getClassMetadata($this->classOrAlias);
}
}

View File

@ -79,7 +79,7 @@ class DoctrineTestHelper
$symfonyFileLocator = class_exists(SymfonyFileLocator::class) ? SymfonyFileLocator::class : LegacySymfonyFileLocator::class;
$driverChain = class_exists(MappingDriverChain::class) ? MappingDriverChain::class : LegacyMappingDriverChain::class;
$driverChain = new MappingDriverChain();
$driverChain = new $driverChain();
$driverChain->addDriver(
new XmlDriver(
new $symfonyFileLocator(

View File

@ -29,8 +29,10 @@ final class TestRepositoryFactory implements RepositoryFactory
/**
* {@inheritdoc}
*
* @return ObjectRepository|LegacyObjectRepository
*/
public function getRepository(EntityManagerInterface $entityManager, $entityName): ObjectRepository
public function getRepository(EntityManagerInterface $entityManager, $entityName)
{
$repositoryHash = $this->getRepositoryHash($entityManager, $entityName);