periwinkle/array-config
Composer 安装命令:
composer require periwinkle/array-config
包简介
Allows for using native PHP files as config files in PHP
README 文档
README
Allows for using native PHP files as config files in PHP!
Using YAML and XML as configuration scripts in PHP projects has become prolific. However, this comes with the overhead of having to validate, process, and convert those configuration files to PHP to be used.
What if you could just use native PHP arrays for configuration files?
Now you can!
periwinkle/array-config brings revolutionary support to PHP to use PHP in PHP.
Installation
periwinkle/array-config can be installed via Composer:
composer require periwinkle/array-config
Usage
Let's say you had a configuration file written in Yaml:
database: driver: pgsql host: localhost name: awesomedb user: awesomesauce password: mustangSally
With periwinkle/array-config, you can now write this configuration file as pure PHP!
return [ 'database' => [ 'driver' => 'pgsql', 'host' => 'localhost', 'name' => 'awesomedb', 'user' => 'awesomesauce', 'password' => 'mustangSally' ] ];
To use this config file, simply:
$config = include 'configs/database.php';
No need to parse Yaml! No need to parse Xml!
Older Versions of PHP
array-config is so revolutionary, we've added support going all the way back to PHP 3! The examples above use the short array syntax introduced in PHP 5.4. If you're living in the past, you can still use array-config*:
return array( 'database' => array( 'driver' => 'pgsql', 'host' => 'localhost', 'name' => 'awesomedb', 'user' => 'awesomesauce', 'password' => 'mustangSally' ) );
Usage:
$config = include 'configs/database.php';
* Note: Composer will not work with some older versions. For those versions, feel free
to copy the array-config source code to a directory within your project. Any directory
will do; we suggest a functions/ or includes/ directory if you have one.
Framework Support
Ping your favorite neighborhood framework developer, and tell them you want the ability to use native PHP config files in their projects!
Join the array party!
- PhpUnit/DbUnit Fixtures: Provides support for native PHP array based fixtures for DbUnit.
Seriously
Yeah, I know you can just cache the result of the Yaml or Xml parsing so that it doesn't have to be done over and over again, but there's no valid reason to use it in the first place.
Just use PHP.
periwinkle/array-config 适用场景与选型建议
periwinkle/array-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35 次下载、GitHub Stars 达 54, 最近一次更新时间为 2014 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 periwinkle/array-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 periwinkle/array-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 35
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 54
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-07