-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
144 lines (132 loc) · 3.66 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* MP3 Player
*
* @author Sammie S. Taunton <[email protected]>
* @copyright 2014 Sammie S. Taunton
* @license https://github.com/diemuzi/mp3/blob/master/LICENSE License
* @link https://github.com/diemuzi/mp3 MP3 Player
*/
namespace Mp3;
use Zend\Console\Adapter\AdapterInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface;
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
use Zend\Mvc\MvcEvent;
use Zend\View\Model\ViewModel;
/**
* Class Module
*
* @package Mp3
*/
class Module implements
ConfigProviderInterface,
AutoloaderProviderInterface,
ConsoleBannerProviderInterface,
ConsoleUsageProviderInterface
{
/**
* Boostrap
*
* @param MvcEvent $mvcEvent
*/
public function onBootstrap(MvcEvent $mvcEvent)
{
$eventManager = $mvcEvent->getApplication()
->getEventManager();
/**
* Disable Layout on Error
*/
$eventManager->attach(
MvcEvent::EVENT_DISPATCH_ERROR,
function ($mvcEvent) {
/**
* @var MvcEvent $mvcEvent
*/
$mvcEvent->getResult()
->setTerminal(true);
}
);
$sharedEvents = $eventManager
->getSharedManager();
/**
* Disable Layout in ViewModel
*/
$sharedEvents->attach(
'Zend\Mvc\Controller\AbstractActionController',
'dispatch',
function ($mvcEvent) {
/**
* @var MvcEvent $mvcEvent
*/
$result = $mvcEvent->getResult();
if ($result instanceof ViewModel) {
$result->setTerminal(true);
}
}
);
$mvcEvent->getApplication()
->getEventManager()
->getSharedManager()
->attach(
'Mp3\Controller\SearchController',
'Mp3Help',
function ($event) use
(
$mvcEvent
) {
/**
* @var MvcEvent $event
*/
echo $mvcEvent->getApplication()
->getServiceManager()
->get('Mp3\Service\Search')
->Help($event->getParam('help'));
}
);
}
/**
* {@inheritdoc}
*/
public function getConfig()
{
return include_once __DIR__ . '/config/module.config.php';
}
/**
* {@inheritdoc}
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php'
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__
)
)
);
}
/**
* {@inheritdoc}
*/
public function getConsoleBanner(AdapterInterface $console)
{
return 'MP3 Player Console';
}
/**
* {@inheritdoc}
*/
public function getConsoleUsage(AdapterInterface $console)
{
return array(
array(
'Import Search',
'mp3 import',
'--help'
)
);
}
}