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

Table of Contents


Namespace

OpenFGA\Models\Collections


Source

View source code


Implements


Related Classes


Methods

add

public function add(string $key, T $item): static

Add an item to the collection with the specified key. This method associates an item with a string key, allowing for named access to collection elements similar to an associative array.

View source


Parameters

Name Type Description
$key string The string key to associate with the item
$item T The item to add to the collection

Returns

static


count

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

View source


Returns

int&lt;0, max&gt;


current

public function current(): T

View source


Returns

T


get

public function get(string $key): T|null

Get an item by its string key. This method retrieves the item associated with the specified key. Returns null if no item is found with the given key.

View source


Parameters

Name Type Description
$key string The key of the item to retrieve

Returns

T | null — The item associated with the key, or null if not found


has

public function has(string $key): bool

Check if a key exists in the collection. This method determines whether the collection contains an item associated with the specified key.

View source


Parameters

Name Type Description
$key string The key to check for existence

Returns

bool — True if the key exists, false otherwise


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<string, mixed>

Serialize the collection to an array.

View source


Returns

array&lt;string, mixed&gt;


key

public function key(): string

Get the current iterator key. This method returns the current string key in the collection iteration. For keyed collections, this is always a string identifier.

View source


Returns

string — The current iterator key


next

public function next(): void

Move the iterator to the next position. This method advances the internal iterator pointer to the next key-value pair in the collection.

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 with the specified key.

View source


Parameters

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

Returns

bool — True if the key exists, false otherwise


offsetGet

public function offsetGet(mixed $offset): T|null

Get an item by its offset key.

View source


Parameters

Name Type Description
$offset mixed

Returns

T | null


offsetSet

public function offsetSet(string|null $offset, T $value): void

View source


Parameters

Name Type Description
$offset string | null
$value T

Returns

void


offsetUnset

public function offsetUnset(mixed $offset): void

View source


Parameters

Name Type Description
$offset mixed

Returns

void


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 key-value pair in the collection.

View source


Returns

void


toArray

public function toArray(): array<string, T>

Convert the collection to a standard PHP associative array. This method creates a native PHP associative array containing all items in the collection, preserving their string keys and values.

View source


Returns

array&lt;string, T&gt; — An associative 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 key-value pair in the collection.

View source


Returns

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

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