-
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from lstrojny/custom-purger
Support for custom purgers
- Loading branch information
Showing
11 changed files
with
503 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
DependencyInjection/CompilerPass/PurgerFactoryCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass; | ||
|
||
use LogicException; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use function sprintf; | ||
|
||
final class PurgerFactoryCompilerPass implements CompilerPassInterface | ||
{ | ||
public const PURGER_FACTORY_TAG = 'doctrine.fixtures.purger_factory'; | ||
|
||
public function process(ContainerBuilder $container) : void | ||
{ | ||
$definition = $container->getDefinition('doctrine.fixtures_load_command'); | ||
$taggedServices = $container->findTaggedServiceIds(self::PURGER_FACTORY_TAG); | ||
|
||
$purgerFactories = []; | ||
foreach ($taggedServices as $serviceId => $tags) { | ||
foreach ($tags as $tagData) { | ||
if (! isset($tagData['alias'])) { | ||
throw new LogicException(sprintf('Proxy factory "%s" must define an alias', $serviceId)); | ||
} | ||
|
||
$purgerFactories[$tagData['alias']] = new Reference($serviceId); | ||
} | ||
} | ||
|
||
$definition->setArgument(2, $purgerFactories); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\Purger; | ||
|
||
use Doctrine\Common\DataFixtures\Purger\ORMPurger; | ||
use Doctrine\Common\DataFixtures\Purger\PurgerInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
final class ORMPurgerFactory implements PurgerFactory | ||
{ | ||
public function createForEntityManager(?string $emName, EntityManagerInterface $em, array $excluded = [], bool $purgeWithTruncate = false) : PurgerInterface | ||
{ | ||
$purger = new ORMPurger($em, $excluded); | ||
$purger->setPurgeMode($purgeWithTruncate ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE); | ||
|
||
return $purger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\Purger; | ||
|
||
use Doctrine\Common\DataFixtures\Purger\PurgerInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
|
||
interface PurgerFactory | ||
{ | ||
public function createForEntityManager(?string $emName, EntityManagerInterface $em, array $excluded = [], bool $purgeWithTruncate = false) : PurgerInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\Tests; | ||
|
||
use Doctrine\Common\Persistence\ManagerRegistry as DeprecatedManagerRegistry; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
use function interface_exists; | ||
|
||
final class DeprecationUtil | ||
{ | ||
public static function getManagerRegistryClass() : string | ||
{ | ||
return interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : DeprecatedManagerRegistry::class; | ||
} | ||
} |
Oops, something went wrong.