Lines
0.00%
0 / 5
Functions and Methods
0.00%
0 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| WorkerStoresFactory | 0.00% | 0 / 5 | 0.00% | 0 / 2 | 12 | 0.00% | 0 / 1 | |||
| __construct | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| createStores | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 6 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Worker; | |
| 6 | ||
| 7 | use LogicException; | |
| 8 | use Stewart\Runtime\Ipc\Message\Bootstrap; | |
| 9 | use Stewart\Store\DisabledStores; | |
| 10 | use Stewart\Store\Exception\StoreSetupException; | |
| 11 | use Stewart\Store\KeyspacedStores; | |
| 12 | use Stewart\Store\StoreBackend; | |
| 13 | use Stewart\Store\StorePrefix; | |
| 14 | use Stewart\Store\Stores; | |
| 15 | use Stewart\Store\StoreValueCodec; | |
| 16 | use Stewart\Support\Text\ClosestNameFinder; | |
| 17 | ||
| 18 | final readonly class WorkerStoresFactory | |
| 19 | { | |
| 20 | public function __construct( | |
| 21 | private Bootstrap $bootstrap, | |
| 22 | private StoreValueCodec $codec, | |
| 23 | private ClosestNameFinder $closestNameFinder, | |
| 24 | private ?StoreBackend $storeBackend = null, | |
| 25 | ) {} | |
| 26 | ||
| 27 | /** @throws StoreSetupException */ | |
| 28 | public function createStores(): Stores | |
| 29 | { | |
| 30 | if ($this->storeBackend === null) { | |
| 31 | return new DisabledStores(); | |
| 32 | } | |
| 33 | ||
| 34 | $prefix = $this->bootstrap->store->prefix ?? throw new LogicException('A store backend was opened without store settings.'); | |
| 35 | ||
| 36 | return new KeyspacedStores($this->storeBackend, new StorePrefix($prefix), $this->bootstrap->knownAppIds->collection, $this->codec, $this->closestNameFinder); | |
| 37 | } | |
| 38 | } |