|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Reddogs (https://github.com/reddogs-at) |
|
4
|
|
|
* |
|
5
|
|
|
* @see https://github.com/reddogs-at/reddogs-doctrine-migrations for the canonical source repository |
|
6
|
|
|
* @license https://github.com/reddogs-at/reddogs-doctrine-migrations/blob/master/LICENSE MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Reddogs\Doctrine\Migrations; |
|
9
|
|
|
|
|
10
|
|
|
use Zend\ServiceManager\Factory\FactoryInterface; |
|
11
|
|
|
use Interop\Container\ContainerInterface; |
|
12
|
|
|
use Symfony\Component\Console\Application; |
|
13
|
|
|
use Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand as AbstractMigrationsCommand; |
|
14
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration; |
|
15
|
|
|
use Doctrine\ORM\EntityManager; |
|
16
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
17
|
|
|
|
|
18
|
|
|
class CommandFactory implements FactoryInterface |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Get command |
|
23
|
|
|
* |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
* |
|
26
|
|
|
* @see \Zend\ServiceManager\Factory\FactoryInterface::__invoke() |
|
27
|
|
|
* @return AbstractCommand |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
30
|
|
|
{ |
|
31
|
|
|
$config = $container->get('config'); |
|
32
|
|
|
return new $requestedName( |
|
33
|
|
|
new Application(), |
|
34
|
|
|
$this->getMigrationsCommand($requestedName), |
|
35
|
|
|
new Configuration($container->get(EntityManager::class)->getConnection()), |
|
36
|
|
|
new ConsoleOutput(), |
|
37
|
|
|
$config['doctrine']['reddogs_doctrine_migrations'] |
|
38
|
|
|
); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get migrations command |
|
43
|
|
|
* |
|
44
|
|
|
* @param string $requestedName |
|
45
|
|
|
* @return AbstractMigrationsCommand |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getMigrationsCommand($requestedName) |
|
48
|
|
|
{ |
|
49
|
|
|
$parts = explode('\\', $requestedName); |
|
50
|
|
|
$class = 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\' . array_pop($parts); |
|
51
|
|
|
return new $class(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
} |