src/site/php host-helpers.php

Functions

cfw_host()

cfw_host(string  $name) : mixed

Reads a capability the host installed on the Module.

Parameters

string $name

The capability the host installed on the Module.

Returns

mixed —

The host function, or NULL when there is no bridge.

cfw_call()

cfw_call(callable  $fn, array  $payload) : array<string,mixed>

Sends one request across the bridge and decodes the reply.

Parameters

callable $fn

The host function from cfw_host().

array $payload

The request, run through the pw codec.

Returns

array —

The decoded reply, or an ok => false refusal naming what went wrong.

cfw_sql()

cfw_sql(string  $sql, array  $params = []) : array<string,mixed>

Runs one SQL statement on the object's database.

Parameters

string $sql

One statement.

array $params

Positional or named bindings.

Returns

array —

The host reply: ok, and rows on a read.

cfw_txn()

cfw_txn(array}>  $statements, bool  $commit = true, array{sql: string, params: array}|null  $read = null) : array<string,mixed>

Runs statements in one transaction, optionally reading inside it.

Parameters

array}> $statements

The statements to run in one transaction.

bool $commit

Whether to commit rather than roll back.

array{sql: string, params: array}|null $read

A statement to run inside the transaction and report.

Returns

array —

The host reply: ok, and readResult when a read was asked for.