Module::getAutoloaderConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 4
c 2
b 1
f 0
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace ZfPhinx;
4
5
use Zend\Console\Adapter\AdapterInterface as Console;
6
use Zend\Console\Adapter\AdapterInterface;
7
use Zend\EventManager\EventManagerInterface;
8
use Zend\Loader\StandardAutoloader;
9
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
10
use Zend\ModuleManager\Feature\ConfigProviderInterface;
11
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface;
12
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
13
use Zend\Mvc\Console\ResponseSender\ConsoleResponseSender;
14
use Zend\Mvc\MvcEvent;
15
use Zend\Mvc\ResponseSender\SendResponseEvent;
16
use Zend\Mvc\SendResponseListener;
17
18
/**
19
 * Module class
20
 */
21
class Module implements
22
    AutoloaderProviderInterface,
23
    ConfigProviderInterface,
24
    ConsoleUsageProviderInterface,
25
    ConsoleBannerProviderInterface
26
{
27
    const MODULE_NAME    = 'ZfPhinx';
28
    const MODULE_VERSION = '0.2.0';
29
30
    /**
31
     * Init event manager
32
     *
33
     * @param  MvcEvent $event
34
     * @return void
35
     */
36
    public function onBootstrap(MvcEvent $event)
37
    {
38
        $eventManager = $event->getApplication()->getServiceManager()->get(SendResponseListener::class)->getEventManager();
39
        /** @var EventManagerInterface $eventManager */
40
        $eventManager->attach(SendResponseEvent::EVENT_SEND_RESPONSE, new ConsoleResponseSender(), -2000);
41
    }
42
43
    /**
44
     * Returns configuration to merge with application configuration
45
     *
46
     * @return array|\Traversable
47
     */
48
    public function getConfig()
49
    {
50
        return include __DIR__ . '/../../config/module.config.php';
51
    }
52
53
    /**
54
     * Return an array for passing to Zend\Loader\AutoloaderFactory.
55
     *
56
     * @return array
57
     */
58
    public function getAutoloaderConfig()
59
    {
60
        return [
61
            StandardAutoloader::class => [
62
                'namespaces' => [
63
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
64
                ],
65
            ],
66
        ];
67
    }
68
69
    /**
70
     * Returns an array or a string containing usage information for this module's Console commands.
71
     *
72
     * @param  AdapterInterface  $console
73
     * @return array|string|null
74
     */
75
    public function getConsoleUsage(Console $console)
76
    {
77
        return [
78
            'Common command flags',
79
            ['-q', 'Do not output any message'],
80
            ['-n', 'Do not ask any interactive question'],
81
            ['-v|vv|vvv', 'Verbosity of messages: normal|more verbose|debug'],
82
            'Commands',
83
            'zfphinx create [--template TEMPLATE] [--class CLASS] MIGRATION' => 'Create a new migration',
84
            ['--template TEMPLATE', 'Use an alternative template'],
85
            ['--class CLASS', 'Use a class implementing "Phinx\Migration\CreationInterface" to generate the template'],
86
            ['MIGRATION', 'Unique migration name'],
87
            'zfphinx migrate [--target TARGET] [--date DATE] [--environment ENVIRONMENT]' => 'Migrate the database',
88
            ['--target TARGET', 'The version number to migrate to. Format: YYYYMMDDHHMMSS'],
89
            ['--date DATE', 'The date to migrate to. Format: YYYYMMDD'],
90
            ['--environment ENVIRONMENT', 'The target environment'],
91
            'zfphinx rollback [--target TARGET] [--date DATE] [--environment ENVIRONMENT]' => 'Rollback the last or to a specific migration',
92
            ['--target TARGET', 'The version number to rollback to. Format: YYYYMMDDHHMMSS'],
93
            ['--date DATE', 'The date to rollback to. Format: YYYYMMDD'],
94
            ['--environment ENVIRONMENT', 'The target environment'],
95
            'zfphinx status [--format FORMAT] [--environment ENVIRONMENT]' => 'Show migration status',
96
            ['--format FORMAT', 'The output format: text or json. Defaults to text'],
97
            ['--environment ENVIRONMENT', 'The target environment'],
98
            'zfphinx test [--environment ENVIRONMENT]' => 'Verify the configuration file',
99
            ['--environment ENVIRONMENT', 'The target environment'],
100
        ];
101
    }
102
103
    /**
104
     * Returns a string containing a banner text, that describes the module and/or the application.
105
     *
106
     * @param  AdapterInterface $console
107
     * @return string|null
108
     */
109
    public function getConsoleBanner(Console $console)
110
    {
111
        return self::MODULE_NAME . ' ' . self::MODULE_VERSION;
112
    }
113
}
114