API Models Collections RelationMetadataCollection - evansims/openfga-php GitHub Wiki
Collection implementation for OpenFGA relation metadata objects. This class provides a concrete implementation for managing keyed collections of relation metadata objects. Relation metadata provides additional context about relations defined in authorization model type definitions, including module information and source file details. The collection uses relation names as keys, enabling efficient retrieval of metadata for specific relations within a type definition.
Table of Contents
OpenFGA\Models\Collections
KeyedCollectionInterface
Traversable
JsonSerializable
Iterator
Countable
ArrayAccess
RelationMetadataCollectionInterface
- RelationMetadata (item)
- RelationMetadataCollectionInterface (interface)
public function add(string $key, OpenFGA\Models\ModelInterface $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 |
ModelInterface |
The item to add to the collection |
static
public function count(): int<0, max>
int<
0,
max>
public function current(): OpenFGA\Models\ModelInterface
public function get(string $key)
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 |
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>
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): ?OpenFGA\Models\ModelInterface
Get an item by its offset key.
Name | Type | Description |
---|---|---|
$offset |
mixed |
ModelInterface
| null
public function offsetSet(mixed $offset, mixed $value): void
Name | Type | Description |
---|---|---|
$offset |
mixed |
|
$value |
mixed |
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
Implements Models\Collections\KeyedCollectionInterface
public function schema(): CollectionSchemaInterface
Get the schema definition for this collection type. Returns the schema that defines the structure and validation rules for this collection, including the expected item type and constraints.
CollectionSchemaInterface
— The collection schema
public function toArray(): array
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
— 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