Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

AppKey
in package

FinalYes

The application secret, ZEALPHP_APP_KEY.

Format: base64: followed by the base64 of at least 32 random bytes (php app.php key:generate prints one). A raw string of 32+ bytes is also accepted. Old keys listed in ZEALPHP_APP_KEY_PREVIOUS (comma-separated) are accepted for verifying, never for signing, so a rotation doesn't invalidate pages that are already open.

Callers never use the raw key: derive() gives each purpose its own key via HKDF, so a value signed for one purpose can't be replayed as another.

Table of Contents

Constants

MIN_BYTES  : mixed = 32

Properties

$ephemeral  : bool
$key  : string|null
$previous  : array<int, string>|null

Methods

current()  : string|null
The current key, or null when none is configured.
derive()  : string
The purpose-specific signing key derived from the current key.
deriveAll()  : array<int, string>
Purpose-specific keys from the current key and every previous key, current first — for verification.
generate()  : string
A new key in the base64: format, for ZEALPHP_APP_KEY.
isEphemeral()  : bool
previous()  : array<int, string>
Old keys accepted for verification.
reset()  : void
Forget any cached or configured key (tests).
set()  : void
Set the key in code (tests, or apps that load secrets themselves).
useEphemeral()  : void
Use a random key for this process. Call before workers fork so every worker shares it. Values signed with it stop verifying after a restart.
decode()  : string

Constants

MIN_BYTES

public mixed MIN_BYTES = 32

Properties

$ephemeral

private static bool $ephemeral = false

$key

private static string|null $key = null

$previous

private static array<int, string>|null $previous = null

Methods

current()

The current key, or null when none is configured.

public static current() : string|null
Return values
string|null

derive()

The purpose-specific signing key derived from the current key.

public static derive(string $purpose) : string
Parameters
$purpose : string
Tags
throws
RuntimeException

when no key is configured.

Return values
string

deriveAll()

Purpose-specific keys from the current key and every previous key, current first — for verification.

public static deriveAll(string $purpose) : array<int, string>
Parameters
$purpose : string
Return values
array<int, string>

generate()

A new key in the base64: format, for ZEALPHP_APP_KEY.

public static generate() : string
Return values
string

isEphemeral()

public static isEphemeral() : bool
Return values
bool

previous()

Old keys accepted for verification.

public static previous() : array<int, string>
Return values
array<int, string>

reset()

Forget any cached or configured key (tests).

public static reset() : void

set()

Set the key in code (tests, or apps that load secrets themselves).

public static set(string $key, string ...$previous) : void
Parameters
$key : string
$previous : string

useEphemeral()

Use a random key for this process. Call before workers fork so every worker shares it. Values signed with it stop verifying after a restart.

public static useEphemeral() : void

decode()

private static decode(string $value) : string
Parameters
$value : string
Return values
string
On this page