Skip to content

All functions ​

Every function of the library, with the description from its source. This page is built from src/functions.php of version 0.3.0, so it cannot say something else than the code does.

Import the functions you use, or give the namespace a short name:

php
use function Runio\ScriptUi\{title, text, button, success};

use Runio\ScriptUi as ui;      // then: ui\title('Find orders');
GroupFunctions
Displaytitle heading note code json link divider metric progress success info warning error
Inputstext textarea number select radio multiselect checkbox date_input file_input field_error valid
Datatable chart
Actionsbutton download csv
Flow and layoutcolumns expander tabs refresh stop rerun
Hostinguser configure clean_uploads serve respond

Display ​

title() ​

php
function title(string $text): void

The big heading of the page. The first one also names the browser tab.

heading() ​

php
function heading(string $text): void

A section heading.

note() ​

php
function note(string $text): void

A paragraph of plain text. Line breaks are kept.

code() ​

php
function code(string $text): void

Text in a fixed-width block, for code, SQL or log lines.

json() ​

php
function json(mixed $value): void

Any value as readable JSON.

php
function link(string $label, string $url, bool $newTab = false): void

A link. Only http, https and mailto addresses and paths on this site are accepted.

divider() ​

php
function divider(): void

A thin line between two parts of the page.

metric() ​

php
function metric(string $label, string|int|float $value, string|int|float|null $delta = null, bool $inverse = false): void

One number that matters, with an optional change such as "+4.2%".

  • $inverse (bool): set it when going up is bad news (refunds, errors, churn)

progress() ​

php
function progress(string $label, int|float|null $value = null, int|float $max = 100, ?string $text = null): void

A bar that shows how far a task is: progress('Importing orders', $done, $total).

It draws what the two numbers say in this run, and nothing moves by itself. For a task that runs somewhere else, call refresh() on the same page: every run reads the numbers anew.

  • $label (string): what is counted. It names the bar, also for a screen reader, so it must not be empty
  • $value (int|float|null): how much is done. Leave it out while nobody knows: the bar then only says that work is going on
  • $max (int|float): how much there is to do. A value beyond it counts as all of it, and one below 0 as nothing. While $max is 0 or less, or one of the two is no number that can be counted with (NAN, INF), nobody knows how far the task is, and the bar says that
  • $text (string|null): your own words beside the bar, in place of the percentage: "1,200 of 3,000 orders". '' leaves the place empty

success() ​

php
function success(string $text): void

A message that something worked. Line breaks are kept.

info() ​

php
function info(string $text): void

A message that tells the user something they should know. Line breaks are kept.

warning() ​

php
function warning(string $text): void

A message that something needs care. Software that reads the page out says it at once.

error() ​

php
function error(string $text): void

A message that something went wrong. Software that reads the page out says it at once. What is wrong with one input belongs to field_error().

Inputs ​

text() ​

php
function text(string $label, string $default = '', ?string $placeholder = null, ?string $help = null, ?string $key = null): string

A single line of text. Returns what the user typed, trimmed.

textarea() ​

php
function textarea(string $label, string $default = '', int $rows = 4, ?string $placeholder = null, ?string $help = null, ?string $key = null): string

Several lines of text.

number() ​

php
function number(
    string $label,
    int|float|null $default = null,
    int|float|null $min = null,
    int|float|null $max = null,
    int|float|null $step = null,
    ?string $help = null,
    ?string $key = null,
): int|float|null

A number, kept between $min and $max. Returns null while the field is empty. A whole number comes back as an int, anything else as a float. With a whole-number $step the result is always a whole number.

select() ​

php
function select(string $label, array $options, mixed $default = null, ?string $help = null, ?string $key = null, ?bool $byKey = null): mixed

