Passed
Branch feature/2.1-geodispersion-dev (1d61a8)
by Jonathan
61:21
created

AdminConfigPage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 17 2
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * webtrees-lib: MyArtJaub library for webtrees
5
 *
6
 * @package MyArtJaub\Webtrees
7
 * @subpackage Certificates
8
 * @author Jonathan Jaubart <[email protected]>
9
 * @copyright Copyright (c) 2009-2021, Jonathan Jaubart
10
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3
11
 */
12
13
declare(strict_types=1);
14
15
namespace MyArtJaub\Webtrees\Module\Certificates\Http\RequestHandlers;
16
17
use Fisharebest\Webtrees\I18N;
18
use Fisharebest\Webtrees\Registry;
19
use Fisharebest\Webtrees\Tree;
20
use Fisharebest\Webtrees\Exceptions\HttpNotFoundException;
21
use Fisharebest\Webtrees\Http\ViewResponseTrait;
22
use Fisharebest\Webtrees\Services\ModuleService;
23
use MyArtJaub\Webtrees\Module\Certificates\CertificatesModule;
24
use Psr\Http\Message\ResponseInterface;
25
use Psr\Http\Message\ServerRequestInterface;
26
use Psr\Http\Server\RequestHandlerInterface;
27
28
/**
29
 * Request handler for displaying configuration of the module.
30
 */
31
class AdminConfigPage implements RequestHandlerInterface
32
{
33
    use ViewResponseTrait;
34
35
    /**
36
     * @var CertificatesModule|null $module
37
     */
38
    private $module;
39
40
    /**
41
     * Constructor for Admin Config page request handler
42
     *
43
     * @param ModuleService $module_service
44
     */
45
    public function __construct(ModuleService $module_service)
46
    {
47
        $this->module = $module_service->findByInterface(CertificatesModule::class)->first();
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
     */
54
    public function handle(ServerRequestInterface $request): ResponseInterface
55
    {
56
        $this->layout = 'layouts/administration';
57
58
        if ($this->module === null) {
59
            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
        }
61
62
        $tree = $request->getAttribute('tree');
63
        assert($tree instanceof Tree);
64
65
        $data_folder = Registry::filesystem()->dataName();
66
67
        return $this->viewResponse($this->module->name() . '::admin/config', [
68
            'title'             =>  $this->module->title(),
69
            'tree'              =>  $tree,
70
            'data_folder'       =>  $data_folder
71
        ]);
72
    }
73
}
74