interface ApiKeyRepositoryInterface (View source)

Persistence for API keys: lookup by key value or owner, creation, expiry and usage tracking.

Methods

array
getAll(int|null $userId = null)

Get all API keys

ApiKey|null
findById(int $id)

Find an API key by ID

ApiKey|null
findBySecretKey(string $secretKey)

Find an API key by its secret key value

save(ApiKey $apiKey)

Save an API key

bool
delete(int $id)

Delete an API key

bool
updateLastUsed(int $id)

Update the last used timestamp of an API key

bool
disable(int $id)

Disable an API key

bool
enable(int $id)

Enable an API key

int
countByUser(int $userId)

Count number of API keys for a user

array
getZoneIds(int $apiKeyId)

Get the zone IDs an API key is restricted to

void
saveZoneIds(int $apiKeyId, array $zoneIds)

Replace the set of zone IDs an API key is restricted to

Details

array getAll(int|null $userId = null)

Get all API keys

Parameters

int|null $userId

Optional user ID to filter by creator

Return Value

array

Array of API keys

ApiKey|null findById(int $id)

Find an API key by ID

Parameters

int $id

The ID of the API key to find

Return Value

ApiKey|null

The API key, or null if not found

ApiKey|null findBySecretKey(string $secretKey)

Find an API key by its secret key value

Parameters

string $secretKey

The secret key to find

Return Value

ApiKey|null

The API key, or null if not found

ApiKey save(ApiKey $apiKey)

Save an API key

Parameters

ApiKey $apiKey

The API key to save

Return Value

ApiKey

The saved API key with ID updated if it was a new key

bool delete(int $id)

Delete an API key

Parameters

int $id

The ID of the API key to delete

Return Value

bool

True if the API key was deleted, false otherwise

bool updateLastUsed(int $id)

Update the last used timestamp of an API key

Parameters

int $id

The ID of the API key to update

Return Value

bool

True if the API key was updated, false otherwise

bool disable(int $id)

Disable an API key

Parameters

int $id

The ID of the API key to disable

Return Value

bool

True if the API key was disabled, false otherwise

bool enable(int $id)

Enable an API key

Parameters

int $id

The ID of the API key to enable

Return Value

bool

True if the API key was enabled, false otherwise

int countByUser(int $userId)

Count number of API keys for a user

Parameters

int $userId

The user ID

Return Value

int

Number of API keys

array getZoneIds(int $apiKeyId)

Get the zone IDs an API key is restricted to

Parameters

int $apiKeyId

The ID of the API key

Return Value

array

The zone IDs (empty array means no restriction)

void saveZoneIds(int $apiKeyId, array $zoneIds)

Replace the set of zone IDs an API key is restricted to

Parameters

int $apiKeyId

The ID of the API key

array $zoneIds

The zone IDs to store (empty array clears the restriction)

Return Value

void