Issues (48)

OptionsResolver/OptionsResolverLocator.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
7
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9
 *
10
 * Copyright (c) 2024 Mykhailo Shtanko [email protected]
11
 *
12
 * For the full copyright and license information, please view the LICENSE.MD
13
 * file that was distributed with this source code.
14
 */
15
16
namespace FRZB\Component\MetricsPower\OptionsResolver;
17
18
use Fp\Collections\HashMap;
19
use FRZB\Component\DependencyInjection\Attribute\AsService;
20
use FRZB\Component\MetricsPower\Attribute\OptionsInterface;
21
use FRZB\Component\MetricsPower\OptionsResolver\Resolver\OptionsResolverInterface;
22
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
23
24
#[AsService]
25
class OptionsResolverLocator implements OptionsResolverLocatorInterface
26
{
27
    /** @var HashMap<string, OptionsResolverInterface> */
28
    private readonly HashMap $resolvers;
29
30
    public function __construct(
31
        #[TaggedIterator(OptionsResolverInterface::class, defaultIndexMethod: 'getType')]
32
        iterable $resolvers,
33
    ) {
34
        $this->resolvers = HashMap::collect($resolvers);
0 ignored issues
show
The property resolvers is declared read-only in FRZB\Component\MetricsPo...\OptionsResolverLocator.
Loading history...
35
    }
36
37
    public function get(OptionsInterface $option): OptionsResolverInterface
38
    {
39
        return $this->resolvers->get($option::class)->get()
40
            ?? $this->resolvers->get(OptionsInterface::class)->getUnsafe();
41
    }
42
}
43