API Services StoreServiceInterface - evansims/openfga-php GitHub Wiki
Service interface for high-level store operations. This interface provides a business-focused abstraction over store management, offering convenience methods and enhanced validation beyond basic CRUD operations. It simplifies common store workflows while maintaining the Result pattern for consistent error handling across the SDK.
Table of Contents
OpenFGA\Services
- StoreService (implementation)
public function createStore(string $name): FailureInterface|SuccessInterface
Creates a new store with validation. This method creates a new OpenFGA store after validating the provided name. It ensures the name meets requirements before attempting creation, providing clearer error messages than the raw API when validation fails.
Name | Type | Description |
---|---|---|
$name |
string |
The name for the new store (must not be empty) |
FailureInterface
| SuccessInterface
— Success containing the created Store, or Failure with error details
public function deleteStore(string $storeId, bool $confirmExists = true): FailureInterface|SuccessInterface
Deletes a store with optional confirmation. This method deletes a store after optionally verifying it exists first. When confirmation is enabled, it provides clearer error messages if the store doesn't exist, preventing confusion about failed delete operations.
Name | Type | Description |
---|---|---|
$storeId |
string |
The ID of the store to delete |
$confirmExists |
bool |
Whether to verify the store exists before deletion |
FailureInterface
| SuccessInterface
— Success with null value, or Failure with error details
public function findStore(string $storeId): FailureInterface|SuccessInterface
Finds a store by ID with enhanced error handling. This method retrieves a store by its ID, providing more descriptive error messages when the store is not found or when other errors occur. It helps distinguish between "not found" and other types of failures.
Name | Type | Description |
---|---|---|
$storeId |
string |
The ID of the store to find |
FailureInterface
| SuccessInterface
— Success containing the Store, or Failure with detailed error context
public function findStoresByName(string $pattern, int|null $maxItems = NULL): FailureInterface|SuccessInterface
Finds stores by name pattern. This method searches for stores whose names match a given pattern, supporting basic wildcard matching. It's useful for finding stores in multi-tenant scenarios or when working with naming conventions.
Name | Type | Description |
---|---|---|
$pattern |
string |
The name pattern to match (supports * as wildcard) |
$maxItems |
int | null
|
Maximum number of matching stores to return |
FailureInterface
| SuccessInterface
— Success containing Stores collection of matches, or Failure with error details
public function getOrCreateStore(string $name): FailureInterface|SuccessInterface
Gets an existing store or creates a new one with the given name. This convenience method first attempts to find a store by name among existing stores. If no store with the given name exists, it creates a new one. This is useful for idempotent store setup in development or testing scenarios. Note: This method lists all stores to find matches by name, which may be inefficient with large numbers of stores.
Name | Type | Description |
---|---|---|
$name |
string |
The name of the store to find or create |
FailureInterface
| SuccessInterface
— Success containing the Store (existing or new), or Failure with error details
public function listAllStores(int|null $maxItems = NULL): FailureInterface|SuccessInterface
Lists all stores with simplified pagination. This method retrieves all accessible stores, automatically handling pagination to return a complete collection. It abstracts away the complexity of dealing with continuation tokens for most use cases.
Name | Type | Description |
---|---|---|
$maxItems |
int | null
|
Maximum number of stores to retrieve (null for all) |
FailureInterface
| SuccessInterface
— Success containing Stores collection, or Failure with error details
public function listStores(
string|null $continuationToken = NULL,
int|null $pageSize = NULL,
): FailureInterface|SuccessInterface
Lists stores with pagination support. This method retrieves stores with explicit pagination control, allowing you to specify continuation tokens for iterating through large result sets.
Name | Type | Description |
---|---|---|
$continuationToken |
string | null
|
Token from previous response to get next page |
$pageSize |
int | null
|
Maximum number of stores to return per page |
FailureInterface
| SuccessInterface
— Success containing Stores collection, or Failure with error details