forked from zpetr/apigility-htmlnegotiation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
87 lines (77 loc) · 2.3 KB
/
Copy pathModule.php
File metadata and controls
87 lines (77 loc) · 2.3 KB
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
<?php
namespace hola\HtmlNegotiation;
use Zend\Mvc\MvcEvent;
class Module
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/',
),
),
);
}
/**
* Retrieve Service Manager configuration
*
* Defines HtmlNegotiation\HtmlStrategy service factory.
*
* @return array
*/
public function getServiceConfig()
{
return array('factories' => array(
'hola\HtmlNegotiation\HtmlRenderer' => function ($services) {
$helpers = $services->get('ViewHelperManager');
$apiProblemRenderer = $services->get('ZF\ApiProblem\ApiProblemRenderer');
$config = $services->get('Config');
$renderer = new View\HtmlRenderer($apiProblemRenderer,$config);
$renderer->setHelperPluginManager($helpers);
return $renderer;
},
'hola\HtmlNegotiation\HtmlStrategy' => function ($services) {
$renderer = $services->get('hola\HtmlNegotiation\HtmlRenderer');
return new View\HtmlStrategy($renderer);
},
));
}
/**
* Listener for bootstrap event
*
* Attaches a render event.
*
* @param \Zend\Mvc\MvcEvent $e
*/
public function onBootstrap($e)
{
$app = $e->getTarget();
$services = $app->getServiceManager();
$events = $app->getEventManager();
$events->attach(MvcEvent::EVENT_RENDER, array($this, 'onRender'), 190);
}
/**
* Listener for the render event
*
* Attaches a rendering/response strategy to the View.
*
* @param \Zend\Mvc\MvcEvent $e
*/
public function onRender($e)
{
$result = $e->getResult();
if (!$result instanceof View\HtmlModel) {
return;
}
$app = $e->getTarget();
$services = $app->getServiceManager();
$view = $services->get('View');
$events = $view->getEventManager();
$events->attach($services->get('hola\HtmlNegotiation\HtmlStrategy'), 190);
}
}