Parse content from json/yaml/csv/text to a usable array
Use this library to turn your day-to-day configurations into usable arrays/objects.
Supports json, yaml, csv, xml and plain text.
<?php
/**
* Read a file, import recursive and return a merged array
*/
$data = Elgentos\Parser::readFile('file.json');
<?php
/**
* Read a file, no recursion
*/
$data = Elgentos\Parser::readSimple('file.json');
To use in your project require
composer require elgentos/parser
To support YAML also require:
composer require symfony/yaml
You can use directives inside your file.
Load content of other files directly in your current file.
YAML
othercontent:
"@import": path/to/other/file.yaml
JSON
{
"othercontent": {"@import": "path/to/otherfile.yaml" }
}
CSV
"@import"
"path/to/file.json"
"path/to/otherfile.yaml"
"path/to/file2.yaml"
Read a directory recursively.
base:
"@import-dir": "path/to/directory"
{
"base": {"@import-dir": "path/to/directory"}
}
Due Service Contracts you can easily add your own functionality:
- Rules
\Elgenttos\Parser\Interfaces\RuleInterface
- Matcher
\Elgenttos\Parser\Interfaces\MatcherInterface
- Parser
\Elgenttos\Parser\Interfaces\RuleInterface
- Stories
\Elgenttos\Parser\Interfaces\StoriesInterface
For our technical docs docs/technical.md.