Download the PHP package omegaalfa/collection without Composer
On this page you can find all versions of the php package omegaalfa/collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download omegaalfa/collection
More information about omegaalfa/collection
Files in omegaalfa/collection
Package collection
Short Description This library implements the Trie routing logic
License MIT
Informations about the package collection
collection
This package is a PHP library that provides a simple and efficient way to work with collections of data. It provides a wide range of methods for manipulating, filtering, and transforming collections, making it a powerful tool for any PHP developer.
Installation
Prerequisites
PHP 8.1 or higher
Methods
The Collection class provides the following methods:
Collection Class
- __construct(Iterator|array $items = []): Creates a new Collection instance, optionally initializing it with an array or an Iterator.
- addIterator(Iterator|array $collection = []): Adds a new Iterator or array to the existing collection.
- current(): returns the current element of the Iterator (it is a collection for an Iterator).
- setAttribute(mixed $key, mixed $value): Sets an attribute in the collection (if it is an array).
- getAttribute(mixed $key): Gets an attribute from the collection (if it is an array).
- getIterator(): Traversable: Returns an iterator for the collection, allowing iteration over its items.
- map(callable $callback): Collection: Applies a callback function to each item in the collection and returns a new Collection with the transformed items.
- filter(callable $callback): Collection: Filters the collection based on a given callback function, returning a new Collection with only the items that satisfy the condition.
- each(callable $callback): Collection: Applies a callback function to each item in the collection, without modifying the original collection.
- count(): int: Returns the number of items in the collection.
- searchValueKey(array $array, string $key): mixed: Searches for a value in a multidimensional array based on a given key.
- add(mixed $item): void: Adds a new item to the collection.
- remove(mixed $item): void: Removes an item from the collection.
- arrayToGenerator(array $array): Generator: Converts an array into a generator, allowing iteration over its elements.
- toArray(): array: Returns the collection as an array.
LazyFileIterator Class
- __construct(string $filePath): Creates a new LazyFileIterator instance, specifying the path to the JSON file.
- current(): mixed: Returns the current JSON object decoded from the file line.
- next(): void: Moves the iterator to the next line in the file.
- key(): int: Returns the current key (line number) of the iterator.
- valid(): bool: Checks if the iterator is pointing to a valid line in the file.
- rewind(): void: Resets the iterator to the beginning of the file.
Examples
Contributing
Feel free to submit issues or pull requests. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License. See the LICENSE file for details.