digitalrevolution/utils
Composer 安装命令:
composer require digitalrevolution/utils
包简介
A library for everyday use utility classes
README 文档
README
DR Utility Classes
A library with everyday use classes and methods:
Arrays
first- Get the first element of an array, exception otherwise.firstOrNull- Get the first element of an array, null otherwise.last- Get the last element of an array, exception otherwise.lastOrNull- Get the last element of an array, null otherwise.find- Find the first element in an array that matches a predicate, exception otherwise.findOrNull- Find the first element in an array that matches a predicate, null otherwise.flatten- Recursively flattens an array returning an array with all the elements.implode- Implode an iterable into a string. Supports iterable of boolean, int, float, string, null, Stringable and BackedEnum.contains- Test if the given value is contained within items. SupportsEquatableInterface.diff- Get the difference between two arrays. SupportsComparableInterface.equals- Tests if two arrays have equal contents, ignoring order. SupportsComparableInterface.explode- Explode a string or null into an array, with exploding empty string to empty array.map- Similar toarray_mapbut with support foriterable, and receive key as second argument in the callback.mapAssoc- Map an array to a new array using a callback, preserving keys.mapKeys- Map an array to a new keyed array using a callback,reindex- Reindex an array with new keys based on the result of the callback.groupBy- Group items by the given return value of the callback.renameKey- Rename thestringkey of an array element.remove- Remove an element from an array based on the callback. SupportsEquatableInterface.removeKey- Remove an element from an array based on the key.removeKeys- Remove multiple elements from an array based on the keys.removeTypes- Filters an array by removing all values that match the provided types.removeNull- Filters an array by removing all null values.search- Find the key of an element in an array or false otherwise. SupportsEquatableInterface.unique- Remove duplicate values from an array. SupportsEquatableInterface.wrap- Wrap a value in an array, unless it is already an array.toJson- Converts an array into a json string.fromJson- Converts a json string into an array.fetchByPath- Fetch a value from a multi-dimensional array by the given path.assignByPath- Assign a value to a multi-dimensional array by the given path.
Assert
Fluent assertion methods, inspired by webmozart/assert:
nullnotNullisArrayisListinArrayisCallableresourceobjectscalarintegerpositiveIntnegativeIntnonNegativeIntnonPositiveIntnumericfloatstringclassStringstartsWithnotStartsWithendsWithnotEndsWithbooleantruefalsenotFalseemptyArraynonEmptyArraynonEmptyStringisInstanceOfgreaterThan- SupportsComparableInterface.lessThan- SupportsComparableInterface.typefileExistsfiledirectoryreadablewritable
Example
$value = Assert::notNull($this->repository->find(123));
Stringify
::value(mixed $value): string
Easily convert any value to a string representation.
true > 'true' false > 'false' null > 'null' 123 > '123' 1.23 > '1.23' 'abc' > 'abc' '' > 'empty-string', [] > 'empty-array' [1, 2, 3] > 'array-list(3)' ['foo' => 'bar'] => 'keyed-array(1)' StringableObject => 'value (StringableObject)' stdClass => 'stdClass' resource => 'resource (stream)'
Closures
unfold
Turns a variable with a closure into the return type of that closure.
Can be called multiple times on the same variable, but will only execute the closure once.
$service = fn() => new Service(); Closures::unfold($service); $service instanceof Service // true
Installation
composer require digitalrevolution/utils
About us
At 123inkt (Part of Digital Revolution B.V.), every day more than 50 development professionals are working on improving our internal ERP and our several shops. Do you want to join us? We are looking for developers.
digitalrevolution/utils 适用场景与选型建议
digitalrevolution/utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 69.48k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 07 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 digitalrevolution/utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 digitalrevolution/utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 69.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-20