forked from peteraba/devmonk-htmlpurifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
110 lines (97 loc) · 3.04 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
<?php
/**
* MQHtmlPurifier
* Copyright (c) 2014 Milq Media.
*
* @author Johan Kuijt <johan@milq.nl>
* @copyright 2014 Milq Media.
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @link http://milq.nl
*/
namespace MQHtmlPurifier;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Loader\AutoloaderFactory;
use Zend\Loader\StandardAutoloader;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ViewHelperProviderInterface;
use MQHtmlpurifier\View\Helper\Purify;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
class Module implements
AutoloaderProviderInterface,
ConfigProviderInterface,
BootstrapListenerInterface,
ViewHelperProviderInterface,
ServiceProviderInterface
{
const SERVICE_NAME = 'purifier';
const CONFIG_KEY_HTMLPURIFIER = 'mqhtmlpurifier';
const CONFIG_KEY_CONFIG = 'config';
const HTMLPURIFIER_PREFIX = 'HTMLPURIFIER_PREFIX';
/**
* {@inheritDoc}
*/
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
AutoloaderFactory::STANDARD_AUTOLOADER => array(
StandardAutoloader::LOAD_NS => array(
'HTMLPurifier' => __DIR__ . '/src/HTMLPurifier/library/HTMLPurifier',
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public static function setConstants()
{
if (!defined(self::HTMLPURIFIER_PREFIX)) {
define(self::HTMLPURIFIER_PREFIX, __DIR__ . '/src/HTMLPurifier/library');
}
}
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $e)
{
self::setConstants();
$app = $e->getApplication();
$config = $app->getServiceManager()->get('Config');
$purifierConfig = \HTMLPurifier_Config::createDefault();
if (!empty($config[self::CONFIG_KEY_HTMLPURIFIER][self::CONFIG_KEY_CONFIG])) {
foreach ($config[self::CONFIG_KEY_HTMLPURIFIER][self::CONFIG_KEY_CONFIG] as $configKey => $configValue) {
$purifierConfig->set($configKey, $configValue);
}
}
$purifier = new \HTMLPurifier($purifierConfig);
$app->getServiceManager()->setService(self::SERVICE_NAME, $purifier);
}
/**
* {@inheritDoc}
*/
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
/**
* {@inheritDoc}
*/
public function getViewHelperConfig()
{
return array(
'factories' => array(
'purify' => 'MQHtmlpurifier\Controller\Plugin\Purify',
),
);
}
/**
* {@inheritDoc}
*/
public function getServiceConfig()
{
return array();
}
}