programie/pini
Composer 安装命令:
composer require programie/pini
包简介
A simple PHP class for reading and writing ini files
README 文档
README
A simple PHP class for reading and writing ini files.
Installation
Add the composer package "programie/pini" to the required packages of your composer.json:
composer require programie/pini
Examples
Parse ini and read values
$ini = new Pini("/path/to/your/file.ini"); $ini->getValue("section name", "key name");// Returns the value of the key "key name" in section "section name"
Merge sections and values from another ini file
Sometimes you want to merge sections and their keys from multiple ini files into one (e.g. if you want to provide default values as an ini file).
This can be done using the merge() method. It will replace all keys with the keys from the given ini file.
$ini1 = new Pini("/path/to/your/first.ini"); $ini2 = new Pini("/path/to/your/second.ini"); $ini1->merge($ini2);
$ini1 will now contain all sections and keys from $ini2. An already existing key will be replaced with the key from the second ini file.
You may also specify the section you want to merge.
$ini1->merge($ini2, "section name");
This will only merge keys from the given section from $ini2 into $ini1.
Write values and save ini
With Pini you are also able to write ini files.
$ini = new Pini(); $ini->setValue("section name", "key name", "some value"); $ini->save("/path/to/your/file.ini");
This will add or replace the key "key name" in the section "section name" with the value "some value".
The save() method saves the whole content of the Pini instance to a file.
Note: The $filename parameter in the save() method is optional. The filename passed on instance creation is used by default.
$ini = new Pini("/path/to/your/file.ini"); // ... Some other ini methods. $ini->save();
This will save the content to the file passed on instance creation ("/path/to/your/file.ini").
Look at the examples folder for more examples.
Structure
An ini file can has the following structure:
[section name] property key = property value another property = another value array property[] = some value array property[] = another value [another section] another property = even another value
Ini files contain multiple sections. Each section can contain multiple properties.
A property key ending with "[]" defines an array. Define multiple same named array properties (e.g. "property[]") with any value to add values to the array.
Non-array properties with the same key already defined in the section will replace the previously defined property.
programie/pini 适用场景与选型建议
programie/pini 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.98k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 programie/pini 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 programie/pini 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-11