Skip to content

Commit

Permalink
bug #1114 [make:entity] _em will be private in ORM 3.0, use getEntity…
Browse files Browse the repository at this point in the history
…Manager() (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
  • Loading branch information
weaverryan committed May 9, 2022
2 parents 5f7249c + 9a1d609 commit 8011758
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 46 deletions.
4 changes: 0 additions & 4 deletions src/Doctrine/EntityClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

use ApiPlatform\Metadata\ApiResource;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\Mapping;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\Str;
Expand Down Expand Up @@ -108,8 +106,6 @@ public function generateRepositoryClass(string $repositoryClass, string $entityC
$entityClass,
ManagerRegistry::class,
ServiceEntityRepository::class,
OptimisticLockException::class,
ORMException::class,
]);

if ($withPasswordUpgrade) {
Expand Down
22 changes: 8 additions & 14 deletions src/Resources/skeleton/doctrine/Repository.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,21 @@ public function __construct(ManagerRegistry $registry)
parent::__construct($registry, <?= $entity_class_name; ?>::class);
}

/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(<?= $entity_class_name ?> $entity, bool $flush = false): void
{
$this->_em->persist($entity);
$this->getEntityManager()->persist($entity);

if ($flush) {
$this->_em->flush();
$this->getEntityManager()->flush();
}
}

/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(<?= $entity_class_name ?> $entity, bool $flush = false): void
{
$this->_em->remove($entity);
$this->getEntityManager()->remove($entity);

if ($flush) {
$this->_em->flush();
$this->getEntityManager()->flush();
}
}
<?php if ($include_example_comments): // When adding a new method without existing default comments, the blank line is automatically added.?>
Expand All @@ -56,8 +50,8 @@ public function upgradePassword(<?= sprintf('%s ', $password_upgrade_user_interf
}

$user->setPassword($newHashedPassword);
$this->_em->persist($user);
$this->_em->flush();

$this->add($user, true);
}

<?php endif ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Repository;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity\UserXml;

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

/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(UserXml $entity, bool $flush = false): void
{
$this->_em->persist($entity);
$this->getEntityManager()->persist($entity);

if ($flush) {
$this->_em->flush();
$this->getEntityManager()->flush();
}
}

/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(UserXml $entity, bool $flush = false): void
{
$this->_em->remove($entity);
$this->getEntityManager()->remove($entity);

if ($flush) {
$this->_em->flush();
$this->getEntityManager()->flush();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Repository;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\Exception\ORMException;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\MakerBundle\Tests\tmp\current_project_xml\src\Entity\XOther;

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

/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function add(XOther $entity, bool $flush = false): void
{
$this->_em->persist($entity);
$this->getEntityManager()->persist($entity);

if ($flush) {
$this->_em->flush();
$this->getEntityManager()->flush();
}
}

/**
* @throws ORMException
* @throws OptimisticLockException
*/
public function remove(XOther $entity, bool $flush = false): void
{
$this->_em->remove($entity);
$this->getEntityManager()->remove($entity);

if ($flush) {
$this->_em->flush();
$this->getEntityManager()->flush();
}
}

Expand Down

0 comments on commit 8011758

Please sign in to comment.