项目作者: elgentos

项目描述 :
Use this library to turn your day-to-day configurations into usable arrays/objects.
高级语言: PHP
项目地址: git://github.com/elgentos/parser.git
创建时间: 2018-07-18T07:51:25Z
项目社区:https://github.com/elgentos/parser

开源协议:MIT License

下载


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.

  1. <?php
  2. /**
  3. * Read a file, import recursive and return a merged array
  4. */
  5. $data = Elgentos\Parser::readFile('file.json');
  1. <?php
  2. /**
  3. * Read a file, no recursion
  4. */
  5. $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

  1. othercontent:
  2. "@import": path/to/other/file.yaml

JSON

  1. {
  2. "othercontent": {"@import": "path/to/otherfile.yaml" }
  3. }

CSV

  1. "@import"
  2. "path/to/file.json"
  3. "path/to/otherfile.yaml"
  4. "path/to/file2.yaml"

@import-dir

Read a directory recursively.

  1. base:
  2. "@import-dir": "path/to/directory"
  1. {
  2. "base": {"@import-dir": "path/to/directory"}
  3. }

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.