Merge branch '4.3' into 4.4

* 4.3:
  Fix merge
This commit is contained in:
Nicolas Grekas 2019-12-12 14:17:19 +01:00
commit 93b2f9ef6f
3 changed files with 22 additions and 7 deletions

View File

@ -202,7 +202,7 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
{
try {
return $this->entityManager ? $this->entityManager->getClassMetadata($class) : $this->classMetadataFactory->getMetadataFor($class);
} catch (MappingException | OrmMappingException $exception) {
} catch (MappingException | OrmMappingException | LegacyMappingException $exception) {
return null;
}
}

View File

@ -51,7 +51,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
*/
public function loadUserByUsername($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

@ -408,7 +408,7 @@ class DoctrineChoiceLoaderTest extends TestCase
})
;
$this->om = $this->createMock(ObjectManager::class);
$this->om = $this->createMock(interface_exists(ObjectManager::class) ? ObjectManager::class : LegacyObjectManager::class);
$this->om->expects($this->once())
->method('getClassMetadata')
->with(SingleIntIdEntity::class)