Documentation

LazyChoiceList
in package
implements ChoiceListInterface

A choice list that loads its choices lazily.

The choices are fetched using a instance. If only or is called, the choice list is only loaded partially for improved performance.

Once or is called, the list is loaded fully.

Tags
author

Bernhard Schussek bschussek@gmail.com

Table of Contents

Interfaces

ChoiceListInterface
A list of choices that can be selected in a choice field.

Properties

$loader  : mixed
$value  : Closure|null
The callable creating string values for each choice.

Methods

__construct()  : mixed
Creates a lazily-loaded list using the given loader.
getChoices()  : array<string|int, mixed>
Returns all selectable choices.
getChoicesForValues()  : array<string|int, mixed>
Returns the choices corresponding to the given values.
getOriginalKeys()  : array<string|int, int>|array<string|int, string>
Returns the original keys of the choices.
getStructuredValues()  : array<string|int, string>
Returns the values in the structure originally passed to the list.
getValues()  : array<string|int, string>
Returns the values for the choices.
getValuesForChoices()  : array<string|int, string>
Returns the values corresponding to the given choices.

Properties

$value

The callable creating string values for each choice.

private Closure|null $value

If null, choices are cast to strings.

Methods

__construct()

Creates a lazily-loaded list using the given loader.

public __construct(ChoiceLoaderInterface $loader[, callable|null $value = null ]) : mixed

Optionally, a callable can be passed for generating the choice values. The callable receives the choice as first and the array key as the second argument.

Parameters
$loader : ChoiceLoaderInterface
$value : callable|null = null

The callable generating the choice values

getChoices()

Returns all selectable choices.

public getChoices() : array<string|int, mixed>
Return values
array<string|int, mixed>

The selectable choices indexed by the corresponding values

getChoicesForValues()

Returns the choices corresponding to the given values.

public getChoicesForValues(array<string|int, mixed> $values) : array<string|int, mixed>
Parameters
$values : array<string|int, mixed>

An array of choice values. Non-existing values in this array are ignored

Return values
array<string|int, mixed>

getOriginalKeys()

Returns the original keys of the choices.

public getOriginalKeys() : array<string|int, int>|array<string|int, string>
Return values
array<string|int, int>|array<string|int, string>

The original choice keys indexed by the corresponding choice values

getStructuredValues()

Returns the values in the structure originally passed to the list.

public getStructuredValues() : array<string|int, string>
Return values
array<string|int, string>

getValues()

Returns the values for the choices.

public getValues() : array<string|int, string>
Return values
array<string|int, string>

getValuesForChoices()

Returns the values corresponding to the given choices.

public getValuesForChoices(array<string|int, mixed> $choices) : array<string|int, string>
Parameters
$choices : array<string|int, mixed>

An array of choices. Non-existing choices in this array are ignored

Return values
array<string|int, string>

        
On this page

Search results