定制 aeviiq/collection 二次开发

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

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

aeviiq/collection

最新稳定版本:v4.0.2

Composer 安装命令:

composer require aeviiq/collection

包简介

A library that provides strict typed collections in PHP.

README 文档

README

Why

To provide an easy way to ensure type safety on collections/arrays and provide useful custom methods for object collections, as seen in the example below.

Installation

composer require aeviiq/collection 

Declaration

/**  * @extends ObjectCollection<int, Foo>  *  * @method \ArrayIterator|Foo[] getIterator()  * @method Foo|null first()  * @method Foo|null last()  */ final class FooCollection extends ObjectCollection { public function filterReleasedBefore(\DateTimeInterface $dateTime): FooCollection { return $this->filter(static function (Foo $foo) use ($dateTime): bool { return $foo->getReleaseDate() < $dateTime; }); } public function filterActives(): FooCollection { return $this->filter(static function (Foo $foo): bool { return $foo->isActive(); }); } protected function allowedInstance(): string { return Foo::class; } }

Usage

// Useful custom methods for ObjectCollections: $fooCollection = new FooCollection([$foo1, $foo2]); $result = $fooCollection->filterReleasedBefore(new DateTime('now'))->filterActives(); // Basic type collections that are provided $intCollection = new IntCollection([1, 2]); $intCollection->append(3); $intCollection = new IntCollection([1, '2']); // InvalidArgumentException thrown $intCollection->append('3'); // InvalidArgumentException thrown

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04