yellowcable/collection

Collection and Aggregation.

2.0.0 2024-03-12 10:37 UTC

This package is auto-updated.

Last update: 2024-05-12 10:58:35 UTC


README

Collection and Aggregation library for PHP8.2+

Create object collections and be in control of iteration and access.

  • You can either extend the abstract or implement and use the interfaces and traits.
  • Aggregation is simple; it clears the content of the collections!

Usage

To use a Collection, make sure you create or instantiate:

$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;
    }
};

Aggregations are possible in the same fashion as Collections:

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

Notes

  • Don't use stdClass if you want to serialize; PHP will not allow it.

Contribute

Contributions are always welcome! Suggestions are only welcome in the form of code.

License

CC0

To the extent possible under law, Yellow Cable has waived all copyright and related or neighboring rights to this work.