configureContainer()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 9.7333
c 0
b 0
f 0
cc 3
nc 1
nop 1
crap 3
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Application\Packages\Authorization;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Limoncello\Application\Authorization\AuthorizationManager;
22
use Limoncello\Application\Packages\Authorization\AuthorizationSettings as S;
23
use Limoncello\Contracts\Application\ContainerConfiguratorInterface;
24
use Limoncello\Contracts\Authorization\AuthorizationManagerInterface;
25
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface;
26
use Limoncello\Contracts\Settings\SettingsProviderInterface;
27
use Psr\Container\ContainerInterface as PsrContainerInterface;
28
use Psr\Log\LoggerInterface;
29
30
/**
31
 * @package Limoncello\Application
32
 */
33
class AuthorizationContainerConfigurator implements ContainerConfiguratorInterface
34
{
35
    /** @var callable */
36
    const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME];
37
38
    /**
39 2
     * @inheritdoc
40
     */
41
    public static function configureContainer(LimoncelloContainerInterface $container): void
42 2
    {
43 2
        $container[AuthorizationManagerInterface::class] = function (PsrContainerInterface $container) {
44
            $settingsProvider = $container->get(SettingsProviderInterface::class);
45 2
            $settings         = $settingsProvider->get(S::class);
46 2
47 2
            $manager      = new AuthorizationManager($container, $settings[S::KEY_POLICIES_DATA]);
48 2
            $isLogEnabled = $settings[S::KEY_LOG_IS_ENABLED] ?? false;
49 2
            if ($isLogEnabled === true && $container->has(LoggerInterface::class)) {
50
                $logger = $container->get(LoggerInterface::class);
51
                $manager->setLogger($logger);
52 2
            }
53
54
            return $manager;
55
        };
56
    }
57
}
58