API Models Collections TupleChanges - evansims/openfga-php GitHub Wiki

Table of Contents


Namespace

OpenFGA\Models\Collections


Source

View source code


Implements


Related Classes


Methods

add

public function add(mixed $item): static

Add an item to the end of the collection. This method appends a new model object to the collection, automatically assigning it the next available integer index. The item is validated to ensure it matches the expected type for this collection, maintaining type safety throughout the authorization data processing pipeline. This operation modifies the current collection instance directly, making it suitable for building collections incrementally. For immutable operations, use the withItems() method instead, which creates new collection instances without modifying the original.

View source


Parameters

Name Type Description
$item mixed The OpenFGA model object to add to the collection

Returns

static


clear

public function clear(): void

Remove all items from the collection. This method empties the collection, resetting it to its initial state with no items and a count of zero.

View source


Returns

void


count

public function count(): int<0, max>

View source


Returns

int&lt;0, max&gt;


current

public function current(): OpenFGA\Models\ModelInterface

View source


Returns

ModelInterface


every

public function every(callable $callback): bool

Check if all items in the collection match the given condition. This method tests whether all items in the collection satisfy the provided callback function. Returns true if all items pass the test, false if any item fails.

View source


Parameters

Name Type Description
$callback callable

Returns

bool — True if all items match the condition, false otherwise


filter

public function filter(callable $callback): static

Create a new collection containing only items that match the condition. This method creates a new collection containing only the items from the current collection that satisfy the provided callback function.

View source


Parameters

Name Type Description
$callback callable

Returns

static — A new collection containing only the matching items


first

public function first(?callable $callback = NULL)

Get the first item in the collection, optionally matching a condition. When called without a callback, returns the first item in the collection. When called with a callback, returns the first item that satisfies the condition.

View source


Parameters

Name Type Description
$callback callable | null

get

public function get(int $offset)

Get an item by its position in the collection. This method retrieves the item at the specified index position. Returns null if the index is out of bounds.

View source


Parameters

Name Type Description
$offset int The index position of the item to retrieve

isEmpty

public function isEmpty(): bool

Check if the collection contains no items. This method provides a convenient way to test whether the collection is empty without needing to check the count.

View source


Returns

bool — True if the collection is empty, false otherwise


jsonSerialize

public function jsonSerialize(): array

View source


Returns

array


key

public function key(): int

Get the current iterator key. This method returns the current position in the collection iteration, which is always an integer for indexed collections.

View source


Returns

int — The current iterator position


next

public function next(): void

Move the iterator to the next position. This method advances the internal iterator pointer to the next item in the collection sequence.

View source


Returns

void


offsetExists

public function offsetExists(mixed $offset): bool

Check if an offset exists in the collection. This method determines whether the collection contains an item at the specified offset position.

View source


Parameters

Name Type Description
$offset mixed The offset to check for existence

Returns

bool — True if the offset exists, false otherwise


offsetGet

public function offsetGet(mixed $offset): ?OpenFGA\Models\ModelInterface

View source


Parameters

Name Type Description
$offset mixed

Returns

ModelInterface | null


offsetSet

public function offsetSet(mixed $offset, mixed $value): void

View source


Parameters

Name Type Description
$offset mixed
$value mixed

Returns

void


offsetUnset

public function offsetUnset(mixed $offset): void

View source


Parameters

Name Type Description
$offset mixed

Returns

void


reduce

public function reduce(mixed $initial, callable $callback): mixed

Reduce the collection to a single value using a callback function. This method iteratively applies a callback function to accumulate the collection items into a single value, starting with an initial value.

View source


Parameters

Name Type Description
$initial mixed The initial value to start the reduction
$callback callable

Returns

mixed — The final accumulated value


rewind

public function rewind(): void

Reset the iterator to the beginning of the collection. This method moves the internal iterator pointer back to the first item in the collection.

View source


Returns

void


schema

Implements Models\Collections\IndexedCollectionInterface

public function schema(): CollectionSchemaInterface

Get the schema definition for this collection type. Returns the schema that defines the structure, validation rules, and serialization behavior for this collection type. The schema specifies the expected item type, validation constraints, and transformation rules that ensure all items in the collection conform to OpenFGA data requirements. Collection schemas enable: - Type validation for all added items - Consistent serialization across different contexts - API compatibility verification - Runtime type checking and error reporting The schema system ensures that authorization data maintains integrity throughout processing, preventing type mismatches that could lead to authorization failures or security vulnerabilities.

View source


Returns

CollectionSchemaInterface — The schema definition containing validation rules and type constraints for this collection


some

public function some(callable $callback): bool

Check if at least one item in the collection matches the given condition. This method tests whether at least one item in the collection satisfies the provided callback function. Returns true if any item passes the test, false if all items fail.

View source


Parameters

Name Type Description
$callback callable

Returns

bool — True if any item matches the condition, false otherwise


toArray

public function toArray(): array

Convert the collection to a standard PHP array. This method creates a native PHP array containing all items in the collection, preserving their order and indexes.

View source


Returns

array — A standard PHP array containing all collection items


valid

public function valid(): bool

Check if the current iterator position is valid. This method determines whether the current iterator position points to a valid item in the collection.

View source


Returns

bool — True if the current position is valid, false otherwise


withItems

public function withItems(mixed $items): static

Create a new collection with the specified items. This method creates a fresh collection instance containing only the provided items, leaving the original collection unchanged.

View source


Parameters

Name Type Description
$items mixed

Returns

static — A new collection instance containing the specified items

⚠️ **GitHub.com Fallback** ⚠️