CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.3 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.3
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
      • Exception
      • Locator
      • Paging
        • Exception
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

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.

Namespace: Cake\Datasource\Paging

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
$this

create() ¶ 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|null

Builder 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
static

fromCallable() ¶ public static

fromCallable(Closure $factory): static

Create builder from callable factory.

Parameters
Closure $factory

Closure that receives builder and returns it

Returns
static

resolve() ¶ 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>|null

Array 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
$this

toArray() ¶ 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>

Property Detail

$isSimpleArray ¶ protected

Type
bool

$map ¶ protected

Type
array<string, array<Cake\Datasource\Paging\SortField|string>|string>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs