KMP PHP API Reference

TenantProvisioningService
in package

Provisions tenant metadata, database resources, migrations, and lifecycle state.

Table of Contents

Constants

PLATFORM_CONNECTION  : mixed = 'platform'
TENANT_CONNECTION  : mixed = 'tenant_provision'

Properties

$platformConnection  : Connection|null

Methods

__construct()  : mixed
provision()  : TenantProvisioningResult
Provision a tenant. Database creation and migrations require CLI/worker context.
assertDedicatedRuntimeRole()  : void
Reject reuse of the platform/default runtime credentials before provisioning writes.
assertValidBlobContainer()  : void
Validate Azure blob container naming.
assertValidHost()  : void
Validate DNS hostname input.
assertValidIdentifier()  : void
Validate PostgreSQL identifier input.
assertValidSlug()  : void
Validate tenant slug format.
assertWorkerContext()  : void
Prevent privileged database work from normal HTTP requests.
configureNamedTenantConnection()  : void
Configure a named tenant datasource for privilege checks.
configureTenantConnection()  : void
Configure the tenant provisioning datasource.
ensureInitialSuperUser()  : void
Create the initial tenant Admin account so the tenant can claim access through forgot password.
ensureKingdomBranch()  : int
Ensure the tenant root branch exists for the initial super-user account.
ensureMemberRole()  : void
Ensure the initial member has the Super User role.
ensurePassword()  : SensitiveString
Ensure the tenant database password exists in the configured secret store.
ensurePermission()  : int
Ensure the permission that marks a role as super-user exists.
ensureRolePermission()  : void
Ensure the Super User role grants super-user permission.
ensureSuperUserMember()  : int
Ensure the initial member account exists with no known password.
ensureSuperUserRole()  : int
Ensure the initial Super User role exists.
envFlag()  : bool
Read a boolean environment flag.
generatePassword()  : string
Generate a tenant database password.
generatePublicId()  : string
Generate an 8-character public ID that is unique in the tenant table.
markTenantStatus()  : void
Mark final tenant lifecycle state after provisioning.
maybeCreateDatabase()  : void
Create or update PostgreSQL tenant database resources.
now()  : string
Return current UTC database timestamp.
platformConnection()  : Connection
Return the platform metadata connection.
pluginsWithMigrations()  : array<int, string>
progress()  : void
Emit progress when a callback is available.
readSchemaVersion()  : string|null
Read the latest tenant migration version.
runTenantMigrations()  : string|null
Configure and run tenant app/plugin migrations.
shouldCreateDatabase()  : bool
Determine whether automatic tenant database creation is enabled.
smokeTestTenantDatabase()  : void
Smoke-test the migrated tenant database.
upsertTenantHost()  : void
Create or update the primary host row for a tenant.
upsertTenantMetadata()  : array<string, mixed>
validateRequest()  : void
Validate tenant provisioning input before side effects.

Constants

Properties

Methods

__construct()

public __construct([Connection|null $platformConnection = null ]) : mixed
Parameters
$platformConnection : Connection|null = null

Optional platform connection override

provision()

Provision a tenant. Database creation and migrations require CLI/worker context.

public provision(TenantProvisioningRequest $request[, callable|null $commandRunner = null ][, callable|null $progress = null ]) : TenantProvisioningResult
Parameters
$request : TenantProvisioningRequest
$commandRunner : callable|null = null

Callable receiving (object|string $command, list $args): int|null

$progress : callable|null = null

Callable receiving (string $level, string $message): void

Return values
TenantProvisioningResult

assertValidBlobContainer()

Validate Azure blob container naming.

private assertValidBlobContainer(string $container) : void
Parameters
$container : string

assertValidHost()

Validate DNS hostname input.

private assertValidHost(string $host) : void
Parameters
$host : string

assertValidIdentifier()

Validate PostgreSQL identifier input.

private assertValidIdentifier(string $identifier, string $label) : void
Parameters
$identifier : string
$label : string

assertValidSlug()

Validate tenant slug format.

private assertValidSlug(string $slug) : void
Parameters
$slug : string

configureNamedTenantConnection()

Configure a named tenant datasource for privilege checks.

private configureNamedTenantConnection(string $connectionName, string $dbName, string $dbRole, SensitiveString $password) : void
Parameters
$connectionName : string
$dbName : string
$dbRole : string
$password : SensitiveString

configureTenantConnection()

Configure the tenant provisioning datasource.

private configureTenantConnection(string $dbServer, string $dbName, string $dbRole, SensitiveString $password) : void
Parameters
$dbServer : string
$dbName : string
$dbRole : string
$password : SensitiveString

ensureKingdomBranch()

Ensure the tenant root branch exists for the initial super-user account.

private ensureKingdomBranch(Connection $connection, string $now) : int
Parameters
$connection : Connection
$now : string
Return values
int

ensureMemberRole()

Ensure the initial member has the Super User role.

private ensureMemberRole(Connection $connection, int $memberId, int $roleId, int $branchId, string $now) : void
Parameters
$connection : Connection
$memberId : int
$roleId : int
$branchId : int
$now : string

ensurePermission()

Ensure the permission that marks a role as super-user exists.

private ensurePermission(Connection $connection, string $now) : int
Parameters
$connection : Connection
$now : string
Return values
int

ensureRolePermission()

Ensure the Super User role grants super-user permission.

private ensureRolePermission(Connection $connection, int $roleId, int $permissionId, string $now) : void
Parameters
$connection : Connection
$roleId : int
$permissionId : int
$now : string

ensureSuperUserRole()

Ensure the initial Super User role exists.

private ensureSuperUserRole(Connection $connection, string $now) : int
Parameters
$connection : Connection
$now : string
Return values
int

envFlag()

Read a boolean environment flag.

private envFlag(string $name) : bool
Parameters
$name : string
Return values
bool

generatePassword()

Generate a tenant database password.

private generatePassword() : string
Return values
string

generatePublicId()

Generate an 8-character public ID that is unique in the tenant table.

private generatePublicId(Connection $connection, string $table) : string
Parameters
$connection : Connection
$table : string
Return values
string

markTenantStatus()

Mark final tenant lifecycle state after provisioning.

private markTenantStatus(Connection $connection, string $tenantId, string $status, string|null $schemaVersion) : void
Parameters
$connection : Connection
$tenantId : string
$status : string
$schemaVersion : string|null

platformConnection()

Return the platform metadata connection.

private platformConnection() : Connection
Return values
Connection

pluginsWithMigrations()

private pluginsWithMigrations() : array<int, string>
Return values
array<int, string>

progress()

Emit progress when a callback is available.

private progress(callable|null $progress, string $level, string $message) : void
Parameters
$progress : callable|null
$level : string
$message : string

readSchemaVersion()

Read the latest tenant migration version.

private readSchemaVersion() : string|null
Return values
string|null

smokeTestTenantDatabase()

Smoke-test the migrated tenant database.

private smokeTestTenantDatabase(string $table, callable|null $progress) : void
Parameters
$table : string
$progress : callable|null

upsertTenantHost()

Create or update the primary host row for a tenant.

private upsertTenantHost(Connection $connection, string $tenantId, string $host) : void
Parameters
$connection : Connection
$tenantId : string
$host : string
On this page

Search results