承接 headsnet/collections 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

headsnet/collections

最新稳定版本:v0.2.1

Composer 安装命令:

composer require headsnet/collections

包简介

Base classes for collections

README 文档

README

Build Status Coverage Latest Stable Version Total Downloads License

Headsnet Collections

Installation

composer require headsnet/collections

Usage

Assuming you have some class Foo that you want to put into a collection:

final class Foo
{
    public function __construct(
        public string $name
    ) {
    }
}

Then create a custom named collection to hold the Foo instances:

/**
 * @extends AbstractImmutableCollection<Foo>
 *
 * @method self filter(callable $func)
 * @method self reverse()
 */
final class FooCollection extends AbstractImmutableCollection
{
    public function getItemClassName(): string
    {
        return Foo::class;
    }
}

Then instantiate the collection:

$foo1 = new Foo();
$foo2 = new Foo();

$allFoos = new FooCollection([$foo1, $foo2]);

You then have an immutable, iterable object that can be filtered, mapped and walked:

foreach ($allFoos as $foo) {
    $this->assertInstanceOf(Foo::class, $foo);
}

Contributing

Contributions are welcome. Please submit pull requests with one fix/feature per pull request.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-18