Permalink
Browse files

SymfonyBundle: add support for referencing services from php_params

  • Loading branch information...
JanTvrdik committed Oct 26, 2017
1 parent 36fd4b7 commit c9ccce41652196ad06dceb67c2a270d6d783b2c6
@@ -38,6 +38,10 @@ public function getConfigTreeBuilder()
->booleanNode('with_dummy_data')
->defaultFalse()
->end()
->arrayNode('php_params')
->variablePrototype()
->end()
->end()
->scalarNode('ignored_queries_file')
->defaultNull()
->end()
@@ -45,6 +45,11 @@ public function load(array $configs, ContainerBuilder $container)
$driverDefinition = new Definition($this->drivers[$driverAlias]);
$driverDefinition->setAutowired(TRUE);
$container->addDefinitions([
'nextras_migrations.dbal' => $dbalDefinition,
'nextras_migrations.driver' => $driverDefinition,
]);
if ($config['diff_generator'] === 'doctrine') {
$structureDiffGeneratorDefinition = new Definition('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator');
$structureDiffGeneratorDefinition->setAutowired(TRUE);
@@ -54,8 +59,15 @@ public function load(array $configs, ContainerBuilder $container)
$structureDiffGeneratorDefinition = NULL;
}
foreach ($config['php_params'] as $phpParamKey => $phpParamValue) {
if (is_string($phpParamValue) && strlen($phpParamValue) > 1 && $phpParamValue[0] === '@') {
$serviceName = substr($phpParamValue, 1);
$config['php_params'][$phpParamKey] = $container->getDefinition($serviceName);
}
}
$configurationDefinition = new Definition('Nextras\Migrations\Configurations\DefaultConfiguration');
$configurationDefinition->setArguments([$config['dir'], $driverDefinition, $config['with_dummy_data']]);
$configurationDefinition->setArguments([$config['dir'], $driverDefinition, $config['with_dummy_data'], $config['php_params']]);
$configurationDefinition->addMethodCall('setStructureDiffGenerator', [$structureDiffGeneratorDefinition]);
$continueCommandDefinition = new Definition('Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand');
@@ -71,8 +83,6 @@ public function load(array $configs, ContainerBuilder $container)
$resetCommandDefinition->addTag('console.command');
$container->addDefinitions([
'nextras_migrations.dbal' => $dbalDefinition,
'nextras_migrations.driver' => $driverDefinition,
'nextras_migrations.configuration' => $configurationDefinition,
'nextras_migrations.continue_command' => $continueCommandDefinition,
'nextras_migrations.create_command' => $createCommandDefinition,

0 comments on commit c9ccce4

Please sign in to comment.