承接 atk14/mini-yaml 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Tests

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.php into 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 / NULL values (controlled by the nullable option)
  • 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 atk14/mini-yaml 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-04