Skip to content

Commit

Permalink
Fix getting runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Sep 11, 2024
1 parent c09dfff commit 62e704e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/Icons/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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([
Expand Down
20 changes: 13 additions & 7 deletions src/Icons/src/Twig/Node/UXIconFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 62e704e

Please sign in to comment.