Lines
100.00%
2 / 2
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| StoreBackendRegistry | 100.00% | 2 / 2 | 100.00% | 2 / 2 | 2 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| requireFactoryForDsn | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Store; | |
| 6 | ||
| 7 | use Stewart\Store\Collection\StoreBackendFactoryCollection; | |
| 8 | use Stewart\Store\Exception\StoreSetupException; | |
| 9 | ||
| 10 | final readonly class StoreBackendRegistry | |
| 11 | { | |
| 12 | private StoreBackendFactoryCollection $factories; | |
| 13 | ||
| 14 | /** @param iterable<StoreBackendFactory> $factories */ | |
| 15 | public function __construct(iterable $factories = []) | |
| 16 | { | |
| 17 | $this->factories = StoreBackendFactoryCollection::keyedByScheme($factories); | |
| 18 | } | |
| 19 | ||
| 20 | /** @throws StoreSetupException */ | |
| 21 | public function requireFactoryForDsn(StoreDsn $dsn): StoreBackendFactory | |
| 22 | { | |
| 23 | return $this->factories->find($dsn->scheme) ?? throw StoreSetupException::schemeUnsupported($dsn->scheme, $this->factories->listSchemes()); | |
| 24 | } | |
| 25 | } |