Download the PHP package petalbranch/toml without Composer

On this page you can find all versions of the php package petalbranch/toml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package toml

Petalbranch TOML

PHP Version Require TOML Version PHPStan Level 9

一个纯 PHP 实现的工业级 TOML 解析器与生成器(Parser & Dumper)。

基于词法分析(Lexer)与抽象语法树(AST)架构设计,将解析(Parse)与生成(Dump)彻底解耦。不仅提供高可靠的 TOML 读写能力,更具备 无损注释回写O(1) 内存极速解析等号对齐排版**等高级特性。


Language


✨ 核心特性


❌ 精准错误诊断(Rich Error Reporting)

当 TOML 格式非法时,解析器会提供结构化错误信息 + 精确定位 + 上下文片段。游标指针(^ )不仅能精确定位列数,还能根据全角/半角字符(如中文、Emoji)自动计算视觉宽度,实现像素级对齐:

支持的错误类型(部分):

每个错误均包含:

👉 不仅是解析器,也可以作为 TOML Linter / 校验工具 使用。

此外,详细错误信息是可配置的(默认开启):

🔄 无损回写与动态修改 (Lossless Round-Trip)

大多数解析器在转储时会丢失注释。本库允许你直接操作 AST(抽象语法树),修改值后重新 Dump,所有注释和排版将被完美保留:

💅 极致美学转储 (Alignment Formatting)

强迫症福音!开启 alignEquals 配置后,Dumper 会自动预扫描同一层级的键名,并使用空格智能对齐所有等号:


🧪 测试覆盖(toml-test)

本项目基于官方 toml-test v2.1.0 测试套件进行验证:

说明:

👉 覆盖 TOML 规范的大量边界情况,保证实现的可靠性与一致性。

⚠️ 唯一失败用例说明(encoder/key/quoted-unicode):

该用例包含 \u0000(空字节)作为键名,并通过 JSON 传入编码器。 由于 PHP 在字符串/数组键层面对空字节存在底层限制,且 JSON 解析链路无法可靠承载该键,导致输入在进入编码器前即被判定为非法( Invalid JSON input)。

👉 该行为与本库的「已知限制」一致,不影响常规 TOML 使用场景。


🤔 为什么选择 Petalbranch TOML?

特性 本库 常见实现
API 友好度 ✅ 提供 toml_encode/toml_decode 全局函数 ❌ 仅支持冗长的类调用
静态分析 (PHPStan) ✅ Level 9 满级通关 ❌ 普遍存在 mixed 警告
内存占用 (Lexer) ✅ O(1) 极速字节游标 ❌ O(N) 数组全量拆分
注释无损回写 ✅ 完美支持 (AST 级别) ❌ 转储时注释全部丢失
错误诊断 ✅ 源码片段 + 像素级游标 ❌ 仅抛出简单的 Exception
生成质量 (Dumper) ✅ 智能内联 + 等号对齐 ❌ 机械式换行输出
规范覆盖度 ✅ 极高 (toml-test 验证) ⚠️ 部分实现 / 落后规范

🧠 架构简述


📦 安装

通过 Composer 安装(需要 PHP 8.3+):


🚀 快速开始

0. 丝滑的全局辅助函数 (推荐)

如果你熟悉 PHP 的 JSON 函数,那么你已经掌握了本库 90% 的用法:

1. 解析 TOML (Parse)


2. 生成 TOML (Dump)


🎯 使用场景


⚙️ 性能与生产环境建议

在生产环境中,建议将解析后的 PHP 数组进行缓存以达到极致性能(如使用 OPcache):


⚠️ 已知限制(Known Limitations)

由于 PHP 底层哈希表对象模型的限制,本库不支持使用空字节(\u0000)作为对象的键名。这在正常工程实践中极度罕见。


📄 开源协议

本项目基于 Apache License 2.0 协议开源 - 查看 LICENSE 文件了解更多细节。


All versions of toml with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package petalbranch/toml contains the following files

Loading the files please wait ...