@@ -34,6 +34,9 @@ final class Iconify
34
34
// -safe margin
35
35
private const MAX_ICONS_QUERY_LENGTH = 400 ;
36
36
37
+ private const DEFAULT_ICON_WIDTH = 16 ;
38
+ private const DEFAULT_ICON_HEIGHT = 16 ;
39
+
37
40
private HttpClientInterface $ http ;
38
41
private \ArrayObject $ sets ;
39
42
private int $ maxIconsQueryLength ;
@@ -81,13 +84,10 @@ public function fetchIcon(string $prefix, string $name): Icon
81
84
82
85
$ height = $ data ['icons ' ][$ name ]['height ' ] ?? $ data ['height ' ] ?? $ this ->sets ()[$ prefix ]['height ' ] ?? null ;
83
86
$ width = $ data ['icons ' ][$ name ]['width ' ] ?? $ data ['width ' ] ?? $ this ->sets ()[$ prefix ]['width ' ] ?? null ;
84
- if (null === $ width && null === $ height ) {
85
- throw new \RuntimeException (\sprintf ('The icon "%s:%s" does not have a width or height. ' , $ prefix , $ nameArg ));
86
- }
87
87
88
88
return new Icon ($ data ['icons ' ][$ name ]['body ' ], [
89
89
'xmlns ' => self ::ATTR_XMLNS_URL ,
90
- 'viewBox ' => \sprintf ('0 0 %s %s ' , $ width ?? $ height , $ height ?? $ width ),
90
+ 'viewBox ' => \sprintf ('0 0 %s %s ' , $ width ?? $ height ?? self :: DEFAULT_ICON_WIDTH , $ height ?? $ width ?? self :: DEFAULT_ICON_HEIGHT ),
91
91
]);
92
92
}
93
93
@@ -133,9 +133,10 @@ public function fetchIcons(string $prefix, array $names): array
133
133
$ height = $ iconData ['height ' ] ?? $ data ['height ' ] ??= $ this ->sets ()[$ prefix ]['height ' ] ?? null ;
134
134
$ width = $ iconData ['width ' ] ?? $ data ['width ' ] ??= $ this ->sets ()[$ prefix ]['width ' ] ?? null ;
135
135
136
+
136
137
$ icons [$ iconName ] = new Icon ($ iconData ['body ' ], [
137
138
'xmlns ' => self ::ATTR_XMLNS_URL ,
138
- 'viewBox ' => \sprintf ('0 0 %d %d ' , $ width ?? $ height , $ height ?? $ width ),
139
+ 'viewBox ' => \sprintf ('0 0 %d %d ' , $ width ?? $ height ?? self :: DEFAULT_ICON_WIDTH , $ height ?? $ width ?? self :: DEFAULT_ICON_HEIGHT ),
139
140
]);
140
141
}
141
142
0 commit comments