CoolCMS API

ApiClientKey extends BaseEntity
in package
implements IdentifiableInterface uses IdentifiableTrait

AbstractYes

Key of an external Api application (`cms_system_api_client_keys`).

An application (ApiClient) may have several keys; each has an optional expiry (expiresAt, null = valid until someone revokes it). A key is valid when it is not revoked and either has no expiry or the expiry has not passed; whether the application gets data is additionally decided by the application switch and revocation.

The table is read and written only by ApiClientRepository via plain DBAL; the entity exists for the mapping and as the single place describing the columns.

IMPORTANT: keyHash (sha256 of the key) never leaves the Api, not even to an administrator (FieldAccess None), and cannot be written by the generic save; it is created only in the manager.

Attributes
#[MappedSuperclass]
#[TableAlias]
$alias: 'apiClientKey'

Table of Contents

Interfaces

IdentifiableInterface
Entity with a simple integer primary key. Most entities have one (often via {@see \App\Core\Traits\Shared\Models\Entities\IdentifiableTrait}); texts and links with a composite key do not, which is why `getId()` is not on {@see \App\Core\Base\BaseEntity}. Code that needs the id of a generic entity asks for this interface (parameter type, template bound, `instanceof`).

Properties

$apiClientId  : int
$createdAt  : DateTime|null
$expiresAt  : DateTime|null
$id  : int|null
$keyHash  : string
$keyPrefix  : string
$label  : string|null
$lastUsedAt  : DateTime|null
$revokedAt  : DateTime|null

Methods

__construct()  : mixed
callInitMethods()  : void
Calls `init{TraitName}()` for every used trait that defines such a method.
getAllTraits()  : array<string, string>
Returns all traits the class uses, including those used by parent classes and nested traits.
getApiClientId()  : int
getCreatedAt()  : DateTime|null
getExpiresAt()  : DateTime|null
getId()  : int|null
getKeyHash()  : string
getKeyPrefix()  : string
getLabel()  : string|null
getLastUsedAt()  : DateTime|null
getRevokedAt()  : DateTime|null
isExpired()  : bool
Returns whether the key has expired at the given moment (default now); never without an expiry.
isPersisted()  : bool
isRevoked()  : bool
isValid()  : bool
Returns whether the key is valid: not revoked and not expired.
setApiClientId()  : $this
setCreatedAt()  : $this
setExpiresAt()  : $this
setId()  : $this
setKeyHash()  : $this
setKeyPrefix()  : $this
setLabel()  : $this
setLastUsedAt()  : $this
setRevokedAt()  : $this
getTraitsRecursive()  : array<string, string>
Walks the trait list recursively and collects nested traits too.

Properties

$apiClientId

protected int $apiClientId = 0
Attributes
#[Column]
$name: 'cms_system_api_clients_api_client_id'
$type: 'integer'
$options: ['unsigned' => true]
#[FieldAccess]
$read: Audience::Privileged
$insert: Audience::None
$update: Audience::None

$createdAt

protected DateTime|null $createdAt = null
Attributes
#[Column]
$name: 'created_at'
$type: 'datetime'

$expiresAt

protected DateTime|null $expiresAt = null
Attributes
#[Column]
$name: 'expires_at'
$type: 'datetime'
$nullable: true

$id

protected int|null $id = null
Attributes
#[Column]
$type: 'integer'
$name: 'api_client_key_id'
$options: ['unsigned' => true]
#[GeneratedValue]
#[Id]

$keyHash

protected string $keyHash = ''
Attributes
#[Column]
$name: 'key_hash'
$type: 'string'
$length: 64
$unique: true
#[FieldAccess]
$read: Audience::None
$insert: Audience::None
$update: Audience::None

$keyPrefix

protected string $keyPrefix = ''
Attributes
#[Column]
$name: 'key_prefix'
$type: 'string'
$length: 20
#[FieldAccess]
$read: Audience::Privileged
$insert: Audience::None
$update: Audience::None

$label

