linkorb/loader

Loader: generic data/config loader with advanced features

v1.2.1 2019-11-25 13:12 UTC

This package is auto-updated.

Last update: 2024-04-25 22:59:12 UTC


README

Generic data/config loader with advanced features

Usage:

$loader = Loader::create();
$data = $loader->load('my.yaml');

Features

File formats:

  • JSON
  • JSON5 (comments, trailing commas, etc)
  • YAML

JSON References ($ref)

You can use json references in any of the supported file formats (json, json5, yaml)

example:

localExample:
  $ref: example.json5
remoteExample:
  $ref: https://example.web/example.json

This will "include" the referenced files as if they were part of the main file.

The file type is determined based on file extension or (in case of remote files) the HTTP response header

Variable interpolation (expressions)

You can reference other variables anywhere in your files:

preferences:
  color: green
text: My favorite color is {{hello.color}}!

Helper functions

You can use various helper functions inside of the variable blocks.

  • strtoupper
  • strtolower
  • ucfirst
  • array_merge_recursive: recursively merge 2 arrays (can be nested multiple times)
  • dict: turn key/value dictionaries into arrays of key+value items

You can register your own helpers too:

$interpolator->register(
  'myHelper',
  function ($arguments, $text) {
    // do something with the input arguments and return
    return ucfirst($text);
  }
)

Variables in references:

You can also use variables in references:

license: MIT
licenseUrl: https://opensource.org/licenses/{{ config.license }}

License

MIT. Please refer to the license file for details.

Brought to you by the LinkORB Engineering team

687474703a2f2f7777772e6c696e6b6f72622e636f6d2f642f6d6574612f74696572312f696d616765732f6c696e6b6f7262656e67696e656572696e672d6c6f676f2e706e67
Check out our other projects at linkorb.com/engineering.

Btw, we're hiring!