Eno\Fieldset » entry

entry($name) → value or null
entry($name, $options) → array/value or null
entry($name, $loader) → value or null
entry($name, $loader, $options) → array/value or null

Retrieve an entry's value from the fieldset, optionally supplying a loader to validate and/or transform the value, and/or an options array.

enoQ&A:
Meaning = 42
Green = Yes
Purpose =
php$document = Parser::parse($input);
$qa = $document->fieldset('Q&A');

$qa->entry('Meaning');   // returns '42'
$qa->entry('Purpose');   // returns null

$qa->entry('Purpose', [ 'required' => true ]);   // throws a ValidationError
$qa->entry('Purpose', [ 'enforce_element' => true ]);   // returns null
$qa->entry('Beige', [ 'enforce_element' => true ]);   // throws a ValidationError

$qa->entry('Green', function($value) { return strtoupper($value); });   // returns 'YES'

$qa->entry('Meaning', function($value) {   // throws a ValidationError
  if($value === '42') {
    throw new Exception("That one's getting old!");
  }
  
  return $value;
});

$qa->entry('Meaning', [ 'with_element' => true ]);
  // returns [ 'element' => [Field name="Meaning" value="42"], 'value' => '42' ]

Parameters

$name

The name of the entry as a string.

$loader

A function returning the transformed/validated value or throwing an error.(The function argument signature is dynamic, you can either use ($value) or($name, $value))

$options

enforce_element

Whether the entry must be present in the document (true or false, defaults to false)

enforce_value

Whether there must be a value or the entry is allowed to be empty (default to false)

required

Alias for enforce_value (this exists on many methods and depending on context refers to either element or value)

with_element

Whether to return an array with both the element and the value (defaults to false)

Return value

The entry's value, or null if empty.