horde/yaml
Composer 安装命令:
composer require horde/yaml
包简介
Roundtrip-capable YAML parsing and writing library
README 文档
README
Pedantic, lossless and pure-PHP YAML 1.2 parser with byte-identical round-trip.
This library ships with two layers:
- Legacy
Horde_Yaml: array-only loader/dumper kept for backwards compatibility with existing Horde components. - Modern
Horde\Yaml\Document: comment-preserving load/edit/dump pipeline with a public AST, anchor and alias support, and atomic file writes. Targets configuration files like.horde.ymlthat must round-trip through human and machine edits.
The two layers live side by side. New code should use the document layer.
Highlights
- 100% YAML 1.2 conformance. All 391 cases from the upstream yaml-test-suite pass: every spec example loads as the spec says it should, every malformed input is rejected.
- Byte-identical round-trip. Loading a source file and dumping it back without mutation produces the exact same bytes. Comments, blank lines, end-of-line spacing, quoting style, and flow layout all survive.
- Comments and trivia are first-class AST nodes. Standalone comments live as siblings of map entries and sequence items. EOL comments are properties of their entry. Stream- and document-level trivia have their own slots. Position-based insert / remove / replace is supported on every container.
- Strict by default, lenient on opt-in.
LeniencyPolicy::strictYaml12()is the conformance baseline.LeniencyPolicy::hordeCompat()keeps the historical tolerance for existing.horde.ymlfiles (legacy booleans, malformed directives, undefined tag handles, etc.). - Pure PHP, no extensions. ext-mbstring is the only requirement. No libyaml, no shell-out.
Conformance table
| Suite | Cases | Pass |
|---|---|---|
| yaml-test-suite (YAML 1.2 reference) | 391 | 391 (100%) |
| Round-trip probe (comments, whitespace, trivia) | 15 | 15 (100%) |
| Unit tests | 1401 | 1401 (100%) |
Requirements
- PHP 8.2 or later (8.1 for the legacy parser)
- ext-mbstring
Installation
composer require horde/yaml
Document layer at a glance
use Horde\Yaml\Document\YamlFileLoader; use Horde\Yaml\Document\YamlFileDumper; $loader = new YamlFileLoader(); $dumper = new YamlFileDumper(); $stream = $loader->load('config.yml'); $doc = $stream->document(0); $doc->setEntry('name', 'kronolith'); $doc->setEntry('version', '6.0.0'); $dumper->dump($stream, 'config.yml');
A clean round-trip (load and dump without mutation) reproduces the
source byte-for-byte. After mutation, every untouched part of the
file stays exactly as it was: comments, blank lines, the spacing
before EOL comments, single vs double quotes, and the layout of
multi-line flow collections. See
doc/examples/byte-identical-roundtrip.php for a runnable proof.
To insert a comment at a specific position, use the container's positional API:
$authors->insertCommentBefore(2, '# Joined the project in 2026.');
See doc/examples/splice-comment.php.
See doc/USAGE.md for the full API and doc/examples/ for runnable
snippets.
Documentation
doc/USAGE.md: document layer API guidedoc/UPGRADING.md: migration notes fromHorde_Yamldoc/examples/: runnable PHP snippetsdoc/changelog.yml: release history
Testing
phpunit # unit + integration suites phpunit -c phpunit-perf.xml.dist # performance gates
The performance suite expects a snapshotted .horde.yml corpus at
test/fixtures/perf/horde-yml-corpus/. Refresh it from a local
component checkout via:
./scripts/snapshot-horde-yml-corpus.sh
Conformance against the upstream yaml-test-suite is opt-in; run
git submodule update --init to fetch the cases, then re-run the
default suite. Triage status lives in
test/fixtures/conformance/yaml-test-suite-status.php.
License
LGPL-2.1. See LICENSE.
horde/yaml 适用场景与选型建议
horde/yaml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.11k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「lossless」 「compliant」 「roundtrip」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 horde/yaml 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 horde/yaml 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 horde/yaml 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Register, configure and ask for cookies consent in a EU-compliant way.
Optimize uploaded/processed images with binaries of your choice
Commands for the TYPO3 Scheduler and command line
Control which cookies/services gets loaded when user enters website, to make it GDPR compliant
TYPO3 CMS extension for embedding YouTube and Vimeo videos GDPR compliant
A PHP CLI package that provides the developer with the means to generate PHP related files, like classes and .ini's, in a variety of different levels of both simplicity and complexity.
统计信息
- 总下载量: 3.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 4
- 推荐数: 2
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2023-10-25