Completed
Push — develop ( b3a94f...bc6c2d )
by Tino
07:35
created

RichFileManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright (c) by the ACP3 Developers.
5
 * See the LICENSE file at the top-level module directory for licensing details.
6
 */
7
8
namespace ACP3\Modules\ACP3\Filemanager\Controller\Admin\Index;
9
10
use ACP3\Core\Controller\AbstractFrontendAction;
11
use ACP3\Core\Controller\Context\FrontendContext;
12
use ACP3\Core\Environment\ApplicationMode;
13
14
class RichFileManager extends AbstractFrontendAction
15
{
16
    /**
17
     * @var string
18
     */
19
    private $applicationMode;
20
21
    public function __construct(FrontendContext $context, string $applicationMode)
22
    {
23
        parent::__construct($context);
24
25
        $this->applicationMode = $applicationMode;
26
    }
27
28
    /**
29
     * @throws \Exception
30
     */
31
    public function execute(): void
32
    {
33
        $app = new \RFM\Application();
34
35
        $local = new \RFM\Repository\Local\Storage($this->getFileManagerConfig());
36
        $local->setRoot($this->appPath->getWebRoot() . 'uploads/', true, true);
37
38
        $app->setStorage($local);
39
40
        $app->api = new \RFM\Api\LocalApi();
41
42
        $app->run();
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    private function getFileManagerConfig(): array
49
    {
50
        return [
51
            'logger' => [
52
                'enabled' => $this->applicationMode === ApplicationMode::DEVELOPMENT,
53
                'file' => $this->appPath->getCacheDir() . 'logs/filemanager.log',
54
            ],
55
            'security' => [
56
                'patterns' => [
57
                    'policy' => 'DISALLOW_LIST',
58
                    'ignoreCase' => true,
59
                    'restrictions' => [
60
                        '*/.htaccess',
61
                        '*/web.config',
62
                        '*/cache/*',
63
                        '*/assets/*',
64
                    ],
65
                ],
66
            ],
67
        ];
68
    }
69
}
70