1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ConsoleTools; |
4
|
|
|
|
5
|
|
|
use Zend\Mvc\ModuleRouteListener; |
6
|
|
|
use Zend\Mvc\MvcEvent; |
7
|
|
|
use Zend\Console\Adapter\AdapterInterface as Console; |
8
|
|
|
use Zend\ModuleManager\Feature\AutoloaderProviderInterface; |
9
|
|
|
use Zend\ModuleManager\Feature\ConfigProviderInterface; |
10
|
|
|
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* |
14
|
|
|
* @author V.Leontiev <[email protected]> |
15
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
16
|
|
|
* @since php 5.6 or higher |
17
|
|
|
* @see https://github.com/newage/console-tools |
18
|
|
|
*/ |
19
|
|
|
class Module implements |
20
|
|
|
AutoloaderProviderInterface, |
21
|
|
|
ConfigProviderInterface, |
22
|
|
|
ConsoleUsageProviderInterface |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
protected $config = null; |
26
|
|
|
|
27
|
|
|
public function onBootstrap(MvcEvent $e) |
28
|
|
|
{ |
29
|
|
|
$this->config = $e->getApplication()->getServiceManager()->get('config'); |
30
|
|
|
$eventManager = $e->getApplication()->getEventManager(); |
31
|
|
|
$moduleRouteListener = new ModuleRouteListener(); |
32
|
|
|
$moduleRouteListener->attach($eventManager); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Create documentation for console usage that module |
37
|
|
|
* |
38
|
|
|
*/ |
39
|
|
|
public function getConsoleUsage(Console $console) |
40
|
|
|
{ |
41
|
|
|
$docs = array(); |
42
|
|
|
|
43
|
|
|
if ($this->config['console-tools']['enable']['schema']) { |
44
|
|
|
$docs = array_merge($docs, array( |
45
|
|
|
'Schema:', |
46
|
|
|
'schema clean [<dump>]' => 'Clean current schema and apply dump file \'clean.sql\'', |
47
|
|
|
array('<dump>' , 'Name of sql file for apply from folder ./config/sql'), |
48
|
|
|
)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($this->config['console-tools']['enable']['migrations']) { |
52
|
|
|
$docs = array_merge($docs, array( |
53
|
|
|
'Migrations:', |
54
|
|
|
'migration create [<short_name>]' => 'Create new migration on format "YmdHis" with short name if needed', |
55
|
|
|
'migration migrate [<migration>] [--percona] [--port=<port>]' => |
56
|
|
|
'Execute a migration to a specified version or the latest available version.', |
57
|
|
|
'migration execute <migration> --up|--down [--percona] [--port=<port>]' => |
58
|
|
|
'Execute a single migration version up or down manually.', |
59
|
|
|
'migration last --show' => 'Show last applied migration number', |
60
|
|
|
array('<migration>' , 'Number of migration'), |
61
|
|
|
array('--up' , 'Execute action up of one migration'), |
62
|
|
|
array('--down' , 'Execute action down of one migration'), |
63
|
|
|
array('--show' , 'Show sql code for last migration'), |
64
|
|
|
array('--percona' , 'Executing ALTER TABLE use percona tool'), |
65
|
|
|
array('<port>' , 'Executing ALTER TABLE use percona tool on specific port'), |
66
|
|
|
)); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($this->config['console-tools']['enable']['fixtures']) { |
70
|
|
|
$docs = array_merge($docs, array( |
71
|
|
|
'Fixtures:', |
72
|
|
|
'fixture apply [<fixture>]' => 'Apply all/name fixture', |
73
|
|
|
array('<fixture>' , 'Apply only there fixture'), |
74
|
|
|
)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $docs; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getConfig() |
81
|
|
|
{ |
82
|
|
|
$config = include __DIR__ . '/../../config/module.config.php'; |
83
|
|
|
|
84
|
|
|
/* Remove schema routes */ |
85
|
|
|
if ($this->config['console-tools']['enable']['schema'] === false) { |
86
|
|
|
unset($config['console']['router']['routes']['schema-clean']); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/* Remove migrations routes */ |
90
|
|
|
if ($this->config['console-tools']['enable']['migrations'] === false) { |
91
|
|
|
unset($config['console']['router']['routes']['migration-create']); |
92
|
|
|
unset($config['console']['router']['routes']['migration-upgrade']); |
93
|
|
|
unset($config['console']['router']['routes']['migration-execute']); |
94
|
|
|
unset($config['console']['router']['routes']['migration-last']); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/* Remove fixtures routes */ |
98
|
|
|
if ($this->config['console-tools']['enable']['fixtures'] === false) { |
99
|
|
|
unset($config['console']['router']['routes']['fixture-apply']); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $config; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function getAutoloaderConfig() |
106
|
|
|
{ |
107
|
|
|
return array( |
108
|
|
|
'Zend\Loader\StandardAutoloader' => array( |
109
|
|
|
'namespaces' => array( |
110
|
|
|
__NAMESPACE__ => __DIR__, |
111
|
|
|
), |
112
|
|
|
), |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|