Skip to content

Commit 97f9fd4

Browse files
Update index.rst: Fixing Custom Purger code sample
Page: https://symfony.com/bundles/DoctrineFixturesBundle/current/index.html#specifying-purging-behavior Wasn't working for me, I was getting: > In ORMExecutorCommon.php line 23: Doctrine\Common\DataFixtures\Executor\ORMExecutor::__construct(): Argument #2 ($purger) must be of type ?Doctrine\Common\DataFixtures\Purger\ORMPurgerInterface, App\DataFixtures\CustomPurger given,
1 parent 954aa87 commit 97f9fd4

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

docs/index.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,19 @@ You can also customize purging behavior significantly more and implement a custo
299299
// src/Purger/CustomPurger.php
300300
namespace App\Purger;
301301

302-
use Doctrine\Common\DataFixtures\Purger\PurgerInterface;
302+
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
303+
use Doctrine\Common\DataFixtures\Purger\ORMPurgerInterface;
304+
use Doctrine\ORM\EntityManagerInterface;
303305

304-
// ...
305-
class CustomPurger implements PurgerInterface
306+
class CustomPurger implements ORMPurgerInterface
306307
{
308+
private EntityManagerInterface $entityManager;
309+
310+
public function setEntityManager(EntityManagerInterface $em): void
311+
{
312+
$this->entityManager = $em;
313+
}
314+
307315
public function purge(): void
308316
{
309317
// ...
@@ -319,7 +327,7 @@ You can also customize purging behavior significantly more and implement a custo
319327
{
320328
public function createForEntityManager(?string $emName, EntityManagerInterface $em, array $excluded = [], bool $purgeWithTruncate = false) : PurgerInterface
321329
{
322-
return new CustomPurger($em);
330+
return new CustomPurger();
323331
}
324332
}
325333

0 commit comments

Comments
 (0)