A choice from a list. Returns one of the options, never anything else.

  • $options (array<array-key,mixed>): ['paid', 'shipped'] offers those values; [7 => 'Last 7 days', 30 => 'Last 30 days'] shows the texts and returns 7 or 30
  • $byKey (bool|null): PHP cannot tell [0 => 'No', 1 => 'Yes'] from the list ['No', 'Yes']. When the keys count up from 0 and are the values, say so with byKey: true

radio() ​

php
function radio(
    string $label,
    array $options,
    mixed $default = null,
    bool $horizontal = false,
    ?string $help = null,
    ?string $key = null,
    ?bool $byKey = null,
): mixed

A choice from a short list, with every option in view. Returns one of the options, never anything else: the first one until the user chooses another.

It takes the options the way select() does. With more than a handful of options, select() needs less room.

  • $options (array<array-key,mixed>): see select()
  • $horizontal (bool): the options stand side by side instead of one under the other
  • $byKey (bool|null): see select()

multiselect() ​

php
function multiselect(
    string $label,
    array $options,
    array $default = [],
    bool $horizontal = false,
    ?string $help = null,
    ?string $key = null,
    ?bool $byKey = null,
): array

Several choices from a list: a tick box for every option. Returns the ticked options as a list, in the order of the options. Nothing ticked is an empty list.

  • $options (array<array-key,mixed>): see select()
  • $default (array<array-key,mixed>): the options that are ticked until the user says otherwise
  • $horizontal (bool): the options stand side by side instead of one under the other
  • $byKey (bool|null): see select()

Returns list<mixed>

checkbox() ​

php
function checkbox(string $label, bool $default = false, ?string $help = null, ?string $key = null): bool

A tick box.

date_input() ​

php
function date_input(
    string $label,
    string|\DateTimeInterface|null $default = null,
    string|\DateTimeInterface|null $min = null,
    string|\DateTimeInterface|null $max = null,
    ?string $help = null,
    ?string $key = null,
): ?string

A date. Returns it as "YYYY-MM-DD", or null while the field is empty.

file_input() ​

php
function file_input(
    string $label,
    ?array $types = null,
    bool $multiple = false,
    ?int $maxSize = null,
    ?string $help = null,
    ?string $key = null,
): Upload|array|null

A field that takes a file from the user's computer.

It returns the file once it is there, on every run, until the user removes it or the tool forgets it:

php
$file = file_input('Orders', types: ['csv']);
if ($file && button('Import')) {
    import($file->path);
    $file->forget();
}

The file lies in a folder that only PHP reads, for a day at most. Nothing about it is trusted: its name is made safe, its content is whatever the user sent, and its ending says nothing about what is in it.

A field that is not drawn in a run gives its file up, as a text field loses its text. That includes a run that ends above the field with stop() or an early return.

  • $types (list<string>|null): the endings a file may have, such as ['csv', 'xlsx']. null takes every kind of file
  • $multiple (bool): take several files, up to 20 and never more than PHP takes in one request (max_file_uploads in php.ini). The function then returns a list
  • $maxSize (int|null): the largest file in bytes. PHP's own limits (upload_max_filesize and post_max_size in php.ini) count as well, and the smaller one wins

Returns ($multiple is true ? list<Upload> : Upload|null): the file, or null while there is none. With $multiple the files, in the order they arrived

field_error() ​

php
function field_error(string $field, string $message): void

Says what is wrong with what an input holds, right under that input. The input is marked, and software that reads the page out says so too.

php
$amount = number('Amount');
$email = text('Customer email');

if (button('Refund')) {
    if ($amount === null || $amount <= 0) {
        field_error('Amount', 'Enter an amount above 0.');
    }
    if (!str_contains($email, '@')) {
        field_error('Customer email', 'Enter an email address.');
    }
    if (valid()) {
        // do the work
    }
}

Call it below the input, in the same run: the input has to be on the page already. After a pressed button the first input that is wrong gets the keyboard focus, and an expander or a tab that hides it comes into sight.

