consolidation/comments 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

consolidation/comments

最新稳定版本:2.0.0

Composer 安装命令:

composer require consolidation/comments

包简介

A tool for preserving comments, e.g. when parsing YAML files.

README 文档

README

A tool for preserving comments, e.g. when parsing YAML files.

Build Status Windows Build Scrutinizer Code Quality Coverage Status License

Component Status

Prototype.

Motivation

Do lightweight editing on YAML files and then rewrite the file without losing embedded comments.

Usage

// First step: read the file, parse the yaml, edit and dump the results.

$original_contents = file_get_contents($filepath);
$parsed_data = Yaml::parse($original_contents);
$processed_data = $this->my_processing_function($parsed_data);
$altered_contents = Yaml::dump($parsed_data, PHP_INT_MAX, 2, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK);

// Second step: collect comments from original document and inject them into result.

$commentManager = new Comments();
$commentManager->collect(explode("\n", $original_contents));
$altered_with_comments = $commentManager->inject(explode("\n", $altered_contents));

$result = implode("\n", $altered_with_comments);

Limitations

The comment manager collects groups of comment lines and associates them with the first non-blank content line that follows the comment. If there are multiple non-blank content lines that are exactly the same, then the comment lines are re-injected in the same order they appeared in the original file.

Installation

$ composer require consolidation/comments

Comparison to Existing Solutions

See Klausi's yaml_comments.

统计信息

  • 总下载量: 7.31M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 1
  • 依赖项目数: 12
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04