Skip to content

Commit 4d9cb9d

Browse files
author
full
committed
Don't get repository at construction time, it could be not loaded yet!
1 parent fe3e2b5 commit 4d9cb9d

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

Entity/TokenManager.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,30 @@ class TokenManager extends BaseTokenManager
2525
*/
2626
protected $em;
2727

28-
/**
29-
* @var EntityRepository
30-
*/
31-
protected $repository;
32-
3328
/**
3429
* @var string
3530
*/
3631
protected $class;
3732

3833
public function __construct(EntityManagerInterface $em, $class)
3934
{
40-
// NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected
41-
/** @var EntityRepository $repository */
42-
$repository = $em->getRepository($class);
43-
4435
$this->em = $em;
45-
$this->repository = $repository;
4636
$this->class = $class;
4737
}
4838

39+
/**
40+
* retrocompatibility with old $repository property
41+
* @param $name
42+
* @return mixed
43+
*/
44+
public function __get($name)
45+
{
46+
if('repository' === $name){
47+
return $this->getRepository();
48+
}
49+
50+
return $this->$name;
51+
}
4952
/**
5053
* {@inheritdoc}
5154
*/
@@ -59,7 +62,7 @@ public function getClass()
5962
*/
6063
public function findTokenBy(array $criteria)
6164
{
62-
return $this->repository->findOneBy($criteria);
65+
return $this->getRepository()->findOneBy($criteria);
6366
}
6467

6568
/**
@@ -85,7 +88,7 @@ public function deleteToken(TokenInterface $token)
8588
*/
8689
public function deleteExpired()
8790
{
88-
$qb = $this->repository->createQueryBuilder('t');
91+
$qb = $this->getRepository()->createQueryBuilder('t');
8992
$qb
9093
->delete()
9194
->where('t.expiresAt < ?1')
@@ -94,4 +97,12 @@ public function deleteExpired()
9497

9598
return $qb->getQuery()->execute();
9699
}
100+
101+
/**
102+
* @return EntityRepository
103+
*/
104+
protected function getRepository(): EntityRepository
105+
{
106+
return $this->em->getRepository($this->class);
107+
}
97108
}

0 commit comments

Comments
 (0)