yosymfony/toml
Composer 安装命令:
composer require yosymfony/toml
包简介
A PHP parser for TOML compatible with specification 0.4.0
README 文档
README
A PHP parser for TOML compatible with TOML v0.4.0.
Support:
Installation
Requires PHP >= 7.1.
Use Composer to install this package:
composer require yosymfony/toml
Usage
You can parse an inline TOML string or from a file:
To parse an inline TOML string:
use Yosymfony\Toml\Toml; $array = Toml::Parse('key = [1,2,3]'); print_r($array);
To parse a TOML file:
$array = Toml::ParseFile('example.toml'); print_r($array);
Additionally, methods parse and parseFile accept a second argument called
resultAsObject to return the result as an object based on stdClass.
$object = Toml::Parse('key = [1,2,3]', true);
TomlBuilder
You can create a TOML string with TomlBuilder. TomlBuilder uses a fluent interface for more readable code:
use Yosymfony\Toml\TomlBuilder; $tb = new TomlBuilder(); $result = $tb->addComment('Toml file') ->addTable('data.string') ->addValue('name', "Toml", 'This is your name') ->addValue('newline', "This string has a \n new line character.") ->addValue('winPath', "C:\\Users\\nodejs\\templates") ->addValue('literal', '@<\i\c*\s*>') // literals starts with '@'. ->addValue('unicode', 'unicode character: ' . json_decode('"\u03B4"')) ->addTable('data.bool') ->addValue('t', true) ->addValue('f', false) ->addTable('data.integer') ->addValue('positive', 25, 'Comment inline.') ->addValue('negative', -25) ->addTable('data.float') ->addValue('positive', 25.25) ->addValue('negative', -25.25) ->addTable('data.datetime') ->addValue('datetime', new \Datetime()) ->addComment('Related to arrays') ->addTable('data.array') ->addValue('simple', array(1,2,3)) ->addValue('multiple', array( array(1,2), array('abc', 'def'), array(1.1, 1.2), array(true, false), array( new \Datetime()) )) ->addComment('Array of tables') ->addArrayOfTable('fruit') // Row ->addValue('name', 'apple') ->addArrayOfTable('fruit.variety') ->addValue('name', 'red delicious') ->addArrayOfTable('fruit.variety') ->addValue('name', 'granny smith') ->addArrayOfTable('fruit') // Row ->addValue('name', 'banana') ->addArrayOfTable('fruit.variety') ->addValue('name', 'plantain') ->getTomlString(); // Generate the TOML string
The result:
#Toml file [data.string] name = "Toml" #This is your name newline = "This string has a \n new line character." winPath = "C:\\Users\\nodejs\\templates" literal = '<\i\c*\s*>' unicode = "unicode character: δ" [data.bool] t = true f = false [data.integer] positive = 25 #Comment inline. negative = -25 [data.float] positive = 25.25 negative = -25.25 [data.datetime] datetime = 2013-06-10T21:12:48Z #Related to arrays [data.array] simple = [1, 2, 3] multiple = [[1, 2], ["abc", "def"], [1.1, 1.2], [true, false], [2013-06-10T21:12:48Z]] # Array of tables [[fruit]] name = "apple" [[fruit.variety]] name = "red delicious" [[fruit.variety]] name = "granny smith" [[fruit]] name = "banana" [[fruit.variety]] name = "plantain"
Limitations
The TomlBuilder class is an utility to get Toml strings that has the following limitations:
- Only admits
basic stringsandliteral strings.
Deprecated method
The following method will be eliminated in version 2.0.0
- [TomlBuilder] addArrayTables
Contributing
When Contributing code to this library, you must follow its coding standards. Toml follows PSR-2 coding style. To ensure the CS, you can use the CLI tool PHP-CS-Fixer.
Unit tests
You can run the unit tests with the following command:
$ cd toml $ composer test
License
This library is open-sourced software licensed under the MIT license.
yosymfony/toml 适用场景与选型建议
yosymfony/toml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.8M 次下载、GitHub Stars 达 210, 最近一次更新时间为 2013 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「toml」 「mojombo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yosymfony/toml 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yosymfony/toml 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yosymfony/toml 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Configuration file loader
A parser for TOML implemented in PHP.
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
PHP parser for TOML language ( https://github.com/toml-lang/toml )
An MT940 bank statement parser for PHP
Config manage, load, get. Supports INI,JSON,YAML,NEON,PHP format file
统计信息
- 总下载量: 1.8M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 216
- 点击次数: 21
- 依赖项目数: 67
- 推荐数: 10
其他信息
- 授权协议: MIT
- 更新时间: 2013-05-12