noflash/waffer
最新稳定版本:v1.0.0
Composer 安装命令:
composer require noflash/waffer
包简介
It holds every bit of your configuration ...and a maple syrup!
README 文档
README
Code is left for historical reasons. If you want something good and modern use Symfony Config.
Waffer
A tiny, fast and (if you want) powerful configuration library. It was wrote in intetion of usage with long running PHP daemons. It supports JSON & serializations configuration files out-of-box.
FAQ
Why Waffer?
When I started working on this code I need some sort of a name. Since it was intended to have smaller version along with bigger one (extending it) I came up with "diet" term stolen right from Panic Inc. and it's DietCoda app ;)
Still eating waffers with maple syrup I laughed and created DietWaffer class. This name sticks.
There's no XML!
Yup, you're right. I fully agree with Linus who's said:
XML is the worst format ever designed
I never had enough patience to deal with DOM trees, even with SimpleXML library onboard.
If you wish XML to be supported I kindly welcome pull-request for that feature.
Wait, where's INI?
INI format have a lot of limitations, and it's full of hacks. To be honest Waffer had INI support while ago, bud it was removed due to naming limitations.
For further informations see Notes section in PHP documentation for parse_ini_string().
Usage
Every library using Waffer is intended to have it it's default configuration. It's much like jQuery plugins - you can provide some extra options which overwrite default configuration. Single instance of Waffer is intended to be injected into multiple objects, deep into application.
Initialization
You can choose one of two classes - Waffer and DietWaffer. Second one contains only core configuration black-box, without any export/import capabilities.
Initial configuration array can be specified as constructor parameter.
(Re)storing data
Waffer was built to be simple, powerful and flexible tool. It supports many different ways of getting and storing configuration data. Let code below exaplains all of them:
$myAwesomeConfiguration = array( 'version' => 1.1, //This is global configuration option 'yummyWaffers' => 10, 'ACME\FooBar' => array( //Configuration for "FooBar" library by ACME 'version' => M_PI, 'bakingTemp' => 280, 'defaultOwner' => 'Mr. Foo' ) ); $config = new DietWaffer($myAwesomeConfiguration); //We don't need full Waffer for options below //Basic usage echo "Global version: ".$config->storage['version']."\n"; //Fastest but completly non-OO $config->setVersion(1.2); //Magic setter echo "New global version: ".$config->getVersion()."\n"; //...with magic getter $config->yummyWaffers++; //You can also use magic property set echo "No. of yummy waffers: ".$config->yummyWaffers."\n"; //...and get //Namespaces echo "ACME FooBar version: ".$config->storage['ACME\FooBar']['version']."\n"; $config->setVersion(3.1, 'ACME\FooBar'); //Magic setter echo "New ACME FooBar version: ".$config->getVersion('ACME\FooBar')."\n"; //...with magic getter //Removing variables unset($config->yummyWaffers); //Checking if variable exists var_dump( isset($config->version), isset($config->yummyWaffers), isset($config->notin) ); //Let's drive OO teachers crazy ;] var_dump( $config(), $config('ACME\FooBar') );
Importing & exporting
Library supports JSON & (un)serialize oob. It also handles loading & saving settings from/to files.
Let's a piece of code explain everything.
$config = new Waffer($myAwesomeConfiguration); echo "JSON: ".$config->toJSON()."\n"; echo "Serialized: ".$config->serialize()."\n"; echo "Save to file ".print_r($config->toFile("example.conf"), true)."\n"; //This will save JSON file, you can pass Waffer::FORMAT_SERIAL to use serialization //You can use fromFile() the same way echo "PHP array: \n".$config."\n";
Libraries integration
Waffer intrnally stores configuration as large array. By design every library using Waffer should register it's settings under own namespace key as shown below.
namespace ACME\FooBar; class FooBar { public static $defaultConfigutation = array( "welecome" => "Hello %s!" "funFacts" => array( "There's disease named Maple syrup urine disease", "Defibrillated patient isn't going to jump out of the bed (unless you're in Hollywood)" ) ); private $config; public function __construct(DietWaffer $config) { $this->config = $config; $this->config->storage[__NAMESPACE__] = array_replace_recursive(self::$defaultConfigutation, (array)@$this->config->storage[__NAMESPACE__]); } }
noflash/waffer 适用场景与选型建议
noflash/waffer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「configuration」 「config」 「Settings」 「PSR-4」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 noflash/waffer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 noflash/waffer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 noflash/waffer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
Configuration component
A Zend Framework module to quickly and easily set PHP settings.
Settings Card for Laravel Nova.
Utils to load, parse and work with configuration on Mezzio projects
Extends basic Wordpress features.
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-01