Nothing is kept of a message. It is there in the run that says it: checked behind a button, it is gone with the next change on the page, and checked on every run, it stays until the input is right. It does not stop the script either: ask valid() before the work is done.

  • $field (string): the label of the input, exactly as it was written, or its key. Two inputs with the same label are told apart by their keys. A name that is the key of one input and the label of another means the one with that key
  • $message (string): what the user has to change. It is shown as text, and cut after 500 characters. One input shows up to ten messages

valid() ​

php
function valid(): bool

True as long as nothing was found wrong with an input in this run: no input that was drawn so far shows a note that says what is wrong with it.

Such a note comes from field_error(), or from file_input() when it turned a file down in this run: one that is too large, or of the wrong kind. That file did not arrive, and the user may believe that it is attached.

Data ​

table() ​

php
function table(
    iterable|\Closure $rows,
    bool $selectable = false,
    ?array $columns = null,
    ?string $key = null,
    string $rowKey = 'id',
    int $pageSize = 25,
    bool $search = false,
    ?string $empty = null,
    ?array $sortable = null,
    ?\Closure $count = null,
): array

A table of rows. Click a column header to sort. A long table is shown one page at a time.

Pass all rows: the table sorts all of them and cuts them into pages itself.

Or pass a function, for a table that is too long for that. The table asks it for one page at a time and hands it a TableQuery: the search, the order, a limit and an offset. The function reads those rows from the database and returns them, and the table never holds more than a page. Such a table sorts by the columns that $sortable names, searches when the function does, and its ticks count for the page on the screen.

  • $rows (iterable<mixed>|\Closure): arrays or objects, for example what a database query returned. Or a function that gets a TableQuery and returns the rows of one page
  • $selectable (bool): adds a tick box to every row. A tick stays when the page of the table changes, unless the rows come from a function
  • $columns (array<array-key,mixed>|null): ['id', 'total'] to choose columns, ['id' => 'Order'] to also rename them
  • $rowKey (string): the column that identifies a row. A row without it is known by what is in it: its tick is dropped when the row changes
  • $pageSize (int): how many rows one page shows, from 1 to 200
  • $search (bool): adds a search box. It filters the rows while the user types and reads the columns that are shown. A ticked row that it hides is not returned. With a function it only hands over what was typed: the function searches
  • $empty (string|null): what to say when there are no rows. By default "No rows." in the language of the page
  • $sortable (array<array-key,mixed>|null): with a function only: the columns whose headers sort, ['id', 'total']. ['customer' => 'c.name'] also says what the function gets for a column. The function only ever gets a value of this list, or null
  • $count (\Closure|null): with a function only: gets the search and returns how many rows there are. Without it the table shows no page count, only "Previous" and "Next"

Returns list<mixed>: the rows the user ticked on all pages of the list, exactly as they were passed in (always empty unless $selectable). With a function: the ticked rows of the page on the screen, as the function returned them

chart() ​

php
function chart(
    iterable $rows,
    string $x,
    string|array $y,
    string $type = 'bar',
    ?string $title = null,
    int $height = 240,
    bool $data = true,
): void

A bar or line chart of the rows.

  • $rows (iterable<mixed>)
  • $x (string): the column with the labels along the bottom
  • $y (string|array<array-key,mixed>): the column with the numbers; a list of columns draws several series, ['revenue' => 'Revenue (USD)'] also names them
  • $type (string): "bar" or "line"
  • $data (bool): also offer the numbers as a table under the chart

Actions ​

button() ​

php
function button(
    string $label,
    string $style = 'default',
    ?string $confirm = null,
    ?string $yes = null,
    ?string $no = null,
    ?string $key = null,
): bool

A button. Returns true only in the run that its click started, so "if (button('Save')) { ... }" does the work exactly once per click.

