|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of the Nextras community extensions of Nette Framework |
| 5 | + * |
| 6 | + * @license New BSD License |
| 7 | + * @link https://github.com/nextras/migrations |
| 8 | + */ |
| 9 | + |
| 10 | +namespace Nextras\Migrations\Bridges\SymfonyBundle\DependencyInjection; |
| 11 | + |
| 12 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 13 | +use Symfony\Component\DependencyInjection\Definition; |
| 14 | +use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
| 15 | + |
| 16 | + |
| 17 | +class NextrasMigrationsExtension extends Extension |
| 18 | +{ |
| 19 | + /** @var array */ |
| 20 | + protected $dbals = [ |
| 21 | + 'dibi' => 'Nextras\Migrations\Bridges\Dibi\DibiAdapter', |
| 22 | + 'dibi2' => 'Nextras\Migrations\Bridges\Dibi\Dibi2Adapter', |
| 23 | + 'dibi3' => 'Nextras\Migrations\Bridges\Dibi\Dibi3Adapter', |
| 24 | + 'doctrine' => 'Nextras\Migrations\Bridges\DoctrineDbal\DoctrineAdapter', |
| 25 | + 'nette' => 'Nextras\Migrations\Bridges\NetteDatabase\NetteAdapter', |
| 26 | + 'nextras' => 'Nextras\Migrations\Bridges\NextrasDbal\NextrasAdapter', |
| 27 | + ]; |
| 28 | + |
| 29 | + /** @var array */ |
| 30 | + protected $drivers = [ |
| 31 | + 'mysql' => 'Nextras\Migrations\Drivers\MySqlDriver', |
| 32 | + 'pgsql' => 'Nextras\Migrations\Drivers\PgSqlDriver', |
| 33 | + ]; |
| 34 | + |
| 35 | + |
| 36 | + public function load(array $configs, ContainerBuilder $container) |
| 37 | + { |
| 38 | + $config = $this->processConfiguration(new Configuration(), $configs); |
| 39 | + |
| 40 | + $dbalAlias = $config['dbal']; |
| 41 | + $dbalDefinition = new Definition($this->dbals[$dbalAlias]); |
| 42 | + $dbalDefinition->setAutowired(TRUE); |
| 43 | + |
| 44 | + $driverAlias = $config['driver']; |
| 45 | + $driverDefinition = new Definition($this->drivers[$driverAlias]); |
| 46 | + $driverDefinition->setAutowired(TRUE); |
| 47 | + |
| 48 | + if ($config['diff_generator'] === 'doctrine') { |
| 49 | + $structureDiffGeneratorDefinition = new Definition('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator'); |
| 50 | + $structureDiffGeneratorDefinition->setAutowired(TRUE); |
| 51 | + $structureDiffGeneratorDefinition->setArgument('$ignoredQueriesFile', $config['ignored_queries_file']); |
| 52 | + |
| 53 | + } else { |
| 54 | + $structureDiffGeneratorDefinition = NULL; |
| 55 | + } |
| 56 | + |
| 57 | + $configurationDefinition = new Definition('Nextras\Migrations\Configurations\DefaultConfiguration'); |
| 58 | + $configurationDefinition->setArguments([$config['dir'], $driverDefinition, $config['with_dummy_data']]); |
| 59 | + $configurationDefinition->addMethodCall('setStructureDiffGenerator', [$structureDiffGeneratorDefinition]); |
| 60 | + |
| 61 | + $continueCommandDefinition = new Definition('Nextras\Migrations\Bridges\SymfonyConsole\ContinueCommand'); |
| 62 | + $continueCommandDefinition->setAutowired(TRUE); |
| 63 | + $continueCommandDefinition->addTag('console.command'); |
| 64 | + |
| 65 | + $createCommandDefinition = new Definition('Nextras\Migrations\Bridges\SymfonyConsole\CreateCommand'); |
| 66 | + $createCommandDefinition->setAutowired(TRUE); |
| 67 | + $createCommandDefinition->addTag('console.command'); |
| 68 | + |
| 69 | + $resetCommandDefinition = new Definition('Nextras\Migrations\Bridges\SymfonyConsole\ResetCommand'); |
| 70 | + $resetCommandDefinition->setAutowired(TRUE); |
| 71 | + $resetCommandDefinition->addTag('console.command'); |
| 72 | + |
| 73 | + $container->addDefinitions([ |
| 74 | + 'nextras_migrations.dbal' => $dbalDefinition, |
| 75 | + 'nextras_migrations.driver' => $driverDefinition, |
| 76 | + 'nextras_migrations.configuration' => $configurationDefinition, |
| 77 | + 'nextras_migrations.continue_command' => $continueCommandDefinition, |
| 78 | + 'nextras_migrations.create_command' => $createCommandDefinition, |
| 79 | + 'nextras_migrations.reset_command' => $resetCommandDefinition, |
| 80 | + ]); |
| 81 | + |
| 82 | + if ($structureDiffGeneratorDefinition) { |
| 83 | + $container->addDefinitions([ |
| 84 | + 'nextras_migrations.structure_diff_generator' => $structureDiffGeneratorDefinition, |
| 85 | + ]); |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments