-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plugin.php
52 lines (45 loc) · 1.34 KB
/
Plugin.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
<?php
declare(strict_types=1);
namespace Vdlp\Csrf;
use Cms\Classes\CmsController;
use System\Classes\PluginBase;
use Throwable;
use Vdlp\Csrf\Middleware\VerifyCsrfTokenMiddleware;
use Vdlp\Csrf\ServiceProviders\CsrfServiceProvider;
final class Plugin extends PluginBase
{
public function pluginDetails(): array
{
return [
'name' => 'vdlp.csrf::lang.plugin.name',
'description' => 'vdlp.csrf::lang.plugin.description',
'author' => 'Van der Let & Partners <octobercms@vdlp.nl>',
'icon' => 'icon-link',
'homepage' => 'https://octobercms.com/plugin/vdlp-csrf',
];
}
public function boot(): void
{
CmsController::extend(static function (CmsController $controller): void {
$controller->middleware(VerifyCsrfTokenMiddleware::class);
});
}
public function register(): void
{
$this->app->register(CsrfServiceProvider::class);
}
public function registerMarkupTags(): array
{
return [
'functions' => [
'csrf_token' => static function (): ?string {
try {
return csrf_token();
} catch (Throwable $exception) {
return null;
}
},
],
];
}
}