Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
23.81% |
5 / 21 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CmsRendererFactory | |
23.81% |
5 / 21 |
|
0.00% |
0 / 2 |
16.06 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createRenderer | |
25.00% |
5 / 20 |
|
0.00% |
0 / 1 |
10.75 | |||
| 1 | <?php |
| 2 | namespace Apie\Common\Wrappers; |
| 3 | |
| 4 | use Apie\CmsLayoutGraphite\GraphiteDesignSystemLayout; |
| 5 | use Apie\CmsLayoutIonic\IonicDesignSystemLayout; |
| 6 | use Apie\CmsLayoutUgly\UglyDesignSystemLayout; |
| 7 | use Apie\Core\Context\ApieContext; |
| 8 | use Apie\HtmlBuilders\Assets\AssetManager; |
| 9 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 10 | use Apie\HtmlBuilders\Interfaces\ComponentRendererInterface; |
| 11 | use Symfony\UX\Icons\Twig\UXIconRuntime; |
| 12 | |
| 13 | final class CmsRendererFactory |
| 14 | { |
| 15 | private function __construct() |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | public static function createRenderer( |
| 20 | UXIconRuntime $runtimeLoader, |
| 21 | ?AssetManager $assetManager, |
| 22 | ): ComponentRendererInterface { |
| 23 | if (class_exists(IonicDesignSystemLayout::class)) { |
| 24 | return IonicDesignSystemLayout::createRenderer( |
| 25 | $runtimeLoader, |
| 26 | $assetManager, |
| 27 | ); |
| 28 | } |
| 29 | if (class_exists(GraphiteDesignSystemLayout::class)) { |
| 30 | return GraphiteDesignSystemLayout::createRenderer( |
| 31 | $runtimeLoader, |
| 32 | $assetManager, |
| 33 | ); |
| 34 | } |
| 35 | if (class_exists(UglyDesignSystemLayout::class)) { |
| 36 | return UglyDesignSystemLayout::createRenderer( |
| 37 | $runtimeLoader, |
| 38 | $assetManager, |
| 39 | ); |
| 40 | } |
| 41 | // fallback is just a message displaying you need to install a cms renderer package. |
| 42 | $contents = file_get_contents(__DIR__ . '/../../resources/html/install-instructions-cms-renderer.html'); |
| 43 | return new class($contents) implements ComponentRendererInterface { |
| 44 | public function __construct(private string $contents) |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | public function render(ComponentInterface $componentInterface, ApieContext $apieContext): string |
| 49 | { |
| 50 | return $this->contents; |
| 51 | } |
| 52 | }; |
| 53 | } |
| 54 | } |