Eno\Section » list
list() → array
list($options) → array
list($loader) → array
list($loader, $options) → array
Retrieve the items of a list, optionally supplying a loader and options.
enocolors:
- pink
- peach
textures:
-
php$document = Parser::parse($input);
$document->list('colors'); // returns [ 'pink', 'peach' ]
$document->list('sounds'); // returns []
$document->list('textures'); // throws a ValidationError
$document->list('textures', [ 'enforce_values' => false ]); // returns [ null ]
$document->list('sounds', [ 'required' => true ]); // throws a ValidationError
$document->list('sounds', [ 'enforce_element' => true ]); // throws a ValidationError
$document->list('colors', function($value) { return strtoupper($value); }); // returns [ 'PINK', 'PEACH' ]
$document->list('colors', function($value) { // throws a ValidationError
if($value == 'peach') {
throw new Exception('Peach may not be on the list!');
}
return "I like {$value}";
]);
$document->list('colors', [ 'with_elements': true ]);
// returns [{ element: [Field value="pink"], 'value' => 'pink' },
// { element: [Field value="pink"], 'value' => 'peach' }]
$document->list('colors', [ 'min_count' => 3 ]); // throws a ValidationError
Parameters
$nameThe name of the list to return as a string.
$loaderA function
returning the transformed/validated value or throwing an error.
(The function is applied to each list item on its own, and its argument
signature is dynamic, you can either use ($value)
or ($name, $value)
)
enforce_element
Whether the list must be present in the document (defaults to false
)
enforce_values
Whether empty list items (-
in the document, mapping to null
) are disallowed (defaults to true
)
exact_count
Validate that there are exactly n
items in the list (takes a number, defaults to null
)
min_count
Validate that there are at least n
items in the list (takes a number, defaults to null
)
max_count
Validate that there are at most n
items in the list (takes a number, defaults to null
)
required
Alias for enforce_element
(this exists on many methods and depending on context refers to either element or value)
with_elements
Whether to return an array of arrays of the form [ 'element' => ..., 'value' => ... ]
instead of just the values (defaults to false
)
Return value
The (optionally transformed/validated) values of the items of this list as an array.With with_elements
set to true
it returns an array of arrays of the form [ 'element' => ..., 'value' => ... ]
instead.