Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
36.00% |
9 / 25 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CmsRendererFactory | |
36.00% |
9 / 25 |
|
33.33% |
1 / 3 |
19.85 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createFallbackLoader | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| createRenderer | |
31.82% |
7 / 22 |
|
0.00% |
0 / 1 |
12.92 | |||
| 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\Component\DependencyInjection\Container; |
| 12 | use Twig\RuntimeLoader\ContainerRuntimeLoader; |
| 13 | use Twig\RuntimeLoader\RuntimeLoaderInterface; |
| 14 | |
| 15 | final class CmsRendererFactory |
| 16 | { |
| 17 | private function __construct() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | private static function createFallbackLoader(): RuntimeLoaderInterface |
| 22 | { |
| 23 | $container = new Container(); |
| 24 | //$container->set() |
| 25 | return new ContainerRuntimeLoader($container); |
| 26 | } |
| 27 | |
| 28 | public static function createRenderer( |
| 29 | ?RuntimeLoaderInterface $runtimeLoader, |
| 30 | ?AssetManager $assetManager, |
| 31 | ): ComponentRendererInterface { |
| 32 | if ($runtimeLoader === null) { |
| 33 | $runtimeLoader = self::createFallbackLoader(); |
| 34 | } |
| 35 | if (class_exists(IonicDesignSystemLayout::class)) { |
| 36 | return IonicDesignSystemLayout::createRenderer( |
| 37 | $runtimeLoader, |
| 38 | $assetManager, |
| 39 | ); |
| 40 | } |
| 41 | if (class_exists(GraphiteDesignSystemLayout::class)) { |
| 42 | return GraphiteDesignSystemLayout::createRenderer( |
| 43 | $runtimeLoader, |
| 44 | $assetManager, |
| 45 | ); |
| 46 | } |
| 47 | if (class_exists(UglyDesignSystemLayout::class)) { |
| 48 | return UglyDesignSystemLayout::createRenderer( |
| 49 | $runtimeLoader, |
| 50 | $assetManager, |
| 51 | ); |
| 52 | } |
| 53 | // fallback is just a message displaying you need to install a cms renderer package. |
| 54 | $contents = file_get_contents(__DIR__ . '/../../resources/html/install-instructions-cms-renderer.html'); |
| 55 | return new class($contents) implements ComponentRendererInterface { |
| 56 | public function __construct(private string $contents) |
| 57 | { |
| 58 | } |
| 59 | |
| 60 | public function render(ComponentInterface $componentInterface, ApieContext $apieContext): string |
| 61 | { |
| 62 | return $this->contents; |
| 63 | } |
| 64 | }; |
| 65 | } |
| 66 | } |