protected string|null $label = null
Attributes
#[Column]
$name: 'label'
$type: 'string'
$length: 100
$nullable: true

$lastUsedAt

protected DateTime|null $lastUsedAt = null
Attributes
#[Column]
$name: 'last_used_at'
$type: 'datetime'
$nullable: true

$revokedAt

protected DateTime|null $revokedAt = null
Attributes
#[Column]
$name: 'revoked_at'
$type: 'datetime'
$nullable: true

Methods

__construct()

public __construct([int|null $id = null ][, int $apiClientId = 0 ][, string $keyHash = '' ][, string $keyPrefix = '' ][, string|null $label = null ][, DateTime|null $createdAt = null ][, DateTime|null $expiresAt = null ][, DateTime|null $revokedAt = null ][, DateTime|null $lastUsedAt = null ]) : mixed
Parameters
$id : int|null = null
$apiClientId : int = 0
$keyHash : string = ''
$keyPrefix : string = ''
$label : string|null = null
$createdAt : DateTime|null = null
$expiresAt : DateTime|null = null
$revokedAt : DateTime|null = null
$lastUsedAt : DateTime|null = null

callInitMethods()

Calls `init{TraitName}()` for every used trait that defines such a method.

public callInitMethods() : void

getAllTraits()

Returns all traits the class uses, including those used by parent classes and nested traits.

public getAllTraits() : array<string, string>
Return values
array<string, string>

getApiClientId()

public getApiClientId() : int
Return values
int

getCreatedAt()

public getCreatedAt() : DateTime|null
Return values
DateTime|null

getExpiresAt()

public getExpiresAt() : DateTime|null
Return values
DateTime|null

getKeyHash()

public getKeyHash() : string
Return values
string

getKeyPrefix()

public getKeyPrefix() : string
Return values
string

getLabel()

public getLabel() : string|null
Return values
string|null

getLastUsedAt()

public getLastUsedAt() : DateTime|null
Return values
DateTime|null

getRevokedAt()

public getRevokedAt() : DateTime|null
Return values
DateTime|null

isExpired()

Returns whether the key has expired at the given moment (default now); never without an expiry.

public isExpired([DateTimeInterface|null $now = null ]) : bool
Parameters
$now : DateTimeInterface|null = null
Return values
bool

isRevoked()

public isRevoked() : bool
Return values
bool

isValid()

Returns whether the key is valid: not revoked and not expired.

public isValid([DateTimeInterface|null $now = null ]) : bool
Parameters
$now : DateTimeInterface|null = null
Return values
bool

setApiClientId()

public setApiClientId(int $apiClientId) : $this
Parameters
$apiClientId : int
Return values
$this

setCreatedAt()

public setCreatedAt(DateTime|null $createdAt) : $this
Parameters
$createdAt : DateTime|null
Return values
$this

setExpiresAt()

public setExpiresAt(DateTime|null $expiresAt) : $this
Parameters
$expiresAt : DateTime|null
Return values
$this

setId()

public setId(int|null $id) : $this
Parameters
$id : int|null
Return values
$this

setKeyHash()

public setKeyHash(string $keyHash) : $this
Parameters
$keyHash : string
Return values
$this

setKeyPrefix()

public setKeyPrefix(string $keyPrefix) : $this
Parameters
$keyPrefix : string
Return values
$this

setLabel()

public setLabel(string|null $label) : $this
Parameters
$label : string|null
Return values
$this

setLastUsedAt()

public setLastUsedAt(DateTime|null $lastUsedAt) : $this
Parameters
$lastUsedAt : DateTime|null
Return values
$this

setRevokedAt()

public setRevokedAt(DateTime|null $revokedAt) : $this
Parameters
$revokedAt : DateTime|null
Return values
$this

getTraitsRecursive()

Walks the trait list recursively and collects nested traits too.

private static getTraitsRecursive(array<string, string> $traits) : array<string, string>
Parameters
$traits : array<string, string>
Return values
array<string, string>
On this page

Search results