Last active
November 10, 2020 07:59
-
-
Save mbabker/ef79d1cbd9a3b238eba1c7306be72562 to your computer and use it in GitHub Desktop.
Compiler pass which removes migration paths added by SyliusCoreBundle and SyliusAdminApiBundle (or other third party packages), useful if you are manually managing all migrations within your Sylius application
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
<?php declare(strict_types=1); | |
namespace App\DependencyInjection\Compiler; | |
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
final class RemoveSyliusMigrationsPass implements CompilerPassInterface | |
{ | |
public function process(ContainerBuilder $container) | |
{ | |
if ($container->hasDefinition('doctrine.migrations.configuration')) { | |
$definition = $container->getDefinition('doctrine.migrations.configuration'); | |
$calls = $definition->getMethodCalls(); | |
$sanitizedCalls = []; | |
/* | |
* Key 0 is the method name, key 1 is the arguments, and if defined key 2 is a flag indicating whether a clone should be returned | |
* Inside the arguments array for `addMigrationsDirectory` calls, key 0 is the namespace and key 1 is the path | |
*/ | |
foreach ($calls as $call) { | |
if ($call[0] !== 'addMigrationsDirectory') { | |
$sanitizedCalls[] = $call; | |
continue; | |
} | |
if ($call[1][0] === 'DoctrineMigrations') { | |
$sanitizedCalls[] = $call; | |
} | |
} | |
$definition->setMethodCalls($sanitizedCalls); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment