API Models Collections TypeDefinitionRelationsInterface - evansims/openfga-php GitHub Wiki
Table of Contents
OpenFGA\Models\Collections
KeyedCollectionInterface
Traversable
JsonSerializable
Iterator
Countable
ArrayAccess
- TypeDefinitionRelations (implementation)
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.
Name | Type | Description |
---|---|---|
$key |
string |
The string key to associate with the item |
$item |
T |
The item to add to the collection |
static
public function count(): int<0, max>
int<
0,
max>
public function current(): T
T
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.
Name | Type | Description |
---|---|---|
$key |
string |
The key of the item to retrieve |
T
| null
— The item associated with the key, or null if not found
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.
Name | Type | Description |
---|---|---|
$key |
string |
The key to check for existence |
bool
— True if the key exists, false otherwise
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.
bool
— True if the collection is empty, false otherwise
public function jsonSerialize(): array<string, mixed>
Serialize the collection to an array.
array<
string,
mixed>
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.
string
— The current iterator key
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.
void
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.
Name | Type | Description |
---|---|---|
$offset |
mixed |
The key to check for existence |
bool
— True if the key exists, false otherwise
public function offsetGet(mixed $offset): T|null
Get an item by its offset key.
Name | Type | Description |
---|---|---|
$offset |
mixed |
T
| null
public function offsetSet(string|null $offset, T $value): void
Name | Type | Description |
---|---|---|
$offset |
string | null
|
|
$value |
T |
void
public function offsetUnset(mixed $offset): void
Name | Type | Description |
---|---|---|
$offset |
mixed |
void
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.
void
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.
array<
string,
T>
— An associative array containing all collection items
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.
bool
— True if the current position is valid, false otherwise