PHPackages                             t2l/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. t2l/comments

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

t2l/comments
============

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

1.1.0(6y ago)0194.0k—2.1%1MITPHPPHP &gt;=5.5.0

Since Nov 5Pushed 6y agoCompare

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

READMEChangelog (1)Dependencies (4)Versions (7)Used By (1)

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

[](#consolidationcomments)

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

[![Build Status](https://camo.githubusercontent.com/de206b1401106e05b5bcc8c5290f5be799c67233183532e398ad07e9565fa8a0/68747470733a2f2f7472617669732d63692e6f72672f54324c2f636f6d6d656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/T2L/comments)[![codecov](https://camo.githubusercontent.com/d3d19096a1fd5948edbb6c4f65d050cfba9ffb770ae0cd0edd6be015f5b41f6d/68747470733a2f2f636f6465636f762e696f2f67682f54324c2f636f6d6d656e74732f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/T2L/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

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 59.4% 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 ~301 days

Total

4

Last Release

2212d ago

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

1.0.2PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ceb7276d70d3cf1279f9009afcd17f0585414ec3628578af3fa5965928cd2f61?d=identicon)[T2L](/maintainers/T2L)

---

Top Contributors

[![T2L](https://avatars.githubusercontent.com/u/492138?v=4)](https://github.com/T2L "T2L (19 commits)")[![greg-1-anderson](https://avatars.githubusercontent.com/u/612191?v=4)](https://github.com/greg-1-anderson "greg-1-anderson (12 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/t2l-comments/health.svg)

```
[![Health](https://phpackages.com/badges/t2l-comments/health.svg)](https://phpackages.com/packages/t2l-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)
