Configuration::configureRestler()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 12
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Aoe\Restler\System\Restler;
4
5
/***************************************************************
6
 *  Copyright notice
7
 *
8
 *  (c) 2024 AOE GmbH <[email protected]>
9
 *
10
 *  All rights reserved
11
 *
12
 *  This script is part of the TYPO3 project. The TYPO3 project is
13
 *  free software; you can redistribute it and/or modify
14
 *  it under the terms of the GNU General Public License as published by
15
 *  the Free Software Foundation; either version 3 of the License, or
16
 *  (at your option) any later version.
17
 *
18
 *  The GNU General Public License can be found at
19
 *  http://www.gnu.org/copyleft/gpl.html.
20
 *
21
 *  This script is distributed in the hope that it will be useful,
22
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 *  GNU General Public License for more details.
25
 *
26
 *  This copyright notice MUST APPEAR in all copies of the script!
27
 ***************************************************************/
28
29
use Aoe\Restler\Configuration\ExtensionConfiguration;
30
use Aoe\Restler\Controller\BeUserAuthenticationController;
31
use Aoe\Restler\Controller\ExplorerAuthenticationController;
32
use Aoe\Restler\Controller\FeUserAuthenticationController;
33
use Luracast\Restler\Explorer\v2\Explorer;
34
use Luracast\Restler\Restler;
35
36
/**
37
 * Configure restler:
38
 *  - add API- and authentication-class, when online-documentation is enabled
39
 *    (this can be configured via extension-manager)
40
 *  - add authentication-class, which can be used to check, if FE-user is logged in
41
 */
42
class Configuration implements ConfigurationInterface
43
{
44
    public function __construct(
45
        private readonly ExtensionConfiguration $extensionConfiguration
46
    ) {
47
    }
48 2
49
    /**
50 2
     * configure restler:
51 2
     *  - add API- and authentication-class, when online documentation is enabled
52
     *  - add common authentication-class (which can be used for TYPO3-FrontEnd-User-authentication)
53
     */
54
    public function configureRestler(Restler $restler): void
55
    {
56
        if ($this->extensionConfiguration->isOnlineDocumentationEnabled()) {
57
            $restler->addAPIClass(Explorer::class, $this->extensionConfiguration->getPathOfOnlineDocumentation());
58 2
            $restler->addAuthenticationClass(ExplorerAuthenticationController::class);
59
        }
60 2
61 1
        // add authentication-class, which can be used to check, if BE-user is logged in
62 1
        $restler->addAuthenticationClass(BeUserAuthenticationController::class);
63
64
        // add authentication-class, which can be used to check, if FE-user is logged in
65
        $restler->addAuthenticationClass(FeUserAuthenticationController::class);
66 2
    }
67
}
68