elgentos/parser

Elgentos Parser for json/yaml files to readable array

3.0.0 2021-09-15 19:11 UTC

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.