Lines
100.00%
8 / 8
Functions and Methods
100.00%
5 / 5
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| GeneratedManifest | 100.00% | 8 / 8 | 100.00% | 5 / 5 | 8 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| readFromClass | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 3 | |||||
| findForGeneratedCode | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 2 | |||||
| hasCurrentFormat | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| findDrift | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Broker; | |
| 6 | ||
| 7 | use Stewart\Contracts\Generated\Manifest; | |
| 8 | use Stewart\Contracts\Wire\ListOf; | |
| 9 | use Stewart\Runtime\App\GeneratedRoots; | |
| 10 | use Stewart\Runtime\Config\CodegenConfig; | |
| 11 | use Stewart\Runtime\Exception\AppException; | |
| 12 | use Stewart\Support\Wire\GeneratedFormat; | |
| 13 | ||
| 14 | // Data rather than the class, because a reload after stewart generate brings it from a process that loaded the new one. | |
| 15 | final readonly class GeneratedManifest | |
| 16 | { | |
| 17 | /** | |
| 18 | * @param list<string> $entityIds | |
| 19 | * @param list<string> $ignoredEntityIds | |
| 20 | */ | |
| 21 | public function __construct( | |
| 22 | public int $formatVersion, | |
| 23 | #[ListOf('string')] | |
| 24 | public array $entityIds, | |
| 25 | #[ListOf('string')] | |
| 26 | public array $ignoredEntityIds, | |
| 27 | ) {} | |
| 28 | ||
| 29 | /** @param class-string<Manifest> $manifest */ | |
| 30 | public static function readFromClass(string $manifest): self | |
| 31 | { | |
| 32 | $constant = $manifest . '::' . GeneratedFormat::MANIFEST_CONSTANT; | |
| 33 | $version = \defined($constant) ? \constant($constant) : 0; | |
| 34 | ||
| 35 | return new self(\is_int($version) ? $version : 0, $manifest::listEntityIds(), $manifest::listIgnoredEntityIds()); | |
| 36 | } | |
| 37 | ||
| 38 | /** @throws AppException */ | |
| 39 | public static function findForGeneratedCode(CodegenConfig $codegen): ?self | |
| 40 | { | |
| 41 | $manifest = GeneratedRoots::fromNamespace($codegen->namespace->value)?->manifestClass; | |
| 42 | ||
| 43 | return $manifest === null ? null : self::readFromClass($manifest); | |
| 44 | } | |
| 45 | ||
| 46 | public function hasCurrentFormat(): bool | |
| 47 | { | |
| 48 | return $this->formatVersion === GeneratedFormat::VERSION; | |
| 49 | } | |
| 50 | ||
| 51 | /** @param list<string> $liveEntityIds */ | |
| 52 | public function findDrift(array $liveEntityIds): ManifestDrift | |
| 53 | { | |
| 54 | return ManifestDrift::calculateBetween($this->entityIds, $liveEntityIds, $this->ignoredEntityIds); | |
| 55 | } | |
| 56 | } |