elgentos / parser
Elgentos Parser for json/yaml files to readable array
Installs: 29 672
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 17
Forks: 1
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/yaml: ^3.4 || ^4.0 || ^5.0
Suggests
- symfony/yaml: Install symfony/yaml to support yaml parsing
README
Parse content from json/yaml/csv/text to a usable array
Description
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');
Instalation
To use in your project require
composer require elgentos/parser
To support YAML also require:
composer require symfony/yaml
Directives
You can use directives inside your file.
@import
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"
@import-dir
Read a directory recursively.
base: "@import-dir": "path/to/directory"
{ "base": {"@import-dir": "path/to/directory"} }
Customization
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
Automated creation of objects
Technical description
For our technical docs docs/technical.md.