API Repositories TupleRepositoryInterface - evansims/openfga-php GitHub Wiki

Repository contract for relationship tuple operations. This interface defines the contract for managing relationship tuples within an OpenFGA store. Tuples represent relationships between users and objects (for example "user:anne is reader of document:budget"), forming the core data that drives authorization decisions. The repository supports both transactional and non-transactional operations for different scale and consistency requirements. All methods return Result objects following the Result pattern, allowing for consistent error handling without exceptions.

Table of Contents


Namespace

OpenFGA\Repositories


Source

View source code


Methods

delete

public function delete(
    StoreInterface $store,
    AuthorizationModelInterface $model,
    TupleKeysInterface $tuples,
    bool $transactional = true,
    array<string, mixed> $options = [],
): FailureInterface|SuccessInterface

Delete relationship tuples from the store. Removes existing relationship tuples from the store. Like write operations, supports both transactional and non-transactional modes with the same constraints and options.

View source


Parameters

Name Type Description
$store StoreInterface The store containing the tuples
$model AuthorizationModelInterface The authorization model to validate against
$tuples TupleKeysInterface The tuples to delete
$transactional bool Whether to use transactional mode (default: true)
$options array&lt;string, mixed&gt;

Returns

FailureInterface | SuccessInterface — Success with WriteTuplesResponse containing operation results, or Failure with error details


listChanges

public function listChanges(
    StoreInterface $store,
    string|null $type = NULL,
    DateTimeImmutable|null $startTime = NULL,
    string|null $continuationToken = NULL,
    int|null $pageSize = NULL,
): FailureInterface|SuccessInterface

List changes to relationship tuples over time. Retrieves a chronological log of tuple changes (writes and deletes) within the store. Useful for auditing, synchronization, or understanding how relationships evolved. Results can be filtered by object type and time range.

View source


Parameters

Name Type Description
$store StoreInterface The store to query
$type string | null Filter by object type (for example "document")
$startTime DateTimeImmutable | null Filter changes after this time
$continuationToken string | null Token from previous response for pagination
$pageSize int | null Maximum number of changes to return

Returns

FailureInterface | SuccessInterface — Success with ListTupleChangesResponse containing change history, or Failure with error details


read

public function read(
    StoreInterface $store,
    TupleKeyInterface $filter,
    string|null $continuationToken = NULL,
    int|null $pageSize = NULL,
): FailureInterface|SuccessInterface

Read relationship tuples from the store. Retrieves tuples matching the specified filter criteria. The filter uses partial matching - you can specify any combination of user, relation, and object to narrow results. Results are paginated for efficient retrieval of large datasets.

View source


Parameters

Name Type Description
$store StoreInterface The store containing the tuples
$filter TupleKeyInterface Filter criteria for tuple matching
$continuationToken string | null Token from previous response for pagination
$pageSize int | null Maximum number of tuples to return (1-100)

Returns

FailureInterface | SuccessInterface — Success with ReadTuplesResponse containing matching tuples, or Failure with error details


write

public function write(
    StoreInterface $store,
    AuthorizationModelInterface $model,
    TupleKeysInterface $tuples,
    bool $transactional = true,
    array<string, mixed> $options = [],
): FailureInterface|SuccessInterface

Write relationship tuples to the store. Creates new relationship tuples in the store. Supports both transactional mode (all-or-nothing, limited to 100 tuples) and non-transactional mode for larger batches with configurable parallelism and retry behavior.

View source


Parameters

Name Type Description
$store StoreInterface The store to write tuples to
$model AuthorizationModelInterface The authorization model to validate against
$tuples TupleKeysInterface The tuples to write
$transactional bool Whether to use transactional mode (default: true)
$options array&lt;string, mixed&gt;

Returns

FailureInterface | SuccessInterface — Success with WriteTuplesResponse containing operation results, or Failure with error details


writeAndDelete

public function writeAndDelete(
    StoreInterface $store,
    AuthorizationModelInterface $model,
    TupleKeysInterface|null $writes = NULL,
    TupleKeysInterface|null $deletes = NULL,
    bool $transactional = true,
    array<string, mixed> $options = [],
): FailureInterface|SuccessInterface

Write and delete relationship tuples in a single operation. Combines write and delete operations for efficiency, especially useful when you need to atomically replace relationships. In transactional mode, all operations succeed or fail together. In non-transactional mode, operations are batched for optimal performance.

View source


Parameters

Name Type Description
$store StoreInterface The store to operate on
$model AuthorizationModelInterface The authorization model to validate against
$writes TupleKeysInterface | null Tuples to write (optional)
$deletes TupleKeysInterface | null Tuples to delete (optional)
$transactional bool Whether to use transactional mode (default: true)
$options array&lt;string, mixed&gt;

Returns

FailureInterface | SuccessInterface — Success with WriteTuplesResponse containing operation results, or Failure with error details

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