CoolCMS API

FilterBuilder
in package

Table of Contents

Constants

BOOL_OPTIONS  : array<string|int, mixed> = ['isNull', 'inclusive']
Options handed to `bool` typed filter constructor parameters.
GROUP_TYPES  : array<string|int, mixed> = ['group', 'or', 'and']
Normalized types whose `filters` key holds nested filter definitions.
STRING_OPTIONS  : array<string|int, mixed> = ['matchType', 'operator', 'format', 'logic', 'm...
Options handed to `string` typed filter constructor parameters.

Methods

buildFilter()  : Filter
Returns a ready filter as is and builds a filter from an array definition.
buildFilters()  : array<string|int, Filter>
isBuildable()  : bool
Returns whether {@see self::buildFilters()} can build this external (JSON / query string) filter list without a PHP error.
boolOption()  : bool
bound()  : mixed
Returns a range bound: `value` as a `[from, to]` pair, otherwise `from` / `to` from the definition.
buildFilterFromArray()  : Filter
Builds a filter from an array definition.
buildFulltextFilter()  : Filter
Builds a fulltext filter.
fields()  : array<string|int, string>|string
Returns the filter columns; constructors take `array|string $fields` (non-empty column names).
hasBuildableOptions()  : bool
hasBuildableShape()  : bool
isFieldShape()  : bool
Filter constructors take `array|string $fields`; an array must list column names.
nestedDefinitions()  : array<string|int, mixed>
Returns the nested definitions of a group filter (`filters`).
normalizeType()  : string
Normalizes a filter type to lowercase without separators or the `Filter` suffix.
readField()  : mixed
readType()  : mixed
Positional `[type, field, value]` or named `{type, field, value}` definition.
stringOption()  : string

Constants

BOOL_OPTIONS

Options handed to `bool` typed filter constructor parameters.

private array<string|int, mixed> BOOL_OPTIONS = ['isNull', 'inclusive']

GROUP_TYPES

Normalized types whose `filters` key holds nested filter definitions.

private array<string|int, mixed> GROUP_TYPES = ['group', 'or', 'and']

STRING_OPTIONS

Options handed to `string` typed filter constructor parameters.

private array<string|int, mixed> STRING_OPTIONS = ['matchType', 'operator', 'format', 'logic', 'mode']

Methods

buildFilter()

Returns a ready filter as is and builds a filter from an array definition.

public static buildFilter(Filter|array<string|int, mixed> $filter) : Filter
Parameters
$filter : Filter|array<string|int, mixed>
Return values
Filter

buildFilters()

public static buildFilters(array<string|int, mixed> $filters) : array<string|int, Filter>
Parameters
$filters : array<string|int, mixed>

ready filters or their array definitions

Return values
array<string|int, Filter>

isBuildable()

Returns whether {@see self::buildFilters()} can build this external (JSON / query string) filter list without a PHP error.

public static isBuildable(array<string|int, mixed> $filters) : bool

Without this check a malformed definition ([true], a non-string type, an unknown type, a broken nested group) would end as a TypeError or InvalidArgumentException (HTTP 500). Type checks cover exactly what the builder hands to typed parameters and cast nothing; value-level rules (unknown or missing type, operator or logic outside the allowed set) live only in the builder and the filter constructors, so a dry build is the final check.

Parameters
$filters : array<string|int, mixed>
Tags
phpstan-assert-if-true

array<FilterInterface|array<array-key, mixed>> $filters

Return values
bool

boolOption()

private static boolOption(array<string|int, mixed> $filter, string $key, bool $default) : bool
Parameters
$filter : array<string|int, mixed>
$key : string
$default : bool
Return values
bool

bound()

Returns a range bound: `value` as a `[from, to]` pair, otherwise `from` / `to` from the definition.

private static bound(mixed $value, int $index, mixed $fallback) : mixed

IMPORTANT: a string value is not indexed; 'abc'[0] would yield 'a' as a bound. Only arrays are read by index.

Parameters
$value : mixed
$index : int
$fallback : mixed

buildFilterFromArray()

Builds a filter from an array definition.

private static buildFilterFromArray(array<string|int, mixed> $filter) : Filter
Parameters
$filter : array<string|int, mixed>
Return values
Filter

buildFulltextFilter()

Builds a fulltext filter.

private static buildFulltextFilter(array<string|int, string>|string $field, mixed $value[, array<string|int, mixed> $filter = [] ]) : Filter
Parameters
$field : array<string|int, string>|string
$value : mixed
$filter : array<string|int, mixed> = []
Return values
Filter

fields()

Returns the filter columns; constructors take `array|string $fields` (non-empty column names).

private static fields(array<string|int, mixed> $filter) : array<string|int, string>|string
Parameters
$filter : array<string|int, mixed>
Return values
array<string|int, string>|string

hasBuildableOptions()

private static hasBuildableOptions(array<string|int, mixed> $filter) : bool
Parameters
$filter : array<string|int, mixed>
Return values
bool

hasBuildableShape()

private static hasBuildableShape(array<string|int, mixed> $filters) : bool
Parameters
$filters : array<string|int, mixed>
Tags
phpstan-assert-if-true

array<FilterInterface|array<array-key, mixed>> $filters

Return values
bool

isFieldShape()

Filter constructors take `array|string $fields`; an array must list column names.

private static isFieldShape(mixed $field) : bool
Parameters
$field : mixed
Tags
phpstan-assert-if-true

array|string $field

Return values
bool

nestedDefinitions()

Returns the nested definitions of a group filter (`filters`).

private static nestedDefinitions(array<string|int, mixed> $filter) : array<string|int, mixed>
Parameters
$filter : array<string|int, mixed>
Return values
array<string|int, mixed>

normalizeType()

Normalizes a filter type to lowercase without separators or the `Filter` suffix.

private static normalizeType(string $type) : string
Parameters
$type : string
Return values
string

readField()

private static readField(array<string|int, mixed> $filter) : mixed
Parameters
$filter : array<string|int, mixed>

readType()

Positional `[type, field, value]` or named `{type, field, value}` definition.

private static readType(array<string|int, mixed> $filter) : mixed
Parameters
$filter : array<string|int, mixed>

stringOption()

private static stringOption(array<string|int, mixed> $filter, string $key, string $default) : string
Parameters
$filter : array<string|int, mixed>
$key : string
$default : string
Return values
string
On this page

Search results