class CachingFactoryDecorator implements ChoiceListFactoryInterface
Caches the choice lists created by the decorated factory.
Methods
static string | generateHash(mixed $value, string $namespace = '') Generates a SHA-256 hash for the given value. | |
__construct(ChoiceListFactoryInterface $decoratedFactory) Decorates the given factory. | ||
ChoiceListFactoryInterface | getDecoratedFactory() Returns the decorated factory. | |
ChoiceListInterface | createListFromChoices(array|Traversable $choices, null|callable $value = null) Creates a choice list for the given choices. | |
ChoiceListInterface | createListFromLoader(ChoiceLoaderInterface $loader, null|callable $value = null) Creates a choice list that is loaded with the given loader. | |
ChoiceListView | createView(ChoiceListInterface $list, null|array|callable $preferredChoices = null, null|callable $label = null, null|callable $index = null, null|callable $groupBy = null, null|array|callable $attr = null) Creates a view for the given choice list. |
Details
static string generateHash(mixed $value, string $namespace = '')
Generates a SHA-256 hash for the given value.
Optionally, a namespace string can be passed. Calling this method will the same values, but different namespaces, will return different hashes.
__construct(ChoiceListFactoryInterface $decoratedFactory)
Decorates the given factory.
ChoiceListFactoryInterface getDecoratedFactory()
Returns the decorated factory.
ChoiceListInterface createListFromChoices(array|Traversable $choices, null|callable $value = null)
Creates a choice list for the given choices.
The choices should be passed in the values of the choices array.
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.
ChoiceListInterface createListFromLoader(ChoiceLoaderInterface $loader, null|callable $value = null)
Creates a choice list that is loaded with the given loader.
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.
ChoiceListView createView(ChoiceListInterface $list, null|array|callable $preferredChoices = null, null|callable $label = null, null|callable $index = null, null|callable $groupBy = null, null|array|callable $attr = null)
Creates a view for the given choice list.
Callables may be passed for all optional arguments. The callables receive the choice as first and the array key as the second argument.
- The callable for the label and the name should return the generated label/choice name.
- The callable for the preferred choices should return true or false, depending on whether the choice should be preferred or not.
- The callable for the grouping should return the group name or null if a choice should not be grouped.
- The callable for the attributes should return an array of HTML attributes that will be inserted in the tag of the choice.
If no callable is passed, the labels will be generated from the choice keys. The view indices will be generated using an incrementing integer by default.
The preferred choices can also be passed as array. Each choice that is contained in that array will be marked as preferred.
The attributes can be passed as multi-dimensional array. The keys should match the keys of the choices. The values should be arrays of HTML attributes that should be added to the respective choice.
Please login to continue.