Skip to content

Latest commit

 

History

History
85 lines (67 loc) · 1.66 KB

README.md

File metadata and controls

85 lines (67 loc) · 1.66 KB

Elgentos Content parser Build Status

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.