In a loop every button needs its own key, made from the row it belongs to: button('Refund', key: 'refund-' . $order['id']).

  • $style (string): "default", "primary" or "danger"
  • $confirm (string|null): a question to ask first. The button then returns true only after the user answered yes to exactly this text. Keep it the same from run to run: with the time of day in it, the answer would never fit the question
  • $yes (string|null): the text of the answer that goes ahead. By default "Yes" in the language of the page
  • $no (string|null): the text of the answer that does nothing. By default "Cancel" in the language of the page

download() ​

php
function download(string $label, iterable|string|\Closure $content, string $file, string $style = 'default', ?string $key = null): void

A button that hands the user a file.

php
download('Download CSV', $orders, 'orders.csv');

Rows become a CSV file, or JSON when the name ends in ".json". Text is sent as it is. A function is called only when the user asks for the file, so a slow query does not run on every page view:

php
download('Export all', fn () => $db->fetchAll('SELECT * FROM orders'), 'orders.csv');

The run ends where the file is made, as after stop(). A download is written to the log like a pressed button, with the name and the size of the file. When the log cannot be written (the callback throws or returns false), the file is not sent.

The file is made in memory. No rows give an empty file: to still write the names of the columns, pass csv($rows, columns: [...]).

  • $content (iterable<mixed>|string|\Closure): rows, text, or a function that returns one of the two. A generator can be read only once: when the page shows the same rows, pass an array or a function
  • $file (string): the name of the file, such as "orders.csv". It may contain what a user typed: it is made safe. Its ending should come from you, because the ending decides what a computer does with the file
  • $style (string): "default", "primary" or "danger"

csv() ​

php
function csv(iterable $rows, ?array $columns = null, string $separator = ',', bool $allowFormulas = false, bool $bom = true): string

Rows as CSV text, for download() when the defaults do not fit:

php
download('Export', fn () => csv($orders, separator: ';'), 'orders.csv');
  • $rows (iterable<mixed>)
  • $columns (array<array-key,mixed>|null): ['id', 'total'] to choose columns, ['id' => 'Order'] to also rename them. By default every column, under its own name. For a very long export name the columns: the rows are then written one by one and not kept
  • $separator (string): what stands between two cells: ",", ";", "|", ":" or a tab. Excel expects ";" where people write 1,5 for one and a half
  • $allowFormulas (bool): a spreadsheet runs a cell that starts with "=", "+", "-" or "@" as a formula. By default such a cell gets a "'" in front, and numbers are left alone. Pass true only when every cell comes from you
  • $bom (bool): start the file with the mark that tells Excel the text is UTF-8

Flow and layout ​

columns() ​

php
function columns(callable ...$columns): void

Puts things side by side. Each argument is a function that draws one column: fn () => ..., a method, or name(...). The name of a function in quotes is not run.

expander() ​

php
function expander(string $label, callable $content, bool $open = false, ?string $key = null): void

A part of the page under a line that opens and closes it. For what is not needed every time: advanced options, the details of a row, a long explanation.

The content always runs, and the inputs inside keep working and keep their values while the part is closed. Closed only means out of sight. It does not mean private: what is inside is in the page, for everybody who can open the tool.

stop() inside ends this part and not the page.

  • $content (callable():mixed): draws what is inside: fn () => ..., a method, or name(...). The name of a function in quotes is not run
  • $open (bool): how it starts. From then on it stays the way the user left it

tabs() ​

php
function tabs(array $tabs, ?string $key = null): void

Parts of the page behind headers, one of them in view at a time. For a page that holds more than one screen should show at once: the orders, the customers and the settings of a shop.

Every tab runs on every run, whichever is in view. The inputs behind the others keep working and keep their values, and changing the tab needs no run of the tool. Work that takes long belongs behind a button.

A tab that is not open is out of sight, not private: it is in the page, for everybody who can open the tool. stop() inside a tab ends that tab and not the page.

  • $tabs (array<array-key,callable():mixed>): the label of each tab and the function that draws it: ['Orders' => fn () => table($orders), 'Settings' => $settings]. The name of a function in quotes is not run

