Skip to content

Commit db3ff6f

Browse files
committed
add ChainIconRegistry
1 parent de8ce35 commit db3ff6f

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

src/Icons/config/services.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\UX\Icons\Command\WarmCacheCommand;
1515
use Symfony\UX\Icons\IconRenderer;
1616
use Symfony\UX\Icons\Registry\CacheIconRegistry;
17+
use Symfony\UX\Icons\Registry\ChainIconRegistry;
1718
use Symfony\UX\Icons\Registry\LocalSvgIconRegistry;
1819
use Symfony\UX\Icons\Twig\IconFinder;
1920
use Symfony\UX\Icons\Twig\UXIconComponent;
@@ -24,14 +25,20 @@
2425
$container->services()
2526
->set('.ux_icons.cache_icon_registry', CacheIconRegistry::class)
2627
->args([
27-
service('.ux_icons.local_svg_icon_registry'),
28+
service('.ux_icons.chain_registry'),
2829
service('cache.system'),
2930
])
3031

3132
->set('.ux_icons.local_svg_icon_registry', LocalSvgIconRegistry::class)
3233
->args([
3334
abstract_arg('icon_dir'),
3435
])
36+
->tag('ux_icons.registry', ['priority' => 10])
37+
38+
->set('.ux_icons.chain_registry', ChainIconRegistry::class)
39+
->args([
40+
tagged_iterator('ux_icons.registry'),
41+
])
3542

3643
->alias('.ux_icons.icon_registry', '.ux_icons.cache_icon_registry')
3744

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\Icons\Registry;
13+
14+
use Symfony\UX\Icons\Exception\IconNotFoundException;
15+
use Symfony\UX\Icons\IconRegistryInterface;
16+
use Symfony\UX\Icons\Svg\Icon;
17+
18+
/**
19+
* @author Kevin Bond <kevinbond@gmail.com>
20+
*
21+
* @internal
22+
*/
23+
final class ChainIconRegistry implements IconRegistryInterface
24+
{
25+
/**
26+
* @param IconRegistryInterface[] $registries
27+
*/
28+
public function __construct(private iterable $registries)
29+
{
30+
}
31+
32+
public function get(string $name): Icon
33+
{
34+
foreach ($this->registries as $registry) {
35+
try {
36+
return $registry->get($name);
37+
} catch (IconNotFoundException) {
38+
}
39+
}
40+
41+
throw new IconNotFoundException(sprintf('Icon "%s" not found.', $name));
42+
}
43+
}

0 commit comments

Comments
 (0)