Passed
Push — main ( 9da72c...4c09d2 )
by Felix
20:30 queued 11:53
created

Configuration   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 9
dl 0
loc 36
ccs 9
cts 10
cp 0.9
rs 10
c 1
b 1
f 1
wmc 3

2 Methods

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