Repository navigation
Expand file tree
/
Copy pathTableConfigurationException.php
More file actions
186 lines (163 loc) · 6.84 KB
/
Copy pathTableConfigurationException.php
File metadata and controls
186 lines (163 loc) · 6.84 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
declare(strict_types=1);
namespace NyonCode\WireTable\Exceptions;
use InvalidArgumentException;
use NyonCode\WireCore\Core\Query\Search\SearchValueType;
use NyonCode\WireCore\Foundation\Contracts\WireException;
/**
* Thrown when a table is handed an argument its definition cannot accept.
*
* Extends InvalidArgumentException because every site it replaces threw one —
* the SPL base is part of the published behaviour, so it is preserved verbatim.
* A bad table *state* (rather than a bad argument) is
* {@see TableHasNoDataSourceException}, which stays a RuntimeException for the
* same reason.
*/
final class TableConfigurationException extends InvalidArgumentException implements WireException
{
public static function invalidPollInterval(): self
{
return new self('Interval must be like "5s", "500ms", "10m" or "1h".');
}
public static function invalidPerPageOption(mixed $option): self
{
$given = is_scalar($option) ? (string) $option : get_debug_type($option);
return new self("Page size [{$given}] is not a positive whole number.");
}
public static function invalidNotificationDriver(mixed $configured): self
{
$given = is_string($configured) ? $configured : get_debug_type($configured);
return new self(
"wire-table.notification_driver [{$given}] is not a NotificationDriver; name a class implementing "
.'NyonCode\WireCore\Notifications\Contracts\NotificationDriver, or null for the global default.'
);
}
public static function relationPathNotGroupable(string $column): self
{
return new self(
"groupBy() only supports direct columns, got [{$column}]. ".
'Expose the related value as a column on the query (join/select alias) and group by that.'
);
}
/**
* @param array<int, string> $valid
*/
public static function unknownSearchValueType(string $type, array $valid): self
{
return new self(
"Unknown search value type [{$type}]. Valid types: ".implode(', ', $valid).'.'
);
}
/**
* A declared search value type the table's search box can never ask for.
*
* The series of a structured code arrives as its own word — `8866 01..08`
* is the word `8866` and the range `01..08` — so a code column is only
* whole once the term is split as well, and the suggested line says so.
*/
public static function searchValueTypeNeedsRanges(string $column, SearchValueType $type): self
{
$call = $type === SearchValueType::Code
? '->search(fn (SearchConfig $s) => $s->tokenize()->ranges())'
: '->search(fn (SearchConfig $s) => $s->ranges())';
return new self(
"Column [{$column}] declares searchAs('{$type->value}'), but this table's search does not read ".
'ranges, so the comparison it allows can never be typed into the box — the term is matched as '.
"literal text and the table comes back empty. Add {$call} to the table, or drop the declaration."
);
}
/**
* @param array<int, string> $valid
*/
public static function unknownSummaryType(string $type, array $valid): self
{
return new self(
"Unknown summary type [{$type}]. Valid types: ".implode(', ', $valid).'.'
);
}
/**
* @param array<int, string> $valid
*/
public static function unknownGesture(string $capability, array $valid): self
{
return new self(
"Unknown table gesture [{$capability}]. Valid gestures: ".implode(', ', $valid).'.'
);
}
/**
* @param array<int, string> $valid
*/
public static function unknownInactiveRowOption(string $option, array $valid): self
{
return new self(
"Unknown inactive-row option [{$option}]. Valid options: ".implode(', ', $valid).'.'
);
}
public static function recordActionInRowActions(): self
{
return new self(
'A RecordAction cannot be registered in actions(). '.
'Action::make()->onDoubleClick() returns a RecordAction — pass it to '.
'recordAction()/recordActions() instead.'
);
}
public static function cannotConfigureReferencedRecordAction(string $method, string $name): self
{
return new self(
"Cannot call {$method}() on the record action referencing [{$name}]: a ".
'reference by name has no action of its own to configure. Configure it '.
'where it is declared in actions(), or wrap an Action instead of naming one.'
);
}
/**
* @param array<int, string> $reserved
*/
public static function reservedRecordActionKey(string $key, array $reserved): self
{
return new self(
"onKey('{$key}') collides with the table's built-in keyboard navigation — ".
'the key is reserved and the shortcut could never fire. Reserved keys: '.
implode(', ', array_filter($reserved)).'. Bind a different key instead.'
);
}
public static function genericEditorNotRendered(string $column): self
{
return new self(
"Column [{$column}]: editable() cannot choose an editor — an ordinary ".
'column renders no editor at all, whatever type is named. Use the column '.
'that renders the one you want: TextInputColumn, SelectColumn, '.
'ToggleColumn or CheckboxColumn. editable(bool) still switches editing '.
'on and off for those.'
);
}
public static function fixedFilterOptions(string $filter): self
{
return new self(
"TrashedFilter::make('{$filter}')->options() cannot be set: the filter ".
'switches the soft-delete scope rather than matching values, so its two '.
'options are fixed. Rename them with withTrashedLabel() / onlyTrashedLabel().'
);
}
public static function modelIsNotSoftDeletable(string $filter, string $model): self
{
return new self(
"TrashedFilter::make('{$filter}') needs soft deletes, but [{$model}] does not ".
'use the SoftDeletes trait. Add the trait (and a deleted_at column), or drop '.
'the filter from the table.'
);
}
public static function subRowRelationMissing(string $relation, string $model): self
{
return new self(
"subRows('{$relation}') expects a relationship method [{$relation}()] on ".
"[{$model}], but none exists. Check the spelling, or define the relationship."
);
}
public static function subRowsNotConfigured(string $method): self
{
return new self(
"{$method}() reads a record's children, but the table names no relationship ".
'for them. Call subRows(\'relation\') on the table first.'
);
}
}