ApiKey
class ApiKey implements JsonSerializable (View source)
Class ApiKey
Represents an API key entity that can be used for API authentication
Methods
ApiKey constructor.
Generate a new random API key with 'pwa_' prefix
Gets the ID of this API key (null if not saved)
Sets the ID of this API key
Gets the name of this API key
Sets the name of this API key
Gets the secret key of this API key
Sets the secret key of this API key
Gets the user ID who created this API key
Sets the user ID who created this API key
Gets the creation date of this API key
Gets the date this API key was last used
Updates the last used timestamp to now
Checks if this API key is disabled
Sets whether this API key is disabled
Gets the expiration date of this API key
Checks if this API key has expired
Checks if this API key is valid (not expired and not disabled)
Lifecycle state, derived from the disabled flag and the expiry date.
Regenerate the secret key
Gets the creator username
Sets the creator username
Gets the creator fullname
Sets the creator fullname
Whether this API key is restricted to read-only (view/GET) requests
Set whether this API key is restricted to read-only requests
Operations the key may perform (view/create/update/delete); null means all
Set the operations the key may perform; null/empty means all
Zones the key is restricted to; null/empty means no restriction
Set the zones the key is restricted to; null/empty means no restriction
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.
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
DateTime
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.
Disabled wins when both apply, matching what the key list displays.
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