pklink/dotor
最新稳定版本:2.0.0
Composer 安装命令:
composer require pklink/dotor
包简介
Easy access to array values using dot notation. Useful for handling configurations or something like that
README 文档
README
Dotor is a library for PHP 5.6 and higher to access an array by using dot notification. This can be useful for handling array configurations or something like that
Installation
Install Dotor with Composer
Create or update your composer.json
{
"require": {
"pklink/dotor": "2.*"
}
}
And run Composer
php composer.phar install
Finally include Composers autoloader
include __DIR__ . '/vendor/autoload.php';
Usage
Using `Dotor is very simple. Create an instance with your (configurarion) array...
// config-sample.php return [ 'name' => 'sample configuration', 'database' => [ 'server' => 'localhost', 'username' => 'root', 'password' => 'password', 'database' => 'blah', 'type' => 'sqlite' ], 'object' => new stdClass(), 'false' => false, 'true' => true, 'zeroString' => '0', 'zeroInt' => 0, 'oneString' => '1', 'oneInt' => 1, 'twoString' => '2', ];
$loader = ArrayLoader::createFromFile('./config-sample.php'); $config = new Dotor($loader);
... and get the content by the get()-method.
$config->get('name'); $config->get('database.server');
Default values
$config->get('asdasdas'); // returns null $config->get('asdasdas', 'blah'); // returns 'blah'
Scalar values
$config->getScalar('object'); // returns '' $config->getScalar('object', 'blah'); // returns 'blah' $config->getScalar('not-existing'); // returns '' $config->getScalar('not-existing', []); // throw InvalidArgumentException
Arrays
$config->getArray('database'); // returns the database array $config->getArray('notexit'); // returns [] $config->getArray('notexit', [1]); // returns [1]
Boolean
$config->getBoolean('database', false); // returns false $config->getBool('database', true); // returns true $config->getBoolean('zeroString', true); // returns false $config->getBoolean('zeroInt', true); // returns false $config->getBoolean('oneString', false); // returns true $config->getBoolean('oneInt', false); // returns true
The getBoolean()-method and their alias getBool() handle the string '1' and the integer 1 as true. Otherwise this
method returns the given $default or true.
$config->getBoolean('oneString', false); // returns true $config->getBoolean('twoString', false); // returns false $config->getBoolean('twoString'); // returns true
Run tests
php composer.phar install --dev php vendor/bin/phpunit tests/
or with code-coverage-report
php composer.phar install --dev php vendor/bin/phpunit --coverage-html output tests/
License
This package is licensed under the BSD 2-Clause License. See the LICENSE file for details.
Credits
This package is inspired by php-dotty
pklink/dotor 适用场景与选型建议
pklink/dotor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 738 次下载、GitHub Stars 达 3, 最近一次更新时间为 2013 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「configuration」 「config」 「array」 「dot」 「Settings」 「dot-notation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pklink/dotor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pklink/dotor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pklink/dotor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Configuration component
A Zend Framework module to quickly and easily set PHP settings.
Trait providing methods to set class properties with an array.
Traits to build collections of specific objects
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
统计信息
- 总下载量: 738
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-2-Clause
- 更新时间: 2013-02-11