bzrk/php-stream
Composer 安装命令:
composer require bzrk/php-stream
包简介
a library to simplify handling(filter, map, ...) collections in php
README 文档
README
A library to handle Collections like in Java
Stream Class
- public count(): int
- public map(Closure $call): Stream
- public flatMap(Closure $call): Stream
- public filter(Closure $call): Stream
- public notNull(): Stream
- public notEmpty(): Stream
- public each(Closure $call): void
- public toList(bool $keepKeys = false): array
- public toMap(Closure $key, Closure $value): array
- public first(): mixed
- public limit(int $size): Stream
- public order(Comparator $comparator): Stream
- public run(): Stream
- public skip(int $count): Stream
- public implode(string $separator = ','): string
- public join(string $separator = ','): string --> alias for implode
- public batch(int $count): Stream
- public associateBy(Closure $call): array
- public collect(string $class): Collection
- public toGenerator(Closure $call = null, $default = null): Generator
- public callBack(Closure $call): Stream
Streams Class
- public static of(array|Iterator|File|CsvFile $data): Stream
- public static range(int $start, int $inclusiveEnd): Stream
- public static split(string $pattern, string $source): Stream
Examples
$data = [ (object)["name" => "hallo", "data" => ["a", "b"]], (object)["name" => "hallo", "data" => ["a", "b", "H", "g"]], (object)["name" => "hallo", "data" => ["a", "b", "d"]], ]; $result = Streams::of($data) ->map(fn(object $obj) => (object)["name" => $obj->name, "cnt" => count($obj->data)]) ->filter(fn(object $obj) => $obj->cnt !== 4) ->order(new Comparator(fn(object $a, object $b) => $a->cnt - $b->cnt)) ->map(fn(object $obj) => "$obj->name - $obj->cnt") ->toList(); //Result is ['hallo - 2', 'hallo - 3']
Create a Stream from a Typed Collection
class User { ... } class UserCollection extends Collection { public function __construct(User ...$data) { parent::__construct($data); } public function add(User $value): void { parent::addEntry($value); } } (new UserCollection(new User("name")))->stream()->map(....)
more Examples in the testsuite.
Running Test
composer verify
or
docker-compose up
bzrk/php-stream 适用场景与选型建议
bzrk/php-stream 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.96k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2021 年 09 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「stream」 「filter」 「array」 「mapping」 「list」 「collection」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bzrk/php-stream 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bzrk/php-stream 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bzrk/php-stream 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Object-Oriented API for PHP streams
Nova searchable filter for belongsTo relationships.
Safely namespaced guzzle psr7 for WP2Static
Trait providing methods to set class properties with an array.
Symfony DataGridBundle
统计信息
- 总下载量: 13.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 13
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-23