-
Notifications
You must be signed in to change notification settings - Fork 2
/
Module.php
92 lines (78 loc) · 2.82 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
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Wiss;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\ModuleManager\ModuleManager;
use Zend\ModuleManager\Feature\ViewHelperProviderInterface;
class Module implements ViewHelperProviderInterface
{
/**
*
* @param MvcEvent $e
*/
public function onBootstrap(MvcEvent $e)
{
// Get the event manager
$app = $e->getApplication();
$sm = $app->getServiceManager();
$evm = $app->getEventManager();
$config = $app->getConfig();
// Hook in to the route event, where is determined
// which controller/action has to be used
$evm->attach(MvcEvent::EVENT_ROUTE, function($e) use($config) {
// Get the matched route and its name
$route = $e->getRouteMatch();
$originalRoute = clone $route;
$currentRoute = $route->getMatchedRouteName();
// Go to the install page first if there is no valid database connection
// Only go there is the current route is not 'install' already
if($currentRoute != 'wiss/install' && $config['application']['installed'] === false) {
// Change to route before it is dispatched. It now goes to the
// install action.
$route->setParam('controller', 'Wiss\Controller\Index');
$route->setParam('action', 'redirectToInstall');
}
// Check if there are zones used
if($config['application']['use_zones']) {
// Rewrite all incoming uri's to a single entry point
$route->setParam('controller', 'Wiss\Controller\Content');
$route->setParam('action', 'route');
$route->setParam('route', $currentRoute);
$route->setParam('originalRoute', $originalRoute);
}
});
}
public function init(ModuleManager $moduleManager)
{
$moduleManager->loadModule('JqueryUi');
}
public function getViewHelperConfig()
{
return array(
'invokables' => array(
'pageUrl' => 'Wiss\View\Helper\PageUrl',
)
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}