From 62e704e189e7d091731ddafa0233cf1706b61f2b Mon Sep 17 00:00:00 2001 From: Pierre du Plessis Date: Wed, 11 Sep 2024 20:17:26 +0200 Subject: [PATCH] Fix getting runtime --- src/Icons/config/services.php | 3 ++- src/Icons/src/Twig/Node/UXIconFunction.php | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Icons/config/services.php b/src/Icons/config/services.php index a0b8ca576bb..7d0dc0abd11 100644 --- a/src/Icons/config/services.php +++ b/src/Icons/config/services.php @@ -14,6 +14,7 @@ use Symfony\UX\Icons\Command\WarmCacheCommand; use Symfony\UX\Icons\IconCacheWarmer; use Symfony\UX\Icons\IconRenderer; +use Symfony\UX\Icons\IconRendererInterface; use Symfony\UX\Icons\Registry\CacheIconRegistry; use Symfony\UX\Icons\Registry\ChainIconRegistry; use Symfony\UX\Icons\Registry\LocalSvgIconRegistry; @@ -60,7 +61,7 @@ abstract_arg('icon_aliases'), ]) - ->alias('Symfony\UX\Icons\IconRendererInterface', '.ux_icons.icon_renderer') + ->alias(IconRendererInterface::class, '.ux_icons.icon_renderer') ->set('.ux_icons.icon_finder', IconFinder::class) ->args([ diff --git a/src/Icons/src/Twig/Node/UXIconFunction.php b/src/Icons/src/Twig/Node/UXIconFunction.php index dfbf34dba7c..891bc41ea9e 100644 --- a/src/Icons/src/Twig/Node/UXIconFunction.php +++ b/src/Icons/src/Twig/Node/UXIconFunction.php @@ -11,8 +11,10 @@ namespace Symfony\UX\Icons\Twig\Node; -use Symfony\UX\Icons\IconRenderer; +use Symfony\UX\Icons\Exception\IconNotFoundException; +use Symfony\UX\Icons\Twig\UXIconRuntime; use Twig\Compiler; +use Twig\Error\RuntimeError; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FunctionExpression; @@ -58,11 +60,15 @@ public function compile(Compiler $compiler): void } } - $compiler->string( - $compiler - ->getEnvironment() - ->getRuntime(IconRenderer::class) - ->renderIcon($iconName->getAttribute('value'), $iconAttributes) - ); + try { + $compiler->string( + $compiler + ->getEnvironment() + ->getRuntime(UXIconRuntime::class) + ->renderIcon($iconName->getAttribute('value'), $iconAttributes) + ); + } catch (IconNotFoundException|RuntimeError) { + parent::compile($compiler); + } } }