1 | <?php |
||
19 | class MigrationsConfigurationFactory extends AbstractFactory |
||
20 | { |
||
21 | /** |
||
22 | * {@inheritDoc} |
||
23 | * |
||
24 | * @return Configuration |
||
25 | */ |
||
26 | 18 | public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
27 | { |
||
28 | 18 | $name = $this->getName(); |
|
|
|||
29 | /* @var $connection \Doctrine\DBAL\Connection */ |
||
30 | 18 | $connection = $container->get('doctrine.connection.' . $name); |
|
31 | 18 | $appConfig = $container->get('config'); |
|
32 | 18 | $migrationsConfig = $appConfig['doctrine']['migrations_configuration'][$name]; |
|
33 | |||
34 | 18 | $configuration = new Configuration($connection); |
|
35 | |||
36 | 18 | $output = new ConsoleOutput(); |
|
37 | $writerCallback = static function ($message) use ($output) { |
||
38 | $output->writeln($message); |
||
39 | 18 | }; |
|
40 | |||
41 | 18 | $outputWriter = $configuration->getOutputWriter(); |
|
42 | 18 | if (method_exists($outputWriter, 'setCallback')) { |
|
43 | 18 | $outputWriter->setCallback($writerCallback); |
|
44 | } else { |
||
45 | // Fallback for doctrine-migrations v1.x |
||
46 | $configuration->setOutputWriter(new OutputWriter($writerCallback)); |
||
47 | } |
||
48 | |||
49 | 18 | $configuration->setName($migrationsConfig['name']); |
|
50 | 18 | $configuration->setMigrationsDirectory($migrationsConfig['directory']); |
|
51 | 18 | $configuration->setMigrationsNamespace($migrationsConfig['namespace']); |
|
52 | 18 | $configuration->setMigrationsTableName($migrationsConfig['table']); |
|
53 | 18 | $configuration->registerMigrationsFromDirectory($migrationsConfig['directory']); |
|
54 | |||
55 | 18 | if (method_exists($configuration, 'setMigrationsColumnName')) { |
|
56 | 18 | $configuration->setMigrationsColumnName($migrationsConfig['column']); |
|
57 | } |
||
58 | |||
59 | 18 | if (isset($migrationsConfig['custom_template']) && method_exists($configuration, 'setCustomTemplate')) { |
|
60 | $configuration->setCustomTemplate($migrationsConfig['custom_template']); |
||
61 | } |
||
62 | |||
63 | 18 | return $configuration; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * {@inheritDoc} |
||
68 | * |
||
69 | * @return Configuration |
||
70 | */ |
||
71 | 18 | public function createService(ServiceLocatorInterface $container) |
|
75 | |||
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | */ |
||
79 | public function getOptionsClass() |
||
82 | } |
||
83 |