-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHtmlPurifierServiceProvider.php
48 lines (37 loc) · 1.15 KB
/
HtmlPurifierServiceProvider.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
<?php
declare(strict_types=1);
namespace Vdlp\HtmlPurifier;
use HTMLPurifier;
use HTMLPurifier_Config;
use October\Rain\Config\Repository;
use October\Rain\Support\ServiceProvider;
class HtmlPurifierServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->publishes([
$this->getConfigPath() => $this->getConfigPublishPath(),
], 'config');
}
public function register(): void
{
$this->mergeConfigFrom($this->getConfigPath(), 'htmlpurifier');
$this->app->singleton(HTMLPurifier::class, static function ($app) {
/** @var Repository $repository */
$repository = $app['config'];
$config = HTMLPurifier_Config::create($repository->get('htmlpurifier'));
return new HTMLPurifier($config);
});
}
private function getConfigPublishPath(): string
{
if (function_exists('config_path')) {
return config_path('htmlpurifier.php');
}
return base_path('config/htmlpurifier.php');
}
private function getConfigPath(): string
{
return __DIR__ . '/config/htmlpurifier.php';
}
}