1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Limoncello\Application\Packages\Cors; |
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\Packages\Cors\CorsSettings as C; |
22
|
|
|
use Limoncello\Contracts\Application\ContainerConfiguratorInterface; |
23
|
|
|
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface; |
24
|
|
|
use Limoncello\Contracts\Settings\SettingsProviderInterface; |
25
|
|
|
use Neomerx\Cors\Analyzer; |
26
|
|
|
use Neomerx\Cors\Contracts\AnalyzerInterface; |
27
|
|
|
use Neomerx\Cors\Strategies\Settings; |
28
|
|
|
use Psr\Container\ContainerInterface as PsrContainerInterface; |
29
|
|
|
use Psr\Log\LoggerInterface; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @package Limoncello\Application |
33
|
|
|
*/ |
34
|
|
|
class CorsContainerConfigurator implements ContainerConfiguratorInterface |
35
|
|
|
{ |
36
|
|
|
/** @var callable */ |
37
|
|
|
const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @inheritdoc |
41
|
|
|
* |
42
|
1 |
|
* @SuppressWarnings(PHPMD.StaticAccess) |
43
|
|
|
* @SuppressWarnings(PHPMD.UndefinedVariable) |
44
|
|
|
*/ |
45
|
1 |
|
public static function configureContainer(LimoncelloContainerInterface $container): void |
46
|
|
|
{ |
47
|
1 |
|
$container[AnalyzerInterface::class] = function (PsrContainerInterface $container) { |
48
|
|
|
$settingsProvider = $container->get(SettingsProviderInterface::class); |
49
|
1 |
|
|
50
|
|
|
[$corsSettings, $isLogEnabled] = $settingsProvider->get(C::class); |
|
|
|
|
51
|
1 |
|
|
52
|
1 |
|
$analyzer = Analyzer::instance((new Settings())->setData($corsSettings)); |
53
|
1 |
|
|
54
|
|
|
if ($isLogEnabled === true && $container->has(LoggerInterface::class)) { |
55
|
|
|
$logger = $container->get(LoggerInterface::class); |
56
|
1 |
|
$analyzer->setLogger($logger); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $analyzer; |
60
|
|
|
}; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.