Class SortableFieldsBuilder
Builder for creating complete sortable fields configurations.
Provides interface for building sortable fields with multiple sort keys and fields. Also handles resolution of sort keys to database ORDER BY clauses.
Property Summary
-
$isSimpleArray protected
bool -
$map protected
array<string, array<Cake\Datasource\Paging\SortField|string>|string>
Method Summary
-
add() public
Add a sort key with its associated SortField objects.
-
create() public static
Create builder from various sortableFields configurations.
-
fromArray() public static
Create builder from array configuration.
-
fromCallable() public static
Create builder from callable factory.
-
resolve() public
Resolve a sort key to its corresponding ORDER BY clause.
-
resolveArrayMapping() protected
Resolve an array mapping to ORDER BY clause.
-
resolveMapping() protected
Resolve a mapping configuration to ORDER BY clause.
-
set() protected
Set a sort key with type-safe validation.
-
toArray() public
Return the complete sortable fields map.
Method Detail
add() ¶ public
add(string $sortKey, Cake\Datasource\Paging\SortField|string ...$fields): $this
Add a sort key with its associated SortField objects.
Parameters
-
string$sortKey The sort key name
-
Cake\Datasource\Paging\SortField|string...$fields The sort fields to add
Returns
$thiscreate() ¶ public static
create(Closure|array<mixed>|null $config): static|null
Create builder from various sortableFields configurations.
Parameters
-
Closure|array<mixed>|null$config The sortableFields configuration
Returns
static|nullBuilder instance or null if no config
fromArray() ¶ public static
fromArray(array<mixed> $config): static
Create builder from array configuration.
Handles both simple array format (['field1', 'field2']) and associative map format (['key' => 'field', ...]).
Parameters
-
array<mixed>$config Array configuration
Returns
staticfromCallable() ¶ public static
fromCallable(Closure $factory): static
Create builder from callable factory.
Parameters
-
Closure$factory Closure that receives builder and returns it
Returns
staticresolve() ¶ public
resolve(string $sortKey, string $direction, bool $directionSpecified = true): array<string, string>|null
Resolve a sort key to its corresponding ORDER BY clause.
Parameters
-
string$sortKey The sort key from URL
-
string$direction The requested direction (asc/desc)
-
bool$directionSpecified optional Whether direction was explicitly specified
Returns
array<string, string>|nullArray of field => direction pairs, or null if invalid
resolveArrayMapping() ¶ protected
resolveArrayMapping(array<mixed> $fields, string $direction, bool $directionSpecified): array<string, string>
Resolve an array mapping to ORDER BY clause.
Parameters
-
array<mixed>$fields Array of fields or SortField objects
-
string$direction The requested direction
-
bool$directionSpecified Whether direction was explicitly specified
Returns
array<string, string>Array of field => direction pairs
resolveMapping() ¶ protected
resolveMapping(mixed $mapping, string $direction, bool $directionSpecified): array<string, string>
Resolve a mapping configuration to ORDER BY clause.
Parameters
-
mixed$mapping The mapping to resolve
-
string$direction The requested direction
-
bool$directionSpecified Whether direction was explicitly specified
Returns
array<string, string>Array of field => direction pairs
set() ¶ protected
set(string $sortKey, mixed $value): $this
Set a sort key with type-safe validation.
Internal method used by fromArray() to ensure type safety while preserving backward compatibility with string and array representations.
Parameters
-
string$sortKey The sort key name
-
mixed$value The sort field(s) - can be string, SortField, or array
Returns
$thistoArray() ¶ public
toArray(): array<string, array<Cake\Datasource\Paging\SortField|string>|string>
Return the complete sortable fields map.
Returns
array<string, array<Cake\Datasource\Paging\SortField|string>|string>