Skip to content

Commit 8011758

Browse files
committed
bug #1114 [make:entity] _em will be private in ORM 3.0, use getEntityManager() (jrushlow)
This PR was merged into the 1.0-dev branch. Discussion ---------- [make:entity] _em will be private in ORM 3.0, use getEntityManager() In `ORM` 3.0 the `Doctrine\ORM\EntityRepository::_em` property will be private, we should use `EntityRepository::getEntityManager()` instead. Commits ------- 9a1d609 [make:entity] _em will be private in ORM 3.0
2 parents 5f7249c + 9a1d609 commit 8011758

File tree

4 files changed

+20
-46
lines changed

4 files changed

+20
-46
lines changed

src/Doctrine/EntityClassGenerator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313

1414
use ApiPlatform\Metadata\ApiResource;
1515
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
16-
use Doctrine\ORM\Exception\ORMException;
1716
use Doctrine\ORM\Mapping;
18-
use Doctrine\ORM\OptimisticLockException;
1917
use Doctrine\Persistence\ManagerRegistry;
2018
use Symfony\Bundle\MakerBundle\Generator;
2119
use Symfony\Bundle\MakerBundle\Str;
@@ -108,8 +106,6 @@ public function generateRepositoryClass(string $repositoryClass, string $entityC
108106
$entityClass,
109107
ManagerRegistry::class,
110108
ServiceEntityRepository::class,
111-
OptimisticLockException::class,
112-
ORMException::class,
113109
]);
114110

115111
if ($withPasswordUpgrade) {

src/Resources/skeleton/doctrine/Repository.tpl.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,21 @@ public function __construct(ManagerRegistry $registry)
1919
parent::__construct($registry, <?= $entity_class_name; ?>::class);
2020
}
2121

22-
/**
23-
* @throws ORMException
24-
* @throws OptimisticLockException
25-
*/
2622
public function add(<?= $entity_class_name ?> $entity, bool $flush = false): void
2723
{
28-
$this->_em->persist($entity);
24+
$this->getEntityManager()->persist($entity);
25+
2926
if ($flush) {
30-
$this->_em->flush();
27+
$this->getEntityManager()->flush();
3128
}
3229
}
3330

34-
/**
35-
* @throws ORMException
36-
* @throws OptimisticLockException
37-
*/
3831
public function remove(<?= $entity_class_name ?> $entity, bool $flush = false): void
3932
{
40-
$this->_em->remove($entity);
33+
$this->getEntityManager()->remove($entity);
34+
4135
if ($flush) {
42-
$this->_em->flush();
36+
$this->getEntityManager()->flush();
4337
}
4438
}
4539
<?php if ($include_example_comments): // When adding a new method without existing default comments, the blank line is automatically added.?>
@@ -56,8 +50,8 @@ public function upgradePassword(<?= sprintf('%s ', $password_upgrade_user_interf
5650
}
5751

5852
$user->setPassword($newHashedPassword);
59-
$this->_em->persist($user);
60-
$this->_em->flush();
53+
54+
$this->add($user, true);
6155
}
6256

6357
<?php endif ?>

tests/Doctrine/fixtures/expected_xml/src/Repository/UserRepository.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Repository;
44

55
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6-
use Doctrine\ORM\Exception\ORMException;
7-
use Doctrine\ORM\OptimisticLockException;
86
use Doctrine\Persistence\ManagerRegistry;
97
use Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity\UserXml;
108

@@ -23,27 +21,21 @@ public function __construct(ManagerRegistry $registry)
2321
parent::__construct($registry, UserXml::class);
2422
}
2523

26-
/**
27-
* @throws ORMException
28-
* @throws OptimisticLockException
29-
*/
3024
public function add(UserXml $entity, bool $flush = false): void
3125
{
32-
$this->_em->persist($entity);
26+
$this->getEntityManager()->persist($entity);
27+
3328
if ($flush) {
34-
$this->_em->flush();
29+
$this->getEntityManager()->flush();
3530
}
3631
}
3732

38-
/**
39-
* @throws ORMException
40-
* @throws OptimisticLockException
41-
*/
4233
public function remove(UserXml $entity, bool $flush = false): void
4334
{
44-
$this->_em->remove($entity);
35+
$this->getEntityManager()->remove($entity);
36+
4537
if ($flush) {
46-
$this->_em->flush();
38+
$this->getEntityManager()->flush();
4739
}
4840
}
4941

tests/Doctrine/fixtures/expected_xml/src/Repository/XOtherRepository.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Repository;
44

55
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
6-
use Doctrine\ORM\Exception\ORMException;
7-
use Doctrine\ORM\OptimisticLockException;
86
use Doctrine\Persistence\ManagerRegistry;
97
use Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity\XOther;
108

@@ -23,27 +21,21 @@ public function __construct(ManagerRegistry $registry)
2321
parent::__construct($registry, XOther::class);
2422
}
2523

26-
/**
27-
* @throws ORMException
28-
* @throws OptimisticLockException
29-
*/
3024
public function add(XOther $entity, bool $flush = false): void
3125
{
32-
$this->_em->persist($entity);
26+
$this->getEntityManager()->persist($entity);
27+
3328
if ($flush) {
34-
$this->_em->flush();
29+
$this->getEntityManager()->flush();
3530
}
3631
}
3732

38-
/**
39-
* @throws ORMException
40-
* @throws OptimisticLockException
41-
*/
4233
public function remove(XOther $entity, bool $flush = false): void
4334
{
44-
$this->_em->remove($entity);
35+
$this->getEntityManager()->remove($entity);
36+
4537
if ($flush) {
46-
$this->_em->flush();
38+
$this->getEntityManager()->flush();
4739
}
4840
}
4941

0 commit comments

Comments
 (0)