sndsgd/yaml

PHP 的 YAML 解析增强

v0.0.7 2023-03-15 15:43 UTC

This package is auto-updated.

Last update: 2024-09-15 19:07:19 UTC


README

Latest Version Software License Build Status

PHP 的 YAML 解析增强。

上下文

sndsgd\yaml\ParserContext 对象是一个数据包,您可以将其用于回调函数中。

回调函数

您可以通过实现 sndsgd\yaml\Callback 来定义自己的回调函数。此存储库包含一个示例:sndsgd\yaml\callbacks\SecondsCallback

解析

  1. 使用所有回调函数创建解析器实例

    $parser = new sndsgd\yaml\Parser(
        new sndsgd\yaml\ParserContext(),
        sndsgd\yaml\callbacks\SecondsCallback::class,
        your\fun\CoolCallback::class,
    );
  2. 使用 ->parse(string $yaml, int $maxDocuments) 解析字符串

  3. 使用 ->parseFile(string $path, int $maxDocuments) 解析文件