klausi/yaml_comments

此包已被废弃,不再维护。没有推荐替代包。

一个支持读取/写入注释行的 YAML 解析器

0.x-dev 2017-03-19 22:20 UTC

This package is not auto-updated.

Last update: 2022-02-01 13:06:07 UTC


README

解析 YAML 并提供与它们的行号以及文档结构的任何给定键的行号相对应的注释。

解析器是从 Symfony YAML 组件 复制并修改的,MIT 许可证 版权 (c) 2004-2017 Fabien Potencier

用法

use Klausi\YamlComments\YamlComments;

$exampleYaml = <<<'EOF'
name: Node
type: module
# Messing up line numbers with comments, yay!
description: 'Allows content to be submitted to the site and displayed on pages.'
package: Core
version: VERSION
core: 8.x
configure: entity.node_type.collection
dependencies:
  - text
  - drupal:rest
  - views
  # Some comment here.
  - rules
EOF;

$parseResult = YamlComments::parse($exampleYaml);

获取此文档的注释行

print_r($parseResult->getComments());
Array
(
    [3] => # Messing up line numbers with comments, yay!
    [13] =>   # Some comment here.
)

获取特定键的行号

print $parseResult->getLineNumber('name');
1
print $parseResult->getLineNumber('description');
4
print $parseResult->getLineNumber(['dependencies', 3]);
14