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