Skip to content

Commit ed6a285

Browse files
committed
prevent DB connections inside constructor code
1 parent 88b8724 commit ed6a285

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Changelog
88
* Add a timeout for the reset retry request.
99
* Add Esperanto translations.
1010
* Fixed incorrect confirmation url.
11+
* [BC break] Use UserManager::getRepository() instead of UserManager::$repository
12+
* [BC break] Use UserManager::getClass() instead of UserManager::$class
1113

1214
### 2.0.0-beta2 (2017-01-31)
1315

Doctrine/UserManager.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ class UserManager extends BaseUserManager
2828
/**
2929
* @var string
3030
*/
31-
protected $class;
32-
33-
/**
34-
* @var ObjectRepository
35-
*/
36-
protected $repository;
31+
private $class;
3732

3833
/**
3934
* Constructor.
@@ -48,10 +43,15 @@ public function __construct(PasswordUpdaterInterface $passwordUpdater, Canonical
4843
parent::__construct($passwordUpdater, $canonicalFieldsUpdater);
4944

5045
$this->objectManager = $om;
51-
$this->repository = $om->getRepository($class);
46+
$this->class = $class;
47+
}
5248

53-
$metadata = $om->getClassMetadata($class);
54-
$this->class = $metadata->getName();
49+
/**
50+
* @return ObjectRepository
51+
*/
52+
protected function getRepository()
53+
{
54+
return $this->objectManager->getRepository($this->getClass());
5555
}
5656

5757
/**
@@ -68,6 +68,11 @@ public function deleteUser(UserInterface $user)
6868
*/
6969
public function getClass()
7070
{
71+
if (false !== strpos($this->class, ':')) {
72+
$metadata = $this->objectManager->getClassMetadata($this->class);
73+
$this->class = $metadata->getName();
74+
}
75+
7176
return $this->class;
7277
}
7378

@@ -76,15 +81,15 @@ public function getClass()
7681
*/
7782
public function findUserBy(array $criteria)
7883
{
79-
return $this->repository->findOneBy($criteria);
84+
return $this->getRepository()->findOneBy($criteria);
8085
}
8186

8287
/**
8388
* {@inheritdoc}
8489
*/
8590
public function findUsers()
8691
{
87-
return $this->repository->findAll();
92+
return $this->getRepository()->findAll();
8893
}
8994

9095
/**

Resources/config/doctrine.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<services>
8-
<service id="fos_user.user_manager.default" class="FOS\UserBundle\Doctrine\UserManager" public="false" lazy="true">
8+
<service id="fos_user.user_manager.default" class="FOS\UserBundle\Doctrine\UserManager" public="false">
99
<argument type="service" id="fos_user.util.password_updater" />
1010
<argument type="service" id="fos_user.util.canonical_fields_updater" />
1111
<argument type="service" id="fos_user.object_manager" />

0 commit comments

Comments
 (0)