vk-php-utils/chain
Composer 安装命令:
composer require vk-php-utils/chain
包简介
PHP Chain library
README 文档
README
The library was created to make working with collections more simple in PHP
Requirements
- PHP >=7.4 (PHP 8.1 is supported)
- Extensions: json, mbstring
Installation
composer require vk-php-utils/chain:^1.0
Chain API
use VKPHPUtils\Chain\Chain; // Constructors Chain::of(...$items): Chain // Initialize mutable chain Chain::immutable(...$items): Chain // Initialize immutable chain // API toArray(): array; // Converts the chain to array (applies all chain-functions) toChain(): Chain; // Useful with mutable chain. Returns new chain with all current chain functions applied hasKey($key): bool // Check exists the key in current chain or no hasValue($value): bool; // Check existence of the value in the chain search($value) // Searches position (key) of the value in current chain. Returns null if the value not found getValue($key) // Get value using key setValue($key, $value): Chain; // Set value using key remove($key): Chain; // Removes element with index eq to $key isEmpty(): bool // Check is the chain empty size(): int // Get the chain size (number of elements) count(): int // Get the chain size (number of elements) append($any): Chain; // Appends value into the chain prepend($any): Chain; // Prepend value into the chain // map/reduce methods filter(?callable $fn = null): Chain // Filter the chain using function $fn map(callable $fn): Chain; // Applies function $fn to each chain item and returns chain with mapped entities. Index-safe operation flatMap(callable $fn): Chain; // Works like {@see map()} but returns iterable set of mapped objects per each the chain's item reduce(callable $fn, $initialValue = null) // Calculate aggregate function result // keys/values keys(): Chain; // Get keys of the chain values(): Chain; // Get chain values // chain methods diff(...$elements): Chain; // Calculates diff between current chain and passed one merge(...$elements): Chain; // Merges all elements with current chain intersect(...$elements): Chain; // Calculates intersection of two sets (current chain and passed one). Non index-safe operation intersectKeepIndexes(...$elements): Chain; // Calculates intersection of two sets (current chain and passed one). Index-safe operation frequencyAnalysis(): Chain; // Created histogram/frequency analysis of the chain flip(): Chain; // Flip the chain mix(): Chain; // Mixes the chain reverse(bool $saveIndex = false): Chain; // Reverse current chain unique(bool $saveIndex = false): Chain; // Unique items of current chain slice(int $startIncluded, int $stopExcluded, int $step = 1, bool $saveIndex = false): Chain; // Get chain's chunk forEach(callable $fn): Chain; // Just calls $fn for each chain element // sort methods sortKeys(?callable $sortFn = null, ?int $direction = SORT_ASC, ?int $sortFlags = null): Chain; // Sorts chain by keys sortValues(?callable $sortFn = null, ?int $direction = SORT_ASC, ?int $sortFlags = SORT_REGULAR): Chain; // Sorts chain by values. Index-safe operation sortByProperty(string $propertyName, int $direction = SORT_ASC): Chain; // Sorts collection by given property
Run Tests
./vendor/bin/phpunit ./tests
vk-php-utils/chain 适用场景与选型建议
vk-php-utils/chain 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.43k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 vk-php-utils/chain 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vk-php-utils/chain 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13.43k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-16