atk14/mini-yaml
Composer 安装命令:
composer require atk14/mini-yaml
包简介
Minimalistic YAML loader and dumper for PHP supporting nested structures, block scalars and PHP template evaluation
关键字:
README 文档
README
MiniYAML is a minimalistic YAML loader and dumper for PHP. It handles the subset of YAML commonly used for configuration files and API responses.
Why MiniYAML?
- Single file, zero dependencies. Drop
miniyaml.phpinto your project and you are done — no Composer, no autoloader, no transitive dependencies. - Tiny footprint. The entire implementation is ~350 lines of straightforward PHP.
- PHP template evaluation. The built-in
InterpretPHP()method lets you embed<?= $var ?>tags directly in YAML, making it easy to build environment-specific configuration without a separate templating step. No other mainstream YAML library offers this. - Readable API. Three static methods —
Load(),Dump(),InterpretPHP()— cover all common use cases without configuration overhead. - Runs on PHP 5.6 and up. Works on legacy hosting and old codebases where modern libraries have already dropped support.
Installation
composer require atk14/mini-yaml
Usage
Load
$ar = miniYAML::Load($yaml_string);
Options:
| Option | Type | Default | Description |
|---|---|---|---|
nullable |
bool | true |
Treat null and NULL as PHP null |
interpret_php |
bool | false |
Evaluate PHP tags (<?php ... ?>) embedded in the YAML string |
values |
array | [] |
Variables made available when interpret_php is enabled |
// Disable null handling — "null" is kept as a plain string $ar = miniYAML::Load($yaml_string, ["nullable" => false]); // Evaluate embedded PHP $yaml = miniYAML::Load($template, [ "interpret_php" => true, "values" => ["domain" => "example.com"], ]);
Dump
$yaml = miniYAML::Dump($array);
Options:
| Option | Type | Default | Description |
|---|---|---|---|
nullable |
bool | true |
Dump PHP null as NULL; when false, dumps as empty string "" |
$yaml = miniYAML::Dump($array, ["nullable" => false]);
Supported YAML features
Load and Dump:
- Hash (associative) arrays:
key: value - Indexed (list) arrays:
- item - Nested structures of arbitrary depth
- Empty arrays:
[] - Quoted strings:
"value"and'value' null/NULLvalues (controlled by thenullableoption)- Comments: lines starting with
#
Load only:
- Literal block scalars (
|) — newlines preserved - Folded block scalars (
>) — newlines replaced with spaces
Dump only:
- Strings containing newlines are automatically serialized as literal block scalars (
|) - Strings requiring escaping (colons, special characters, YAML keywords, …) are wrapped in double quotes
Example
$yaml = ' --- status: success message: Ok data: domain: example.com admin: - Alice - Bob description: | First line. Second line. '; $ar = miniYAML::Load($yaml); // [ // "status" => "success", // "message" => "Ok", // "data" => [ // "domain" => "example.com", // "admin" => ["Alice", "Bob"], // "description" => "First line.\nSecond line.", // ] // ] echo miniYAML::Dump($ar);
Limitations
The following YAML features are not supported:
- Multiline plain scalars (without
|or>) - Anchors and aliases (
&,*) - Explicit type tags (
!!str,!!int, …) - Flow mappings and sequences (
{…},[…]) — except empty array[] - Documents with a common base indentation on all lines
MiniYAML is well-suited for YAML you write and control yourself. If the input comes from an external tool or another language, it may use syntax that MiniYAML silently misparses or ignores.
Alternatives
If MiniYAML does not cover your use case, consider these alternatives:
| Library | Notes |
|---|---|
| symfony/yaml | Pure PHP, covers most of YAML 1.2. The standard choice for full YAML support; works standalone without the Symfony framework. |
| ext-yaml | PHP extension wrapping libyaml (C). Fastest option, full YAML 1.1 compliance. Requires server-level installation. |
| nette/neon | Pure PHP, implements NEON — a YAML-like format with PHP-native types. Not YAML, but a comfortable alternative if you control both ends. |
Testing
composer update --dev
./vendor/bin/run_unit_tests test
License
MiniYAML is free software distributed under the terms of the MIT license
atk14/mini-yaml 适用场景与选型建议
atk14/mini-yaml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.34k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yaml」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 atk14/mini-yaml 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atk14/mini-yaml 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 atk14/mini-yaml 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SUML for PHP
SUML support for Symfony
provides an facade for php-yaml, syck and symphony/yaml so switching in between is easier
Especificação do formato Cnab240 e Cnab400 traduzida para Yaml
Just parse YAML content to array
Trait to support creating complex nested class structures from JSON/YAML objects.
统计信息
- 总下载量: 7.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-04