@@ -41,11 +41,7 @@ public function __construct(private Iconify $iconify, private LocalSvgIconRegist
41
41
protected function configure (): void
42
42
{
43
43
$ this
44
- ->addArgument (
45
- 'names ' ,
46
- InputArgument::IS_ARRAY | InputArgument::REQUIRED ,
47
- 'Icon name from ux.symfony.com/icons (e.g. "mdi:home") ' ,
48
- )
44
+ ->addArgument ('names ' , InputArgument::IS_ARRAY | InputArgument::REQUIRED , 'Icon name from ux.symfony.com/icons (e.g. "mdi:home") ' )
49
45
;
50
46
}
51
47
@@ -55,6 +51,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
55
51
$ names = $ input ->getArgument ('names ' );
56
52
$ result = Command::SUCCESS ;
57
53
54
+ $ prefixIcons = [];
55
+ $ importedIcons = 0 ;
58
56
foreach ($ names as $ name ) {
59
57
if (!preg_match ('#^([\w-]+):([\w-]+)$# ' , $ name , $ matches )) {
60
58
$ io ->error (\sprintf ('Invalid icon name "%s". ' , $ name ));
@@ -65,33 +63,57 @@ protected function execute(InputInterface $input, OutputInterface $output): int
65
63
66
64
[$ fullName , $ prefix , $ name ] = $ matches ;
67
65
68
- $ io ->comment (\sprintf ('Importing %s... ' , $ fullName ));
66
+ $ prefixIcons [$ prefix ] ??= [];
67
+ $ prefixIcons [$ prefix ][$ name ] = $ fullName ;
68
+ }
69
+
70
+ foreach ($ prefixIcons as $ prefix => $ icons ) {
69
71
70
- try {
71
- $ iconSvg = $ this ->iconify ->fetchIcon ($ prefix , $ name )->toHtml ();
72
- } catch (IconNotFoundException $ e ) {
73
- $ io ->error ($ e ->getMessage ());
72
+ if (!$ this ->iconify ->hasIconSet ($ prefix )) {
73
+ $ io ->error (\sprintf ('Icon set "%s" not found. ' , $ prefix ));
74
74
$ result = Command::FAILURE ;
75
75
76
76
continue ;
77
77
}
78
78
79
- $ cursor = new Cursor ($ output );
80
- $ cursor ->moveUp (2 );
81
-
82
- $ this ->registry ->add (\sprintf ('%s/%s ' , $ prefix , $ name ), $ iconSvg );
83
-
84
- $ license = $ this ->iconify ->metadataFor ($ prefix )['license ' ];
79
+ $ metadata = $ this ->iconify ->metadataFor ($ prefix );
80
+ $ io ->writeln ([
81
+ "\n" ,
82
+ \sprintf (' IconSet: <fg=bright-white;bg=black>%s</> - %s ' , $ metadata ['name ' ], $ prefix ),
83
+ \sprintf (' (Licence: %s) ' , $ metadata ['license ' ]['title ' ]),
84
+ "\n" ,
85
+ ]);
86
+
87
+ foreach (array_chunk ($ icons , 25 , true ) as $ iconBatch ) {
88
+ foreach ($ iconBatch as $ name => $ fullName ) {
89
+ $ io ->writeln (\sprintf (' Importing %s:%s ... ' , $ prefix , $ name ));
90
+ }
91
+
92
+ try {
93
+ $ batchResults = $ this ->iconify ->fetchIcons ($ prefix , $ names );
94
+ } catch (IconNotFoundException $ e ) {
95
+ $ io ->error ($ e ->getMessage ());
96
+ $ result = Command::FAILURE ;
97
+
98
+ continue ;
99
+ }
100
+
101
+ $ cursor = new Cursor ($ output );
102
+ $ cursor ->moveUp (count ($ iconBatch ));
103
+
104
+ foreach ($ batchResults as $ name => $ icon ) {
105
+ $ this ->registry ->add (\sprintf ('%s/%s ' , $ prefix , $ name ), (string ) $ icon );
106
+ ++$ importedIcons ;
107
+ $ cursor ->clearLine ();
108
+ $ io ->writeln (\sprintf (" <fg=bright-green;options=bold>✓</> Imported <fg=bright-white;bg=black>%s:</><fg=bright-magenta;bg=black;options>%s</> " , $ prefix , $ name ));
109
+ }
110
+
111
+ $ cursor ->clearLineAfter ();
112
+ }
113
+ }
85
114
86
- $ io ->text (\sprintf (
87
- " <fg=bright-green;options=bold>✓</> Imported <fg=bright-white;bg=black>%s:</><fg=bright-magenta;bg=black;options>%s</> (License: <href=%s>%s</>). Render with: <comment>{{ ux_icon('%s') }}</comment> " ,
88
- $ prefix ,
89
- $ name ,
90
- $ license ['url ' ] ?? '# ' ,
91
- $ license ['title ' ],
92
- $ fullName ,
93
- ));
94
- $ io ->newLine ();
115
+ if (Command::SUCCESS === $ result ) {
116
+ $ io ->success (sprintf ('Imported %d icons. ' , $ importedIcons ));
95
117
}
96
118
97
119
return $ result ;
0 commit comments