Repository navigation
Expand file tree
/
Copy pathIconSetRegistrationException.php
More file actions
108 lines (95 loc) · 4.11 KB
/
Copy pathIconSetRegistrationException.php
File metadata and controls
108 lines (95 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare(strict_types=1);
namespace NyonCode\WireCore\Exceptions;
use InvalidArgumentException;
use NyonCode\WireCore\Foundation\Contracts\WireException;
/**
* Thrown when an icon set cannot be registered as declared — under a prefix that
* would make icon resolution ambiguous, or from a config entry that does not
* name a set at all.
*
* Every message spells out the working form, because the caller is registering a
* set once at boot and has no other feedback loop. That is also why the config
* cases throw rather than skipping: an entry that is quietly ignored costs a set
* of icons that render as the missing-icon placeholder, with nothing anywhere
* connecting the two. Config is read at boot, so none of these can reach a
* request.
*/
final class IconSetRegistrationException extends InvalidArgumentException implements WireException
{
public static function prefixReserved(): self
{
return new self(
'Only the bundled Heroicons set is available unprefixed. Register additional '
.'icon sets under a unique prefix, e.g. registerIconSet($set, "lucide"), and '
.'reference their icons as "lucide:home".'
);
}
public static function prefixContainsColon(string $prefix): self
{
return new self(
"Icon set prefix [{$prefix}] must not contain a colon; the colon separates "
.'the prefix from the icon name (e.g. "lucide:home").'
);
}
/**
* `wire-core.icons.default_set` names a key `wire-core.icons.sets` does not
* have, so nothing would become the unprefixed base and Heroicons would stay
* — the opposite of what the setting asked for, with no sign of it.
*
* @param array<int, int|string> $keys
*/
public static function defaultSetNotListed(string $defaultSet, array $keys): self
{
$listed = $keys === [] ? 'none' : implode(', ', array_map(strval(...), $keys));
return new self(
"wire-core.icons.default_set is [{$defaultSet}], but wire-core.icons.sets has no "
."set under that key (it lists: {$listed}). Add the set under [{$defaultSet}], or "
.'set default_set to one of the listed keys.'
);
}
/**
* A non-default set declared under a numeric key, so it has no prefix to be
* addressed by.
*/
public static function prefixNotAString(string $class): self
{
return new self(
"Icon set [{$class}] must be configured under a string prefix key in "
.'wire-core.icons.sets (e.g. \'lucide\' => LucideIconSet::class). Only the '
.'set matching wire-core.icons.default_set may be unprefixed.'
);
}
/**
* Something in `wire-core.icons.sets` that cannot be an icon set.
*
* Skipped until now, and that is the failure this replaces: a typo in a class
* name meant the set simply did not exist, and every icon addressed through
* its prefix rendered the placeholder instead.
*/
public static function notAnIconSet(mixed $class, string $contract): self
{
$name = is_string($class) ? $class : get_debug_type($class);
$reason = is_string($class) && (class_exists($class) || interface_exists($class))
? "it does not implement [{$contract}]"
: 'it is not a class that exists';
return new self(
"[{$name}] is listed in wire-core.icons.sets but cannot be registered: {$reason}."
);
}
/**
* An entry in `wire-core.icons.paths` that is not a directory of SVG files.
*
* Same reasoning as {@see notAnIconSet()}: silently ignored, a mistyped path
* costs every icon in that folder and says nothing.
*/
public static function iconDirectoryUnreadable(mixed $path): self
{
$name = is_string($path) ? "[{$path}]" : get_debug_type($path);
return new self(
"{$name} is listed in wire-core.icons.paths but is not a readable directory. "
.'Each entry must be a path to a directory of .svg files; a string key is used '
.'as a name prefix for the icons found there.'
);
}
}