|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Abacaphiliac\DoctrineORMDiagnosticsModule; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Application; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Zend\EventManager\EventInterface; |
|
8
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
|
9
|
|
|
use Zend\ModuleManager\Feature\DependencyIndicatorInterface; |
|
10
|
|
|
use Zend\ModuleManager\Feature\InitProviderInterface; |
|
11
|
|
|
use Zend\ModuleManager\ModuleManagerInterface; |
|
12
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
13
|
|
|
|
|
14
|
|
|
class Module implements ConfigProviderInterface, DependencyIndicatorInterface, InitProviderInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Returns configuration to merge with application configuration |
|
18
|
|
|
* |
|
19
|
|
|
* @return array|\Traversable |
|
20
|
|
|
*/ |
|
21
|
3 |
|
public function getConfig() |
|
22
|
|
|
{ |
|
23
|
3 |
|
return require dirname(dirname(__DIR__)) . '/config/module.config.php'; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Expected to return an array of modules on which the current one depends on |
|
28
|
|
|
* |
|
29
|
|
|
* @return array |
|
30
|
|
|
*/ |
|
31
|
3 |
|
public function getModuleDependencies() |
|
32
|
|
|
{ |
|
33
|
|
|
return [ |
|
34
|
3 |
|
'DoctrineModule', |
|
35
|
3 |
|
'DoctrineORMModule', |
|
36
|
3 |
|
'ZFTool', |
|
37
|
3 |
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param ModuleManagerInterface $manager |
|
42
|
|
|
*/ |
|
43
|
2 |
|
public function init(ModuleManagerInterface $manager) |
|
44
|
|
|
{ |
|
45
|
2 |
|
$events = $manager->getEventManager(); |
|
46
|
2 |
|
$sharedEventManager = $events->getSharedManager(); |
|
47
|
2 |
|
$sharedEventManager->attach('doctrine', 'loadCli.post', [$this, 'initializeConsole']); |
|
48
|
2 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Initialize the console with additional commands from (optionally) doctrine\migrations |
|
52
|
|
|
* @param EventInterface $event |
|
53
|
|
|
* @return bool |
|
54
|
|
|
* @throws \Zend\ServiceManager\Exception\ServiceNotFoundException |
|
55
|
|
|
*/ |
|
56
|
5 |
|
public function initializeConsole(EventInterface $event) |
|
57
|
|
|
{ |
|
58
|
5 |
|
$cli = $event->getTarget(); |
|
59
|
5 |
|
if (!$cli instanceof Application) { |
|
60
|
1 |
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
$serviceLocator = $event->getParam('ServiceManager'); |
|
64
|
4 |
|
if (!$serviceLocator instanceof ServiceLocatorInterface) { |
|
65
|
1 |
|
return false; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
3 |
|
if (class_exists('Doctrine\DBAL\Migrations\Tools\Console\Command\UpToDateCommand')) { |
|
69
|
|
|
/** @var Command $upToDateCommand */ |
|
70
|
3 |
|
$upToDateCommand = $serviceLocator->get('doctrine.migrations_cmd.uptodate'); |
|
71
|
|
|
|
|
72
|
3 |
|
$cli->addCommands([ |
|
73
|
3 |
|
$upToDateCommand, |
|
74
|
3 |
|
]); |
|
75
|
3 |
|
} |
|
76
|
|
|
|
|
77
|
3 |
|
return true; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|