elgentos/parser

Elgentos 解析器,用于将 json/yaml 文件转换为可读数组

3.0.0 2021-09-15 19:11 UTC

README

将 json/yaml/csv/text 内容解析为可用数组

描述

使用此库将您的日常配置转换为可用的数组/对象。

支持 json、yaml、csv、xml 和纯文本。

<?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');

安装

在您的项目中使用需要

composer require elgentos/parser

要支持 YAML,还需要

composer require symfony/yaml

指令

您可以在文件中使用指令。

@import

直接在当前文件中加载其他文件的内容。

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

递归读取目录。

base:
  "@import-dir": "path/to/directory"
{
  "base": {"@import-dir": "path/to/directory"}
}

自定义

由于服务合同,您可以轻松添加自己的功能

  • 规则 \Elgenttos\Parser\Interfaces\RuleInterface
  • 匹配器 \Elgenttos\Parser\Interfaces\MatcherInterface
  • 解析器 \Elgenttos\Parser\Interfaces\RuleInterface
  • 故事 \Elgenttos\Parser\Interfaces\StoriesInterface

自动创建对象

技术描述

关于我们的技术文档 docs/technical.md