refresh() ​

php
function refresh(int $seconds, ?int $stopAfter = 3600): void

Lets the page run again by itself, so that a dashboard or the state of a queue stays up to date while somebody looks at it. Where it is called, a small line says when the page was made, with a button that pauses it.

Every refresh is a whole run of the script, so the rate should fit the work: the next run starts $seconds after the answer to the last one, never before. Call it near the top, and not inside expander() or tabs(): its line must be in sight. A page that ends before it reaches the call stops refreshing.

A refresh waits while the user is in the middle of something: typing, choosing from a list, answering the question of a button, or moving the mouse. It presses no button, writes nothing to the log and changes nothing that the tool remembers. Without JavaScript nothing refreshes.

It is a whole run all the same: what the script does on every run, it now does every few seconds with nobody at the page. Work that changes something belongs behind a button. And the login check runs for it like for any request: one that counts the time without a request should leave out those with the header "X-Script-Ui: refresh".

  • $seconds (int): the wait between an answer and the next run: 2 or more
  • $stopAfter (int|null): the page stops by itself when nobody touched it for this many seconds, and says so. An hour by default: a page that keeps asking keeps its session alive. It has to be longer than $seconds. null: never, for a screen on a wall

stop() ​

php
function stop(): never

Ends the run here. Everything drawn so far is shown.

Inside expander() and tabs() it ends that part only, and the rest of the page still runs. So it is no permission check there. Decide who may see or do something before the part is drawn, or right where the work is done.

rerun() ​

php
function rerun(): never

Ends the run and loads the page again from the top. Call it after a button did its work, so that tables above the button show the new data. Messages written with success(), info(), warning() or error() after the click are kept.

Hosting ​

user() ​

php
function user(): ?string

Who is using the tool: what the login check returned. Null when there is no login check.

configure() ​

php
function configure(
    ?callable $auth = null,
    ?callable $log = null,
    ?bool $debug = null,
    ?string $name = null,
    ?string $language = null,
    ?array $texts = null,
    ?string $uploads = null,
    ?callable $allow = null,
): void

Settings for tools that are opened directly as scripts. Call it before anything is drawn, typically in a file that every tool includes.

  • $auth (callable|null): the login check: receives the request, returns the user's name, or null to refuse
  • $log (callable|null): called with an array for every button a user presses and every file a user downloads. It should throw or return false when the entry could not be written: a download is then not sent
  • $debug (bool|null): show error details in the page. By default they are shown only without a login check, where nobody but this computer gets in. With a login check, pass true where you develop
  • $name (string|null): the name of the tool collection
  • $language (string|null): the language of the built-in texts ("Yes", "Reset", "No rows.") on every page: "en", "ar" or "de", or a language you pass the texts for. By default each page follows the language its title is written in
  • $texts (array<array-key,mixed>|null): your own built-in texts, per language: ['de' => ['page.reset' => 'Leeren']]. All texts and their ids are in resources/texts/en.php
  • $uploads (string|null): the folder that keeps uploaded files until a tool is done with them. It must not be a folder the web server serves. By default a folder of its own inside PHP's temp folder
  • $allow (callable|null): who may open which script: receives what the login check returned, and the id of the script (its file name without ".php"), and returns true or false. See serve()

clean_uploads() ​

php
function clean_uploads(?string $folder = null): int

Deletes the uploaded files that are older than a day. The library does this itself while files arrive. Call it from a scheduled job when the files of users who left must not wait for the next upload to be cleaned away.

The job has to run as the system user that runs PHP for the web server. As another user it finds another folder, and nothing in it.

  • $folder (string|null): the folder you passed as uploads:. null: the folder of this system user inside PHP's temp folder

Returns int: how many files were deleted

serve() ​

php
function serve(
    string $directory,
    ?callable $auth = null,
    ?callable $log = null,
    ?string $name = null,
    ?bool $debug = null,
    ?string $base = null,
    ?string $language = null,
    ?array $texts = null,
    ?string $uploads = null,
    ?callable $allow = null,
    ?array $variables = null,
): void

