File tree Expand file tree Collapse file tree 5 files changed +81
-5
lines changed Expand file tree Collapse file tree 5 files changed +81
-5
lines changed Original file line number Diff line number Diff line change 50
50
])
51
51
->tag ('twig.runtime ' )
52
52
53
+ ->alias ('Symfony\UX\Icons\IconRendererInterface ' , '.ux_icons.icon_renderer ' )
54
+
53
55
->set ('.ux_icons.icon_finder ' , IconFinder::class)
54
56
->args ([
55
57
service ('twig ' ),
Original file line number Diff line number Diff line change 16
16
*
17
17
* @internal
18
18
*/
19
- final class IconRenderer
19
+ final class IconRenderer implements IconRendererInterface
20
20
{
21
21
public function __construct (
22
22
private readonly IconRegistryInterface $ registry ,
@@ -32,8 +32,6 @@ public function __construct(
32
32
*
33
33
* Precedence order:
34
34
* Icon file < Renderer configuration < Renderer invocation
35
- *
36
- * @param array<string,string|bool> $attributes
37
35
*/
38
36
public function renderIcon (string $ name , array $ attributes = []): string
39
37
{
Original file line number Diff line number Diff line change
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 ;
13
+
14
+ use Symfony \UX \Icons \Exception \IconNotFoundException ;
15
+
16
+ /**
17
+ * @author Simon André <smn.andre@gmail.com>
18
+ * @author Kevin Bond <kevinbond@gmail.com>
19
+ */
20
+ interface IconRendererInterface
21
+ {
22
+ /**
23
+ * Renders an icon by its name and returns the SVG string.
24
+ *
25
+ * @param string $name the icon name, optionally prefixed with the icon set
26
+ * @param array<string, string|bool> $attributes an array of HTML attributes
27
+ *
28
+ * @throws IconNotFoundException
29
+ *
30
+ * @example
31
+ * $iconRenderer->renderIcon('arrow-right');
32
+ * // Renders the "arrow-right" icon from the default icons directory.
33
+ *
34
+ * $iconRenderer->renderIcon('lucide:heart', ['class' => 'color-red']);
35
+ * // Renders the "heart" icon from the "lucide" icon set, with the "color-red" class.
36
+ */
37
+ public function renderIcon (string $ name , array $ attributes = []): string ;
38
+ }
Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \UX \Icons \Twig ;
13
13
14
- use Symfony \UX \Icons \IconRenderer ;
14
+ use Symfony \UX \Icons \IconRendererInterface ;
15
15
use Symfony \UX \TwigComponent \Event \PreCreateForRenderEvent ;
16
16
17
17
/**
22
22
final class UXIconComponentListener
23
23
{
24
24
public function __construct (
25
- private IconRenderer $ iconRenderer ,
25
+ private IconRendererInterface $ iconRenderer ,
26
26
) {
27
27
}
28
28
Original file line number Diff line number Diff line change
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 \Tests \Integration ;
13
+
14
+ use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
15
+ use Symfony \UX \Icons \IconRenderer ;
16
+ use Symfony \UX \Icons \IconRendererInterface ;
17
+
18
+ /**
19
+ * @author Simon André <smn.andre@gmail.com>
20
+ */
21
+ final class IconRendererTest extends KernelTestCase
22
+ {
23
+ public function testIconRenderService (): void
24
+ {
25
+ $ this ->assertTrue (self ::getContainer ()->has (IconRendererInterface::class));
26
+ }
27
+
28
+ public function testIconRendererAlias (): void
29
+ {
30
+ $ renderer = self ::getContainer ()->get (IconRendererInterface::class);
31
+ $ this ->assertInstanceOf (IconRenderer::class, $ renderer );
32
+ }
33
+
34
+ public function testIconRendererIsPrivate (): void
35
+ {
36
+ $ this ->assertFalse (self ::getContainer ()->has (IconRenderer::class));
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments