class ApiKey implements JsonSerializable (View source)

Class ApiKey

Represents an API key entity that can be used for API authentication

Methods

__construct(string $name, string $secretKey, int|null $createdBy = null, DateTime|null $createdAt = null, DateTime|null $lastUsedAt = null, bool $disabled = false, DateTime|null $expiresAt = null, int|null $id = null)

ApiKey constructor.

static string
generateSecretKey()

Generate a new random API key with 'pwa_' prefix

int|null
getId()

Gets the ID of this API key (null if not saved)

void
setId(int|null $id)

Sets the ID of this API key

string
getName()

Gets the name of this API key

void
setName(string $name)

Sets the name of this API key

string
getSecretKey()

Gets the secret key of this API key

void
setSecretKey(string $secretKey)

Sets the secret key of this API key

int|null
getCreatedBy()

Gets the user ID who created this API key

void
setCreatedBy(int|null $createdBy)

Sets the user ID who created this API key

getCreatedAt()

Gets the creation date of this API key

void
setCreatedAt(DateTime $createdAt)

Sets the creation date of this API key

DateTime|null
getLastUsedAt()

Gets the date this API key was last used

void
setLastUsedAt(DateTime|null $lastUsedAt)

Sets the date this API key was last used

void
updateLastUsed()

Updates the last used timestamp to now

bool
isDisabled()

Checks if this API key is disabled

void
setDisabled(bool $disabled)

Sets whether this API key is disabled

DateTime|null
getExpiresAt()

Gets the expiration date of this API key

void
setExpiresAt(DateTime|null $expiresAt)

Sets the expiration date of this API key

bool
hasExpired()

Checks if this API key has expired

bool
isValid()

Checks if this API key is valid (not expired and not disabled)

ApiKeyStatus
status()

Lifecycle state, derived from the disabled flag and the expiry date.

string
regenerateSecretKey()

Regenerate the secret key

string
getCreatorUsername()

Gets the creator username

void
setCreatorUsername(string $creatorUsername)

Sets the creator username

string
getCreatorFullname()

Gets the creator fullname

void
setCreatorFullname(string $creatorFullname)

Sets the creator fullname

bool
isReadonly()

Whether this API key is restricted to read-only (view/GET) requests

void
setIsReadonly(bool $isReadonly)

Set whether this API key is restricted to read-only requests

array|null
getAllowedOperations()

Operations the key may perform (view/create/update/delete); null means all

void
setAllowedOperations(array|null $allowedOperations)

Set the operations the key may perform; null/empty means all

array|null
getZoneIds()

Zones the key is restricted to; null/empty means no restriction

void
setZoneIds(array|null $zoneIds)

Set the zones the key is restricted to; null/empty means no restriction

array
jsonSerialize()

Specifies data which should be serialized to JSON

Details

__construct(string $name, string $secretKey, int|null $createdBy = null, DateTime|null $createdAt = null, DateTime|null $lastUsedAt = null, bool $disabled = false, DateTime|null $expiresAt = null, int|null $id = null)

ApiKey constructor.

Parameters

string $name

The name of the API key

string $secretKey

The secret key used for authentication

int|null $createdBy

User ID who created this key

DateTime|null $createdAt

When the key was created

DateTime|null $lastUsedAt

When the key was last used

bool $disabled

Whether the key is disabled

DateTime|null $expiresAt

When the key expires (null means no expiration)

int|null $id

Optional ID if retrieved from database

static string generateSecretKey()

Generate a new random API key with 'pwa_' prefix

Return Value

string

A random API key string with 'pwa_' prefix

int|null getId()

Gets the ID of this API key (null if not saved)

Return Value

int|null

The ID of this API key

void setId(int|null $id)

Sets the ID of this API key

Parameters

int|null $id

The ID to set

Return Value

void

string getName()

Gets the name of this API key

Return Value

string

The name of this API key

void setName(string $name)

Sets the name of this API key

Parameters

string $name

The name to set

Return Value

void

string getSecretKey()

Gets the secret key of this API key

Return Value

string

The secret key

void setSecretKey(string $secretKey)

Sets the secret key of this API key

Parameters

string $secretKey

The secret key to set

Return Value

void

int|null getCreatedBy()

Gets the user ID who created this API key

Return Value

int|null

The user ID

void setCreatedBy(int|null $createdBy)

Sets the user ID who created this API key

Parameters

int|null $createdBy

The user ID to set

Return Value

void

DateTime getCreatedAt()

Gets the creation date of this API key

Return Value

DateTime

The creation date

void setCreatedAt(DateTime $createdAt)

Sets the creation date of this API key

Parameters

DateTime $createdAt

The creation date to set

Return Value

void

DateTime|null getLastUsedAt()

Gets the date this API key was last used

Return Value

DateTime|null

The last used date, or null if never used

void setLastUsedAt(DateTime|null $lastUsedAt)

Sets the date this API key was last used

Parameters

DateTime|null $lastUsedAt

The last used date to set

Return Value

void

void updateLastUsed()

Updates the last used timestamp to now

Return Value

void

bool isDisabled()

Checks if this API key is disabled

Return Value

bool

True if this API key is disabled, false otherwise

void setDisabled(bool $disabled)

Sets whether this API key is disabled

Parameters

bool $disabled

True to disable this API key, false to enable it

Return Value

void

DateTime|null getExpiresAt()

Gets the expiration date of this API key

Return Value

DateTime|null

The expiration date, or null if it never expires

void setExpiresAt(DateTime|null $expiresAt)

Sets the expiration date of this API key

Parameters

DateTime|null $expiresAt

The expiration date to set

Return Value

void

bool hasExpired()

Checks if this API key has expired

Return Value

bool

True if this API key has expired, false otherwise

bool isValid()

Checks if this API key is valid (not expired and not disabled)

Return Value

bool

True if this API key is valid, false otherwise

ApiKeyStatus status()

Lifecycle state, derived from the disabled flag and the expiry date.

Disabled wins when both apply, matching what the key list displays.

Return Value

ApiKeyStatus

string regenerateSecretKey()

Regenerate the secret key

Return Value

string

The new secret key

string getCreatorUsername()

Gets the creator username

Return Value

string

The creator username

void setCreatorUsername(string $creatorUsername)

Sets the creator username

Parameters

string $creatorUsername

The creator username to set

Return Value

void

string getCreatorFullname()

Gets the creator fullname

Return Value

string

The creator fullname

void setCreatorFullname(string $creatorFullname)

Sets the creator fullname

Parameters

string $creatorFullname

The creator fullname to set

Return Value

void

bool isReadonly()

Whether this API key is restricted to read-only (view/GET) requests

Return Value

bool

void setIsReadonly(bool $isReadonly)

Set whether this API key is restricted to read-only requests

Parameters

bool $isReadonly

Return Value

void

array|null getAllowedOperations()

Operations the key may perform (view/create/update/delete); null means all

Return Value

array|null

void setAllowedOperations(array|null $allowedOperations)

Set the operations the key may perform; null/empty means all

Parameters

array|null $allowedOperations

Return Value

void

array|null getZoneIds()

Zones the key is restricted to; null/empty means no restriction

Return Value

array|null

void setZoneIds(array|null $zoneIds)

Set the zones the key is restricted to; null/empty means no restriction

Parameters

array|null $zoneIds

Return Value

void

array jsonSerialize()

Specifies data which should be serialized to JSON

Return Value

array