corpsee/nameless-utilities
最新稳定版本:3.0.1
Composer 安装命令:
composer require corpsee/nameless-utilities
包简介
PHP Utilities compliant with PSR-1, PSR-2, PSR-4 and Composer
README 文档
README
This package is abandoned and no longer maintained.
Nameless utilities
PHP Utilities compliant with PSR-1, PSR-2, PSR-4 and Composer.
Installation
You can install Nameless utilities by composer. Add following code to "require" section of the composer.json:
"require": { "corpsee/nameless-utilities": "<version>" }
And install dependencies using the Composer:
cd path/to/your-project
composer install
Usage
ArrayHelper
use Nameless\Utilities\ArrayHelper; echo ArrayHelper::toString([1, 2, 3]); // Prints '1, 2, 3', ', ' is default separator echo ArrayHelper::toString([1, 2, 3], ':'); // Prints '1:2:3' $array = [ 'one' => 1, 'two' => 2, 'three' => 3, ]; echo ArrayHelper::get($array, 'four', 4); // Prints '4' (4)
DateTimeHelper
use Nameless\Utilities\DateTimeHelper; echo DateTimeHelper::humanize(121.001); // Prints '2 minute 1 second 1 millisecond'
Usage with localization/alternative labels:
use Nameless\Utilities\DateTimeHelper; $localization = [ ['мкс', 'мкс'], ['мс', 'мс'], ['с', 'с'], ['мин', 'мин'], ['ч', 'ч'], ['д', 'д'], ['мес', 'мес'], ['г', 'г'], ]; echo DateTimeHelper::humanize(121, $localization); // Prints '2 мин 1 с'
FileSizeHelper
use Nameless\Utilities\FileSizeHelper; echo FileSizeHelper::humanize(1000000000); // Prints '953.67MB' echo FileSizeHelper::unhumanize('954MB'); // Prints '1000341504' (bytes)
PathHelper
use Nameless\Utilities\PathHelper; echo PathHelper::toURL('/base/path/to/url', '/base'); // Prints '/path/to/url'
StringHelper
use Nameless\Utilities\StringHelper; var_dump(StringHelper::startWith('example', 'exa')); // Prints true var_dump(StringHelper::endWith('example', 'mplee')); // Prints true var_dump(StringHelper::contains('example', 'xampl')); // Prints true echo StringHelper::cut('example', 6); // Prints 'exampl...', '...' is default suffix echo StringHelper::cutWords('simple example', 1); // Prints 'example...', '...' is default suffix echo StringHelper::transliterate('очень простой пример', 'Russian-Latin/BGN'); // Prints transliterated 'ochen prostoj primer' echo StringHelper::standardize('очень простой Пример', 'Russian-Latin/BGN'); // Prints standardizated 'ochen_prostoj_primer', '_' is default words separator echo StringHelper::standardize('очень простой Пример', 'Russian-Latin/BGN', '-'); // Prints 'ochen-prostoj-primer', use '-' for slugify string var_dump(StringHelper::toArray('1,2,3,')); // Prints Array ['1', '2', '3'], ',' is default separator echo StringHelper::snakecaseToCamelcase('snake_case'); // Prints 'SnakeCase' echo StringHelper::snakecaseToCamelcase('snake_case', true); // Prints 'snakeCase' echo StringHelper::camelcaseToSnakecase('CamelCase'); // Prints 'camel_case'
UrlHelper
use Nameless\Utilities\UrlHelper; echo UrlHelper::toPath('/path/to/url', '/base'); // Prints '/base/path/to/url'
BcMathHelper
Passing values of type float to a BCMath function which expects a string as operand may not have the desired effect due to the way PHP converts float values to string, namely that the string may be in exponential notation (what is not supported by BCMath), and that the decimal separator is locale depended (while BCMath always expects a decimal point).
<?php $num1 = 0; // (string) 0 => '0' $num2 = -0.000005; // (string) -0.000005 => '-5.05E-6' echo bcadd($num1, $num2, 6); // => '0.000000' setlocale(LC_NUMERIC, 'de_DE'); // uses a decimal comma $num2 = 1.2; // (string) 1.2 => '1,2' echo bcsub($num1, $num2, 1); // => '0.0' ?>
BcMathHelper solve problem with floats to strings converting and "," as decimal separator for BcMath functions:
use Nameless\Utilities\BcMathHelper; var_dump(BcMathHelper::add('0.000005', '0.000005', 5)); // (float)0.00001 var_dump(BcMathHelper::add('0,000005', '0,000005', 5)); // (float)0.00001 var_dump(BcMathHelper::add(0.000005, 0.000005, 5)); // (float)0.00001 var_dump(BcMathHelper::add('5.0E-6', '5.0E-7', 5)); // (float)0.00001 var_dump(BcMathHelper::sub(0.000005, 0.000001, 5)); // (float)0.000004 var_dump(BcMathHelper::mul(0.000005, 0.000002, 11)); // (float)0.00000000001 var_dump(BcMathHelper::div(0.000005, 0.000002, 2)); // (float)2.50 var_dump(BcMathHelper::comp(0.000005, 0.000002, 6)); // (int)1
Tests
You can run the unit tests with the following commands:
cd path/to/nameless-utilities
./vendor/bin/phpunit
License
The Nameless utilities is open source software licensed under the GPL-3.0 license.
corpsee/nameless-utilities 适用场景与选型建议
corpsee/nameless-utilities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 850 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「helpers」 「url」 「transliterate」 「utilities」 「humanize」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 corpsee/nameless-utilities 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 corpsee/nameless-utilities 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 corpsee/nameless-utilities 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy URL rewrites in your Laravel application
HTML and form generation
Falsy helps you manage half-truths with PHP
A Laravel helper to detect if the current route/path is active.
Provides a service and twig extension for getting short urls like http://your.host/~short
Alfabank REST API integration
统计信息
- 总下载量: 850
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2015-06-14