Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
UxIconFactory
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
4 / 4
7
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 create
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 createIconRenderer
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 createIconRegistry
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2namespace Apie\Common\Wrappers;
3
4use Psr\Log\LoggerInterface;
5use Symfony\Contracts\Cache\CacheInterface;
6use Symfony\UX\Icons\IconFactory;
7use Symfony\UX\Icons\Iconify;
8use Symfony\UX\Icons\IconRegistryInterface;
9use Symfony\UX\Icons\IconRenderer;
10use Symfony\UX\Icons\IconRendererInterface;
11use Symfony\UX\Icons\Registry\CacheIconRegistry;
12use Symfony\UX\Icons\Registry\IconifyOnDemandRegistry;
13use Symfony\UX\Icons\Twig\UXIconRuntime;
14
15class UxIconFactory
16{
17    public function __construct(
18        private readonly LoggerInterface $logger,
19        private readonly ?CacheInterface $cache = null
20    ) {
21    }
22
23    public function create(
24        ?UXIconRuntime $runtimeLoader,
25        IconRendererInterface $iconRenderer,
26    ): UXIconRuntime {
27        return $runtimeLoader ?? new UXIconRuntime(
28            $iconRenderer,
29            true,
30            $this->logger
31        );
32    }
33
34    public function createIconRenderer(
35        ?IconRendererInterface $iconRenderer,
36        IconRegistryInterface $registry
37    ): IconRendererInterface {
38        return $iconRenderer ?? new IconRenderer(
39            $registry
40        );
41    }
42
43    public function createIconRegistry(
44        ?IconRegistryInterface $registry = null,
45    ): IconRegistryInterface {
46        if (!$registry) {
47            $iconify = class_exists(IconFactory::class)
48                ? new Iconify(
49                    $this->cache ?? new \Symfony\Component\Cache\Adapter\ArrayAdapter(),
50                    new IconFactory()
51                ) : new Iconify(
52                    $this->cache ?? new \Symfony\Component\Cache\Adapter\ArrayAdapter(),
53                );
54            $registry = new IconifyOnDemandRegistry($iconify);
55            if ($this->cache) {
56                $registry = new CacheIconRegistry(
57                    $registry,
58                    $this->cache
59                );
60            }
61        }
62        return $registry;
63    }
64}