-
Notifications
You must be signed in to change notification settings - Fork 3
/
Module.php
29 lines (25 loc) · 1.02 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
<?php
namespace HdRouteLayouts;
class Module
{
public function onBootstrap($e)
{
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$routeName = $e->getRouteMatch()->getMatchedRouteName();
$config = $e->getApplication()->getServiceManager()->get('config');
$layoutConfig = $config['route_layouts'];
if (isset($layoutConfig[$routeName])) {
$controller->layout($layoutConfig[$routeName]);
} else {
$rules = array_keys($layoutConfig);
foreach ($rules as $routeRule) {
if (fnmatch($routeRule, $routeName, FNM_CASEFOLD)) {
$controller->layout($layoutConfig[$routeRule]);
break;
}
}
}
}, 100);
}
}