class DbApiKeyRepository implements ApiKeyRepositoryInterface (View source)

Class DbApiKeyRepository

Database implementation of the API key repository

Constants

private HASH_PREFIX

Methods

__construct(PDO $db, ConfigurationManager $config, LoggerInterface|null $logger = null)

DbApiKeyRepository constructor

array
getAll(int|null $userId = null)

No description

ApiKey|null
findById(int $id)

No description

ApiKey|null
findBySecretKey(string $secretKey)

No description

static string
hashSecretKey(string $secretKey)

One-way hash applied to API keys before persistence. SHA-256 is sufficient because keys are 256+ bits of entropy from random_bytes(32); brute force across the keyspace is infeasible without a salt. The sha256$ prefix makes hashed entries syntactically distinct from any legacy plaintext key so the plaintext-fallback path can refuse pass-the-hash candidates without also rejecting unusual legacy key formats.

save(ApiKey $apiKey)

No description

bool
delete(int $id)

No description

bool
updateLastUsed(int $id)

No description

bool
disable(int $id)

No description

bool
enable(int $id)

No description

int
countByUser(int $userId)

No description

array
getZoneIds(int $apiKeyId)

No description

void
saveZoneIds(int $apiKeyId, array $zoneIds)

No description

Details

__construct(PDO $db, ConfigurationManager $config, LoggerInterface|null $logger = null)

DbApiKeyRepository constructor

Parameters

PDO $db

The PDO database layer

ConfigurationManager $config

The configuration manager

LoggerInterface|null $logger

The logger instance

array getAll(int|null $userId = null)

No description

Parameters

int|null $userId

Optional user ID to filter by creator

Return Value

array

Array of API keys

ApiKey|null findById(int $id)

No description

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)

No description

Parameters

string $secretKey

The secret key to find

Return Value

ApiKey|null

The API key, or null if not found

static string hashSecretKey(string $secretKey)

One-way hash applied to API keys before persistence. SHA-256 is sufficient because keys are 256+ bits of entropy from random_bytes(32); brute force across the keyspace is infeasible without a salt. The sha256$ prefix makes hashed entries syntactically distinct from any legacy plaintext key so the plaintext-fallback path can refuse pass-the-hash candidates without also rejecting unusual legacy key formats.

Parameters

string $secretKey

Return Value

string

ApiKey save(ApiKey $apiKey)

No description

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)

No description

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)

No description

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)

No description

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)

No description

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)

No description

Parameters

int $userId

The user ID

Return Value

int

Number of API keys

array getZoneIds(int $apiKeyId)

No description

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)

No description

Parameters

int $apiKeyId

The ID of the API key

array $zoneIds

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

Return Value

void