定制 beauty-framework/collection 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

beauty-framework/collection

最新稳定版本:1.0.1

Composer 安装命令:

composer require beauty-framework/collection

包简介

Beauty Collection

README 文档

README

A powerful collection abstraction for the Beauty Framework.
Supports both eager and lazy data pipelines, multiple storage strategies, method chaining (map, filter, sortBy, paginate, etc.), strict interfaces, and full compatibility.

Features

Collection (eager)

  • Fluent methods:
    • map, filter, where, sortBy, paginate, each, first, last, values
  • Implements:
    • ArrayAccess, Countable, IteratorAggregate, JsonSerializable
  • Smart last() optimization (iterator or buffered strategy)
  • Storage strategies:
    • ArrayStorage (default)
    • DsMapStorage (if ext-ds is available)

LazyCollection

  • Based on Generator
  • Fluent methods:
    • map, filter, chunk, flatMap, reduce, take, first, toArray
  • Memory efficient for large or infinite datasets

Interfaces

  • CollectionInterface
  • SupportsOperations
  • SupportsAccessors
  • LazyCollectionInterface

Installation

composer require beauty-framework/collection

Usage

Eager Collection

$collection = new Collection([
  ['name' => 'Kirill'],
  ['name' => 'Hui'],
  ['name' => 'Zver'],
]);

$filtered = $collection
    ->where('name', 'Kirill')
    ->map(fn($x) => strtoupper($x['name']))
    ->toArray();

Lazy Collection

$collection = new LazyCollection(fn() => yield from range(1, 1_000_000));

$result = $collection
    ->filter(fn($x) => $x % 2 === 0)
    ->take(5)
    ->flatMap(fn($x) => [$x, $x * 10])
    ->toArray();

Tests

vendor/bin/phpunit

Compatibility

  • ArrayAccess
  • Countable
  • IteratorAggregate
  • JsonSerializable

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-19