CLI
Create users, scaffold views and pages, run maintenance, and write your own commands from the terminal.
Running commands
The CLI is at phlat/addons/cli/. Run it from anywhere in the project, inside the app container under Docker Compose:
php phlat/addons/cli/phlat <command> [args] [--flags]
docker compose exec app php phlat/addons/cli/phlat help
composer exec phlat -- <command> also works. The examples below write the command as phlat.
phlat help # every command, grouped by namespace
phlat help make # one namespace
phlat make:page --help # one command
Commands run without addons loaded. They read and write data/ directly, and data/env.cli.json is merged over data/env.json.
Accounts
phlat user:create adam --role=admin
phlat user:list
phlat user:password adam
phlat user:role adam editor
phlat user:delete adam
The password is prompted for, hidden, unless you pass --password=.
Scaffolding
phlat make:view article
phlat make:field summary --type=text --label=Summary
phlat make:page blog/first-post --view=article --title="First post"
make:view creates site/views/article/. make:field writes a field definition to site/fields/. To assign a field to a view, list it under fields in the view's index.json.make:page creates the page folder under data/pages/ with a minted uuid.
Pages
phlat page:list 'view=article,published=1,sort=-updated'
phlat page:field blog/first-post title # read a field
phlat page:field blog/first-post title "New title" # set it
phlat page:publish blog/first-post --off
phlat page:access members --to=login
phlat page:move blog/first-post news/first-post
phlat page:delete blog/first-post
page:list takes the same query DSL as $app->find(). page:access takes public, login, or role names joined by |. Moves and deletes keep the registry in sync.
Maintenance
| Command | Does |
|---|---|
backup:create / backup:restore |
Back up or restore pages (collections included), users, git/ and the env files |
registry:check / registry:rebuild |
Report invalid or duplicate UUIDs, or re-scan data/pages into the registry |
files:rebuild |
Sweep stale variants out of site/public/ |
cache:clear |
Clear one named cache, or empty data/cache |
data:migrate |
Move data/ from the old layout: the deploy key to git/, the old cache folders out of storage/. A dry run until --apply |
db:backup / db:vacuum |
Snapshot every collection's database, or compact every SQLite database |
health:check |
Diagnose the page tree, file caches, env.json and permissions. Exits 1 on any issue, so it works as a deploy gate |
health:disk |
Disk usage of each folder in data/ |
uuid:generate / uuid:regenerate |
Mint a uuid, or reassign every page and user uuid |
clockwork:clear / clockwork:prune / clockwork:status |
Manage the profiler database |
addons:install / addons:update / addons:uninstall / addons:reset |
Manage addons installed as pinned git submodules under addons/ |
Writing a command
A command is a PHP file with $app and $args in scope. Its path is its name: commands/make/page.php is make:page. Site commands go in site/commands/; reusing a built-in name is a hard error. An addon's commands/ folder is prefixed with the addon alias, so phlat/addons/git/commands/log.php runs as @git:log.
Lead with a docblock. Its first line is the summary in phlat help, and the rest is the --help text:
<?php
declare(strict_types=1);
/** @var \Phlat\App $app */
/** @var array $args */
/**
* Print the number of pages.
*
* Usage: phlat page:count [query]
*
* query Registry query, e.g. view=article
*/
use Phlat\Toolkit\Cli;
if (Cli::wantsHelp($args)) {
Cli::usage(__FILE__);
}
Cli::out((string) $app->find($args[0] ?? '')->count());
Use Cli for all output: out, info, success, warning, error, table, progress, input and confirm.