Eno\Loaders

enophp provides a set of core loaders for important types that are available out of the box (in addition to the possiblity to define your own custom loaders, which can be passed as parameter to all accessors).

The loaders are exposed through the API as drop in replacements to the standard accessors:

  • Field
    • value() => [loaderName]()
  • Fieldset
    • entry() => [loaderName]()
  • ListElement
    • items() => [loaderName]Items()
  • Section
    • field() => [loaderName]()
    • list() => [loaderName]List()

So for instance, instead of calling ...

$document->field('done', [ 'required' => true ]);  // returns 'yes'
$document->list('visitor_counts', [ 'required' => true ]);  // returns [ '476', '213', '330', ... ]

... you can just replace field or augment list with the loader name ...

$document->boolean('done', [ 'required' => true ]);  // returns true
$document->integerList('visitor_counts', [ 'required' => true ]);  // returns [ 476, 213, 330, ... ]

Here's another full example:

use Eno\Parser;

$doc = Parser::parse(
<<<DOC
  publish: yes
  location: 36.987094, -25.091719
  contact: contact@faulty
DOC
);

$doc->boolean('publish');
  // returns true

$doc->latLng('location');
  // returns [
  //   'lat' =>  36.987094,
  //   'lng' => -25.091719
  // ]

$doc->email('contact');
  // throws a ValidationError: 'contact' must contain a valid email address, for instance 'jane.doe@eno-lang.org'.

Note that some loaders only perform validation and return their input unaltered as string (e.g. color, email), while others both validate and transform the value into a new type (e.g. float, boolean) or even associative array (e.g. latLng).

Subpages

boolean
color
commaSeparated
date
datetime
float
integer
json
latLng
number
string
url