Generic data/config loader with advanced features
$loader = Loader::create();
$data = $loader->load('my.yaml');
- JSON
- JSON5 (comments, trailing commas, etc)
- YAML
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
You can reference other variables anywhere in your files:
preferences:
color: green
text: My favorite color is {{hello.color}}!
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);
}
)
You can also use variables in references:
license: MIT
licenseUrl: https://opensource.org/licenses/{{ config.license }}
MIT. Please refer to the license file for details.
Check out our other projects at linkorb.com/engineering.
Btw, we're hiring!