dechamp/shorty
Composer 安装命令:
composer require dechamp/shorty
包简介
Just a few tools to help avoid annoying things such as long logic where it should be simple.
README 文档
README
The goal of this library is to provide easy helpers to shorten repetitive task that are used day in and day out.
Guidelines
- Do not create something that you can get from another supported library.
- K.I.S.S. (Keep it simple stupid), don't make large helpers.
- Keep them as static methods for simplicity
Helps shorten typical logic that can become excessive, such as getting a value from an deep array or returning null.
Methods
grabOrNull((array|object) $haystack, (string) $needle)
Used when dealing with arrays or object, when getting values. check recursively for key, return value or null if key not found
- $haystack - (array|object) it will do the same, for array or object
- $needle - (string) search recursively by seperating the keys with
/, expa/b/c
example usage
use
Shorty::grabOrNull($deepArray, "a/b/c/d");
instead of...
isset($deepArray['a']['b']['c']['d']) ? $deepArray['a']['b']['c']['d'] : null;
grabOr((array|object) $haystack, (string) $needle, (mixed) $default)
Used when dealing with arrays or object, when getting values. check recursively for key, return value or your default if key not found
- $haystack - (array|object) it will do the same, for array or object
- $needle - (string) search recursively by seperating the keys with
/, expa/b/c - $default - (mixed) anything you wish to return by default
example usage
use
Shorty::grabOr($deepArray, "a/b/c/d", "tacos");
instead of...
isset($deepArray['a']['b']['c']['d']) ? $deepArray['a']['b']['c']['d'] : "tacos";
grabOrThrow((array|object) $haystack, (string) $needle, Exception $exception)
Used when dealing with arrays or object, when getting values. check recursively for key, return value or throw your exception.
- $haystack - (array|object) it will do the same, for array or object
- $needle - (string) search recursively by seperating the keys with
/, expa/b/c - $exception - Exception instance
example usage
use
try {
$val = Shorty::grabOrThrow($deepArray, "a/b/c/d", new Exception('No tacos'));
} ...
instead of...
try {
if (! isset($deepArray['a']['b']['c']['d'])) {
throw new Exception('No Tacos');
}
$val = $deepArray['a']['b']['c']['d'];
} ...
guard() this is now deprecated, use https://packagist.org/packages/webmozart/assert instead
Testing
You can use the included Dockerfile for running phpunit.
Setup
1 docker build -t shorty .
2 docker run -it -v $PWD:/var/www/html shorty /bin/bash
3 phpunit and phpunit --coverage-text
dechamp/shorty 适用场景与选型建议
dechamp/shorty 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.8k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「array」 「helper」 「isset」 「shorten」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dechamp/shorty 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dechamp/shorty 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dechamp/shorty 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Datetime helpers for timezone handling
Trait providing methods to set class properties with an array.
Library with classes to help you do batch.
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.
统计信息
- 总下载量: 10.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-18