forked from NikolayMurha/SmartyModule
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathModule.php
84 lines (67 loc) · 2.46 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
<?php
namespace SmartyModule;
use Zend\ModuleManager\ModuleManager as Manager,
Zend\EventManager\StaticEventManager,
Zend\View\HelperPluginManager,
Zend\Form\View\HelperConfig,
Zend\Mvc\Router\SimpleRouteStack;
class Module
{
public function onBootstrap($e) {
$this->initializeView($e);
$this->setupView($e);
}
public function initializeView($e)
{
$app = $e->getParam('application');
$request = $app->getRequest();
// support cli requests which do not have a base path
if (method_exists($request, 'getBasePath')) {
$basePath = $app->getRequest()->getBasePath();
}
$serviceManager = $app->getServiceManager();
$view = $serviceManager->get('Zend\View\View');
$strategy = $serviceManager->get('SmartyModule\View\Strategy\SmartyStrategy');
$renderer = $strategy->getRenderer();
$resolver = $serviceManager->get('viewresolver');
$renderer->setResolver($resolver);
$smarty = $renderer->getEngine();
$config = $serviceManager->get('Config');
foreach ($config['smarty'] as $key=>$value) {
if (isset($smarty->$key))
$smarty->$key = $value;
}
$renderer->setHelperPluginManager(new HelperPluginManager(new HelperConfig()));
$renderer->plugin('url')->setRouter(SimpleRouteStack::factory($config['router']['routes']));
if (isset($basePath)) {
$renderer->plugin('basePath')->setBasePath($basePath);
}
}
public function setupView($e)
{
// Register a render event
$application = $e->getParam('application');
$serviceManager = $application->getServiceManager();
$view = $serviceManager->get('Zend\View\View');
$smartyRendererStrategy = $serviceManager->get('SmartyModule\View\Strategy\SmartyStrategy');
$view->addRenderingStrategy(array($smartyRendererStrategy, 'selectRenderer'), 100);
$view->addResponseStrategy(array($smartyRendererStrategy, 'injectResponse'), 100);
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}