yellowcable/collection

2.0.0 2024-03-12 10:37 UTC

This package is auto-updated.

Last update: 2024-09-12 11:35:29 UTC


README

PHP8.2+ 收集和聚合库。

创建对象收集,并控制迭代和访问。

  • 你可以扩展抽象类,或者实现并使用接口和特质。
  • 聚合很简单;它会清除收集的内容!

使用方法

要使用收集,请确保创建或实例化

$collection = new ItemCollection("test", [
    new Item("1", 1, 1),
    new Item("1", 1, 1),
    new Item("1", 1, 1),
    new Item("1", 1, 1),
]);
-----------------------------------------------
$collection = new class () extends Collection
{
    public function getClass(): string
    {
        return Item::class;
    }
};

聚合的方式与收集相同

$agg = new ItemAggregation("bliep");
$agg->addCollection(new ItemCollection("test", [new Item("item", 1, 1)]), false);

注意

  • 如果你想要序列化,不要使用stdClass;PHP不会允许它。

贡献

贡献总是受欢迎的!建议应以代码的形式提交。

许可证

CC0

在法律允许的范围内,Yellow Cable 已经放弃了对本作品的全部版权及相关或邻近权利。