Serves every PHP file in a folder as a tool, with a page that lists them.

Without $auth the tools only answer to a browser on the computer they run on. That check cannot see through every proxy or tunnel: anything that can be reached from outside needs $auth.

  • $auth (callable|null): the login check: receives the request, returns the user's name, or null to refuse
  • $log (callable|null): called with an array for every button a user presses and every file a user downloads. It should throw or return false when the entry could not be written: a download is then not sent
  • $debug (bool|null): show error details in the page. By default only without $auth; with it, pass true where you develop
  • $base (string|null): null: one address, tools are chosen with "?_tool=id". A path such as "/admin/tools": tools get the addresses "/admin/tools/{id}" (the web server must send those addresses to the script that calls serve()).
  • $language (string|null): the language of the built-in texts ("Yes", "Reset", "No rows.") on every page: "en", "ar" or "de", or a language you pass the texts for. By default each page follows the language its title is written in
  • $texts (array<array-key,mixed>|null): your own built-in texts, per language: ['de' => ['page.reset' => 'Leeren']]. All texts and their ids are in resources/texts/en.php
  • $uploads (string|null): the folder that keeps uploaded files until a tool is done with them. It must not be a folder the web server serves. By default a folder of its own inside PHP's temp folder
  • $allow (callable|null): who may open which tool: receives what the login check returned (a name, a number or your user object; null when it only said true, or when there is none), and the id of a tool (its file name without ".php"), and returns true or false. A tool that is not allowed is left out of the list, and answers "Not allowed" before anything of it runs. Without it everybody who gets past the login check may open every tool
  • $variables (array<array-key,mixed>|null): variables for every tool of the folder, by name: ['orders' => $orders] makes $orders in each tool. A tool is a script of its own and sees no variable of yours otherwise

respond() ​

php
function respond(
    string $directory,
    ?callable $auth = null,
    ?callable $log = null,
    ?string $name = null,
    ?bool $debug = null,
    ?string $base = null,
    ?string $language = null,
    ?array $texts = null,
    ?string $uploads = null,
    ?callable $allow = null,
    ?array $variables = null,
    ?object $session = null,
): Http\Response

serve() for an application that sends its pages itself, as one built on Symfony or Laravel does. It works out the same page, and hands it back instead of sending it: the status, the headers and the body. A controller makes the response of its framework from them:

php
$page = respond(__DIR__ . '/../../tools', base: '/admin/tools', session: $request->getSession());

return new Response($page->body, $page->status, $page->headers);

The headers belong to the answer, and so does the status. Pass all of them on: they say where a pressed button leads on to, what a file is called and of which kind it is, that the page is not to be kept, and which script the page may run.

The request is the one PHP itself is working on ($_SERVER, $_GET, $_POST and $_FILES). The test client of a framework does not fill those in, so a tool cannot be tried with it.

Every setting is the one of serve(), and there is one more:

  • $auth (callable|null): see serve()
  • $log (callable|null): see serve()
  • $name (string|null): see serve()
  • $debug (bool|null): see serve()
  • $base (string|null): see serve(). In an application it is the path of the route that leads to the controller, as the browser sees it
  • $language (string|null): see serve()
  • $texts (array<array-key,mixed>|null): see serve()
  • $uploads (string|null): see serve()
  • $allow (callable|null): see serve()
  • $variables (array<array-key,mixed>|null): see serve()
  • $session (object|null): the session of your application: the tools keep what they have to keep in it, under one key, and a logout of your application ends that too. An object with get() and set(), as in Symfony, or with get() and put(), as in Laravel. null: PHP's own session

Returns Http\Response: the page: ->status, ->headers and ->body

Objects a tool gets to hold ​

Upload ​

What file_input() returns.

A file that a user uploaded with file_input().

