Lines
100.00%
3 / 3
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AdminApiCodec | 100.00% | 3 / 3 | 100.00% | 3 / 3 | 3 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| createAdminApiWireMapper | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| encodeResponse | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Http\Admin; | |
| 6 | ||
| 7 | use JsonException; | |
| 8 | use Stewart\Contracts\Exception\StewartException; | |
| 9 | use Stewart\Runtime\Control\Protocol\Frame\CommandResult; | |
| 10 | use Stewart\Runtime\Control\Protocol\Frame\RequestFailed; | |
| 11 | use Stewart\Runtime\Http\Admin\Response\AdminAppList; | |
| 12 | use Stewart\Runtime\Http\Admin\Response\AdminAppView; | |
| 13 | use Stewart\Runtime\Json\ClassShapeReader; | |
| 14 | use Stewart\Runtime\Json\Collection\ValueConverterCollection; | |
| 15 | use Stewart\Runtime\Json\IsoInstantConverter; | |
| 16 | use Stewart\Runtime\Json\WireMapper; | |
| 17 | ||
| 18 | final readonly class AdminApiCodec | |
| 19 | { | |
| 20 | public function __construct(private WireMapper $adminApiWireMapper) {} | |
| 21 | ||
| 22 | public static function createAdminApiWireMapper(): WireMapper | |
| 23 | { | |
| 24 | return new WireMapper(new ClassShapeReader(ValueConverterCollection::keyedByHandledClass([new IsoInstantConverter()]))); | |
| 25 | } | |
| 26 | ||
| 27 | /** @throws JsonException|StewartException */ | |
| 28 | public function encodeResponse(AdminAppList|AdminAppView|CommandResult|RequestFailed $response): string | |
| 29 | { | |
| 30 | return $this->adminApiWireMapper->encodeObject($response); | |
| 31 | } | |
| 32 | } |