Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit f1a3962

Browse files
author
Nate Wiebe
authored
Merge pull request #45 from Pixelrobin/icon-loading-improvements
Make icon property static
2 parents dde46c5 + 25a7f53 commit f1a3962

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/IconManager.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,33 @@ class IconManager
99
{
1010
use SvgAttributesTrait;
1111

12-
private $icons;
12+
private static $icons;
1313

1414
private $aliases = [];
1515

1616
public function __construct()
1717
{
1818
$this->attributes = require \implode(DIRECTORY_SEPARATOR, [\dirname(__FILE__), '..', 'resources', 'attributes.php']);
19-
$this->icons = require \implode(DIRECTORY_SEPARATOR, [\dirname(__FILE__), '..', 'resources', 'icons.php']);
19+
20+
if ($this::$icons === null) {
21+
$this::$icons = require \implode(DIRECTORY_SEPARATOR, [\dirname(__FILE__), '..', 'resources', 'icons.php']);
22+
}
2023
}
2124

2225
public function getIconNames(): array
2326
{
24-
return \array_keys($this->icons);
27+
return \array_keys($this::$icons);
2528
}
2629

2730
public function getIcon(string $name, array $attributes = [], ?string $altText = null): Icon
2831
{
2932
$name = $this->normalizeIconName($name);
3033

31-
if (!isset($this->icons[$name])) {
34+
if (!isset($this::$icons[$name])) {
3235
throw new IconNotFoundException(\sprintf('Icon `%s` not found', $name));
3336
}
3437

35-
return new Icon($name, $this->icons[$name], \array_merge($this->attributes, $attributes), $altText);
38+
return new Icon($name, $this::$icons[$name], \array_merge($this->attributes, $attributes), $altText);
3639
}
3740

3841
public function addAlias(string $alias, string $iconName): self
@@ -41,7 +44,7 @@ public function addAlias(string $alias, string $iconName): self
4144
throw new AliasDefinedException(\sprintf('Alias `%s` already defined', $alias));
4245
}
4346

44-
if (!isset($this->icons[$iconName])) {
47+
if (!isset($this::$icons[$iconName])) {
4548
throw new IconNotFoundException(\sprintf('Icon `%s` not found', $iconName));
4649
}
4750

0 commit comments

Comments
 (0)