The file lies in a folder of the server that only PHP reads. It stays until the user removes it, the tool forgets it or a day has passed. Copy it with saveTo() when it has to stay for longer.

  • $name (string): what the file was called on the user's computer, made safe: it never names a folder. Its ending decides what a computer does with the file, so do not trust it
  • $size (int): in bytes
  • $path (string): where the file lies now. It is not the name the user gave it

contents()

php
public function contents(): string

Everything that is in the file, as one text. For a large file read from path with fopen() or SplFileObject instead.

Throws

  • \RuntimeException when the file is no longer there

rows()

php
public function rows(?string $separator = null, ?string $encoding = null): array

The rows of a CSV file: the first line names the columns, and every other line becomes one row, name => text.

php
foreach ($file->rows() as $row) {
    $orders->add($row['email'], (float) $row['total']);
}

It reads what spreadsheets write: cells apart by ",", ";" or a tab, with or without the mark for UTF-8, in UTF-8, in UTF-16 or in the Western Windows encoding of older versions of Excel. Empty lines are left out, and a line that ends early gets empty cells. Every cell is text and stays as it is in the file: "007" is not 7, and "1,50" is not a number yet.

A file that is not text has no rows. The file comes from a user, so look whether the columns you need are there before you use them.

The whole file is read into memory. Read a very large file from path yourself, line by line.

  • $separator (string|null): what stands between two cells: ",", ";", "|", ":" or a tab. null: found out from the first lines
  • $encoding (string|null): for a file in another encoding, such as "Windows-1256" for Arabic from an older Excel. null: found out as far as that goes

Returns list<array<array-key,string>>

Throws

  • \RuntimeException when the file is no longer there
  • \InvalidArgumentException for a separator or an encoding that cannot be used

saveTo()

php
public function saveTo(string $path, bool $overwrite = false): void

Copies the file to a place where it stays.

The name of the new file is yours to choose. When you build it from the name the user gave, remember that a ".php" in a folder the web server serves is a program.

The copy is for the PHP user only, as the upload was. Call chmod() on it when somebody else has to read it, such as a web server that runs as another user.

  • $overwrite (bool): replace a file that is already there. Without it that is an error

Throws

  • \RuntimeException when the copy could not be made

forget()

php
public function forget(): void

Deletes the file now and empties its field. Call it when the tool is done with the file, after an import for example: the file would otherwise wait in its field, ready to be imported a second time.

The file is gone at once and stays gone, also when the run fails further down. Whatever was done with it has happened by then.

TableQuery ​

What a function gets that you pass to table() in place of the rows.

What a table asks for when it gets a function in place of its rows: one page of the rows, searched and sorted the way the user has set the table.

Nothing in it is taken from the browser as it came. The search is one line of text, cut and tidied: put it into a query as a parameter, like any text a user typed. The sort is a value from the sortable: list of the table, or null. The limit and the offset are numbers that the table worked out.

Two things are left to the query. To LIKE, % and _ in the search stand for any text, until the query escapes them. And an order by a column that several rows share has to end with one that no two rows share, or such rows change places between two pages.

  • $search (string): what the search box holds. '' while it is empty, and when the table has none
  • $sort (string|null): what sortable: says for the column the user sorted by. null while no column is chosen
  • $descending (bool): true when that column is sorted from high to low
  • $limit (int): how many rows to return at most
  • $offset (int): how many rows of the list come before them

Response ​

What respond() returns.

What goes back to the browser.

  • $status (int): the HTTP status
  • $body (string): the page, or the file of a download
  • $headers (array<string,string>): the headers that belong to the answer, by name
  • $alreadySent (bool): the script answered on its own; there is nothing left to send

header()

php
public function header(string $name): ?string

One header by its name, in whatever case it is written. null when the answer has none of that name.

send()

php
public function send(): void

Sends the status, the headers and the body. It does nothing when the script answered on its own.

Released under the MIT License.