2017 © Pedro Peláez
 

library comments

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

image

consolidation/comments

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

  • Wednesday, November 8, 2017
  • by greg.1.anderson
  • Repository
  • 0 Watchers
  • 1 Stars
  • 196 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 39 % Grown

The README.md

Consolidation\Comments

A tool for preserving comments, e.g. when parsing YAML files., (*1)

Build Status Windows Build Scrutinizer Code Quality Coverage Status License, (*2)

Component Status

Prototype., (*3)

Motivation

Do lightweight editing on YAML files and then rewrite the file without losing embedded comments., (*4)

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., (*5)

Installation

$ composer require consolidation/comments, (*6)

Comparison to Existing Solutions

See Klausi's yaml_comments., (*7)

The Versions

08/11 2017

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

08/11 2017

1.0.1

1.0.1.0

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

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

05/11 2017

1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires