Passed
Push — master ( 6c7aff...ce6d49 )
by
unknown
46:49 queued 20:16
created

ProviderRegistry::hasProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
18
namespace TYPO3\CMS\Lowlevel\ConfigurationModuleProvider;
19
20
/**
21
 * Registry for configuration providers which is called by the ConfigurationProviderPass
22
 */
23
final class ProviderRegistry
24
{
25
    /**
26
     * @var ProviderInterface[]
27
     */
28
    protected array $providers = [];
29
30
    public function registerProvider(ProviderInterface $provider, array $attributes): void
31
    {
32
        $this->providers[$attributes['identifier']] = $provider($attributes);
33
    }
34
35
    public function hasProvider(string $identifer): bool
36
    {
37
        return isset($this->providers[$identifer]);
38
    }
39
40
    public function getProvider(string $identifier): ProviderInterface
41
    {
42
        if (!isset($this->providers[$identifier])) {
43
            throw new \InvalidArgumentException('No provider for identifier ' . $identifier . 'found.', 1606490398);
44
        }
45
46
        return $this->providers[$identifier];
47
    }
48
49
    public function getProviders(): array
50
    {
51
        return $this->providers;
52
    }
53
54
    public function getFirstProvider(): ?ProviderInterface
55
    {
56
        return $this->providers !== [] ? reset($this->providers) : null;
57
    }
58
}
59