PHPackages                             consolidation/comments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. consolidation/comments

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

consolidation/comments
======================

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

2.0.0(1y ago)127.5M↓10.6%6[3 PRs](https://github.com/consolidation/comments/pulls)11MITPHPPHP &gt;=8.2

Since Nov 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/consolidation/comments)[ Packagist](https://packagist.org/packages/consolidation/comments)[ RSS](/packages/consolidation-comments/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (8)Used By (11)

Consolidation\\Comments
=======================

[](#consolidationcomments)

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

[![Build Status](https://camo.githubusercontent.com/1ec64b43ee07cb070228d5f259995f3bacc46381dc832978f5c5a45b62cdb2d2/68747470733a2f2f7472617669732d63692e6f72672f636f6e736f6c69646174696f6e2f636f6d6d656e74732e7376673f6272616e63683d6d61696e)](https://travis-ci.org/consolidation/comments)[![Windows Build](https://camo.githubusercontent.com/2ea82ab66522b3f31682f4feec5737d2b769b42fc19d54a2be20a7b015e33e93/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f377832616d78747476767575683770663f7376673d74727565)](https://ci.appveyor.com/project/greg-1-anderson/comments)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8d8e0e7a3c482560ba89153f39f37370e6ac273ac86e8ace542abcbee58c3024/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f6e736f6c69646174696f6e2f636f6d6d656e74732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/consolidation/comments/?branch=main)[![Coverage Status](https://camo.githubusercontent.com/47c46e725767a38c07b44f1fe6bbc22c4b66100ebc5c6188630b799cd435ea20/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f636f6e736f6c69646174696f6e2f636f6d6d656e74732f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/consolidation/comments?branch=main)[![License](https://camo.githubusercontent.com/5d3738c8cafa9d697072a1ca2079eb481fcea050f515a816816f8d423acbe332/68747470733a2f2f706f7365722e707567782e6f72672f636f6e736f6c69646174696f6e2f636f6d6d656e74732f6c6963656e7365)](https://packagist.org/packages/consolidation/comments)

Component Status
----------------

[](#component-status)

Prototype.

Motivation
----------

[](#motivation)

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

Usage
-----

[](#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
-----------

[](#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
------------

[](#installation)

$ composer require consolidation/comments

Comparison to Existing Solutions
--------------------------------

[](#comparison-to-existing-solutions)

See Klausi's [yaml\_comments](https://github.com/klausi/yaml_comments).

###  Health Score

53

—

FairBetter than 97% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~649 days

Total

5

Last Release

520d ago

Major Versions

1.x-dev → 2.0.02024-12-15

PHP version history (3 changes)1.0.0PHP &gt;=5.6.0

1.0.2PHP &gt;=5.5.0

2.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b34cc6bd882277b6c6dda19bf6631ae5c3a909fd667c826a15121642cdc051b2?d=identicon)[greg.1.anderson](/maintainers/greg.1.anderson)

---

Top Contributors

[![greg-1-anderson](https://avatars.githubusercontent.com/u/612191?v=4)](https://github.com/greg-1-anderson "greg-1-anderson (16 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/consolidation-comments/health.svg)

```
[![Health](https://phpackages.com/badges/consolidation-comments/health.svg)](https://phpackages.com/packages/consolidation-comments)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
