1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BEdita, API-first content management framework |
4
|
|
|
* Copyright 2022 Atlas Srl, Chialab Srl |
5
|
|
|
* |
6
|
|
|
* This file is part of BEdita: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Lesser General Public License as published |
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace BEdita\DevTools; |
15
|
|
|
|
16
|
|
|
use BEdita\DevTools\Middleware\HtmlMiddleware; |
17
|
|
|
use Cake\Core\BasePlugin; |
18
|
|
|
use Cake\Core\Configure; |
19
|
|
|
use Cake\Core\PluginApplicationInterface; |
20
|
|
|
use Cake\Http\MiddlewareQueue; |
21
|
|
|
use Cake\Http\ServerRequest; |
22
|
|
|
use Cake\Routing\Middleware\AssetMiddleware; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Plugin class. |
26
|
|
|
*/ |
27
|
|
|
class Plugin extends BasePlugin |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @inheritDoc |
31
|
|
|
*/ |
32
|
|
|
public function bootstrap(PluginApplicationInterface $app): void |
33
|
|
|
{ |
34
|
|
|
parent::bootstrap($app); |
35
|
|
|
|
36
|
|
|
ServerRequest::addDetector('html', ['accept' => ['text/html', 'application/xhtml+xml', 'application/xhtml', 'text/xhtml']]); |
37
|
|
|
|
38
|
|
|
// Configure DebugKit panels. |
39
|
|
|
$panels = ['BEdita/DevTools.Configuration']; |
40
|
|
|
$panels = array_merge((array)Configure::read('DebugKit.panels', []), $panels); |
41
|
|
|
Configure::write('DebugKit.panels', $panels); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritDoc |
46
|
|
|
*/ |
47
|
|
|
public function middleware($middleware): MiddlewareQueue |
48
|
|
|
{ |
49
|
|
|
$middleware = parent::middleware($middleware); |
50
|
|
|
if (!Configure::read('Accept.html', false)) { |
51
|
|
|
return $middleware; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $middleware->prepend([new AssetMiddleware(), new HtmlMiddleware()]); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|