App
The application core.
Boots the site, dispatches the request, and hands out every service: pages, registry, files, session, views and config.
Properties (11)
| $app->dependencies | array | ||
| $app->system | string | readonly | |
| $app->root | string | readonly | |
| $app->path | string | readonly | |
| $app->public | string | readonly | |
| $app->pages | string | readonly | |
| $app->data | string | readonly | |
| $app->config | Config | readonly | |
| $app->request | Request | readonly | |
| $app->session | SessionRoot | readonly | |
| $app->options | Options | readonly |
Services 5
- registry The page index behind find(), opened on first use.
- pageFiles The file manager: uploads, metadata, public mirrors and image variants.
- history The git history of `pages/`: commits, revisions and sync.
- cache A named key-value cache in `data/cache/`.
- email A Mailer for the named transport in config `mail`.
Addons 6
- addons Enabled addons as alias => root path, in config-declaration order.
- mountOf The slug of the site page that mounts an addon: the first page, by path, whose view is exactly `@alias`.
- isAutomount Whether an addon is served at /@alias from its own pages/ instead of being mounted on a site page.
- addonConfig An addon's own setting, namespaced under its `addons.{id}` config entry - the only place addon settings live.
- addon An enabled addon's handle, to emit its own `@alias/event`s from code that has no page.
- aliasRoot The root an `@alias` names - `phlat` the core, any other an enabled addon - or null.
Views and fields 13
- viewNames All view refs a page can take - the site's own views, then the core's as `@phlat/name`.
- roleNames All user role names available - site roles/ merged with phlat's built-ins (admin, guest).
- pageView The view a ref names; every page of a view shares one, so a long list doesn't read the same _index.json once per page.
- locate The folder a ref names under {kind}/: a bare `name` only in $root (the root that owns the file the ref was written in), an `@alias/name` in that alias's root - either one taking the site's override at site/{kind}/@alias/name first. '' when there is none.
- qualify $ref as the site names it: a bare name written in an addon's or the core's file becomes `@alias/name`; a site name or an `@` ref stays as it is.
- owner The root that owns $path, against which a bare ref written in it resolves: a site override (site/{kind}/@alias/...) stands in for that alias's own file, so it is owned by that alias's root.
- field The global field definition $ref names, as seen from $root (see locate()), with its `extends` chain applied and every sub-field it declares resolved inline.
- resolveField $def is a fieldDefs() tuple (type, label, options, render), empty for a key no template declares, whose value is wrapped by its shape alone; $context is where the field lives (path, uuid, page, view, url).
- fieldtypeTemplate Path of a fieldtype's edit or preview template, or null; a missing preview falls back to FieldType::preview().
- fieldtypeMeta A fieldtype's own optional _index.json (its `search` defaults). $type is named as the site names it, like every type a FieldValue carries.
- fileFields A file's declared metadata fields: files/_index.json merged with files/{type}/_index.json, whether or not any page field references them.
- fieldtype The shared FieldType a site-named type ref names; an empty $type is inferred from the shape of $value, so undeclared data is still safely wrapped.
- loadType The class governing the {base}/ folder a site-named ref locates (see locate()): requires {name}.php if present and returns its bound subclass, else $baseClass.
Pages and users 10
- find Pages across the whole site matching a query: `$app->find('view=article,sort=-created,limit=4')`.
- isEditor Signed in with `admin.access`, or the CLI: sees unpublished and gated pages and autosaves. isLoggedIn() first so an anonymous visitor never starts a session.
- userRoot The folder that holds every user, as a record.
- page The page at $uri, or the current request's page when $uri is null.
- resolve A page() that also finds a source page's virtual child: when $uri is not a stored page, its direct parent is asked through child() if that page's view says `"children": {"source": true}`.
- users Returns all users sorted by username, through the registry like every other enumeration.
- collection The collection stored under a field name, shared for the request.
- collections Every collection that exists, by field name: a database in data/collections.
- databases Every SQLite database the site keeps, as [name => path]: those under data/storage by their path there, and each collection's as collections/{field}.db.
- user The user with this username, or null.
Responses 10
- latte The Latte engine, with PhlatPage's tags, filters and template loader.
- render Render a template (or just one of its named {block}s) and send the response.
- renderFragment Renders a template wrapped in fragment.latte : full shell on direct navigation, bare partial on an HTMX request.
- send Render the current (or given) page and send the response.
- redirect HTMX requests get HX-Redirect: a plain Location would be followed by the XHR and swapped into the boosted target.
- location HX-Location for HTMX requests (no full reload); a direct request gets a real redirect.
- refresh HX-Refresh for HTMX requests; a direct request redirects to its own URL for a fresh load.
- trigger Sets HX-Trigger on the response the route sends next; does not exit.
- execute Handles the current request: resolves the page, runs its router and sends the response.
- isCacheable A GET/HEAD from an anonymous visitor with no option cookie, outside debug: a logged-in response can carry drafts and flash messages, and a cached debug page replays a stale X-Clockwork-Id.
Events 4
- on Listens for an event: `$app->on('page.save:after', fn(Page $page) => ...)`.
- onEmit Registers an observer notified after every hook listener runs, with (event, source, duration in ms).
- emit Core's emit: site code and addons use `$page->emit()` or `$app->addon()->emit()`, so they can't spell a core or another addon's event.
- shutdown Emit app.shutdown exactly once per request.
Boot
instance
staticApp::instance(string $path, string $system): self
The one App for this request, built and booted on the first call.
Parameters (2)
| $path | string | |
| $system | string |
Returns self
phlat/src/App.php:58
Paths
$app->uri(string $path): string
Converts an absolute filesystem path to an app-relative URI.
Parameters (1)
| $path | string |
Returns string
phlat/src/App.php:173
Services
$app->history(): History
The git history of `pages/`: commits, revisions and sync.
Returns History
phlat/src/App.php:198
$app->cache(string $name = 'app'): Cache
A named key-value cache in `data/cache/`.
Parameters (1)
| $name | string = 'app' |
Returns Cache
phlat/src/App.php:204
$app->email(string $transport = 'default'): Mailer
A Mailer for the named transport in config `mail`.
Parameters (1)
| $transport | string = 'default' |
Returns Mailer
phlat/src/App.php:210
Addons
$app->addons(): array
Enabled addons as alias => root path, in config-declaration order.
Returns array
phlat/src/App.php:223
$app->mountOf(string $alias): ?string
The slug of the site page that mounts an addon: the first page, by path, whose view is exactly `@alias`.
A dev mounts an addon by creating that page. Null when there is none.
Parameters (1)
| $alias | string |
Returns ?string
phlat/src/App.php:229
$app->isAutomount(string $alias): bool
Whether an addon is served at /@alias from its own pages/ instead of being mounted on a site page.
Parameters (1)
| $alias | string |
Returns bool
phlat/src/App.php:235
$app->addonConfig(string $id, string $key, mixed $default = null): mixed
An addon's own setting, namespaced under its `addons.{id}` config entry - the only place addon settings live.
Parameters (3)
| $id | string | |
| $key | string | |
| $default | mixed = null |
Returns mixed
phlat/src/App.php:241
$app->addon(string $alias): Addon
An enabled addon's handle, to emit its own `@alias/event`s from code that has no page.
Parameters (1)
| $alias | string |
Returns Addon
phlat/src/App.php:247
$app->aliasRoot(string $alias): ?string
The root an `@alias` names - `phlat` the core, any other an enabled addon - or null.
Parameters (1)
| $alias | string |
Returns ?string
phlat/src/App.php:255
Views and fields
$app->viewNames(): array
All view refs a page can take - the site's own views, then the core's as `@phlat/name`.
An _index.json marks a real view, as opposed to a folder of template partials (views/fields, views/ui).
Returns array
phlat/src/App.php:276
$app->roleNames(): array
All user role names available - site roles/ merged with phlat's built-ins (admin, guest).
Returns array
phlat/src/App.php:285
$app->pageView(string $ref): PageView
The view a ref names; every page of a view shares one, so a long list doesn't read the same _index.json once per page.
A bare name is the site's own (site/views/), @alias/name the alias's (site/views/@alias/ first, the override,
then the alias's views/); a bare @alias is its home view.
Parameters (1)
| $ref | string |
Returns PageView
phlat/src/App.php:295
$app->locate(string $kind, string $ref, string $root, bool $override = true): string
The folder a ref names under {kind}/: a bare `name` only in $root (the root that owns the file the ref was written in), an `@alias/name` in that alias's root - either one taking the site's override at site/{kind}/@alias/name first. '' when there is none.
Parameters (4)
| $kind | string | |
| $ref | string | |
| $root | string | |
| $override | bool = true |
Returns string
phlat/src/App.php:313
$app->qualify(string $ref, string $root): string
$ref as the site names it: a bare name written in an addon's or the core's file becomes `@alias/name`; a site name or an `@` ref stays as it is.
Parameters (2)
| $ref | string | |
| $root | string |
Returns string
phlat/src/App.php:332
$app->owner(string $path): string
The root that owns $path, against which a bare ref written in it resolves: a site override (site/{kind}/@alias/...) stands in for that alias's own file, so it is owned by that alias's root.
Parameters (1)
| $path | string |
Returns string
phlat/src/App.php:341
$app->field(string $ref, string $root, bool $override = true): ?Field
The global field definition $ref names, as seen from $root (see locate()), with its `extends` chain applied and every sub-field it declares resolved inline.
Parameters (3)
| $ref | string | |
| $root | string | |
| $override | bool = true |
Returns ?Field
phlat/src/App.php:354
$app->resolveField(string $key, mixed $value, array $def, array $context): FieldValue
$def is a fieldDefs() tuple (type, label, options, render), empty for a key no template declares, whose value is wrapped by its shape alone; $context is where the field lives (path, uuid, page, view, url).
Parameters (4)
| $key | string | |
| $value | mixed | |
| $def | array | |
| $context | array |
Returns FieldValue
phlat/src/App.php:394
$app->fieldtypeTemplate(string $type, string $name): ?string
Path of a fieldtype's edit or preview template, or null; a missing preview falls back to FieldType::preview().
Parameters (2)
| $type | string | |
| $name | string |
Returns ?string
phlat/src/App.php:409
$app->fieldtypeMeta(string $type): array
A fieldtype's own optional _index.json (its `search` defaults). $type is named as the site names it, like every type a FieldValue carries.
Parameters (1)
| $type | string |
Returns array
phlat/src/App.php:415
$app->fileFields(string $type): array
A file's declared metadata fields: files/_index.json merged with files/{type}/_index.json, whether or not any page field references them.
Parameters (1)
| $type | string |
Returns array
phlat/src/App.php:430
$app->loadType(string $base, string $name, string $baseClass): string
The class governing the {base}/ folder a site-named ref locates (see locate()): requires {name}.php if present and returns its bound subclass, else $baseClass.
Parameters (3)
| $base | string | |
| $name | string | |
| $baseClass | string |
Returns string
phlat/src/App.php:451
Pages and users
$app->find(string $query = ''): RecordCollection
Pages across the whole site matching a query: `$app->find('view=article,sort=-created,limit=4')`.
Parameters (1)
| $query | string = '' |
Returns RecordCollection
phlat/src/App.php:496
$app->isEditor(): bool
Signed in with `admin.access`, or the CLI: sees unpublished and gated pages and autosaves. isLoggedIn() first so an anonymous visitor never starts a session.
Returns bool
phlat/src/App.php:502
$app->resolve(string $uri): ?Page
A page() that also finds a source page's virtual child: when $uri is not a stored page, its direct parent is asked through child() if that page's view says `"children": {"source": true}`.
Null when nothing answers. page() never asks a source, so routing and 404s cost no API call.
Parameters (1)
| $uri | string |
Returns ?Page
phlat/src/App.php:548
$app->users(): UserCollection
Returns all users sorted by username, through the registry like every other enumeration.
Returns UserCollection
phlat/src/App.php:654
$app->collection(string $field): Collection
The collection stored under a field name, shared for the request.
Parameters (1)
| $field | string |
Returns Collection
phlat/src/App.php:661
$app->collections(): array
Every collection that exists, by field name: a database in data/collections.
Returns array
phlat/src/App.php:667
$app->databases(): array
Every SQLite database the site keeps, as [name => path]: those under data/storage by their path there, and each collection's as collections/{field}.db.
The cache's are left out - they are made again.
Returns array
phlat/src/App.php:681
Responses
$app->latte(): Engine
The Latte engine, with PhlatPage's tags, filters and template loader.
Returns Engine
phlat/src/App.php:720
render
exits$app->render(string $uri, array $data = [], ?string $block = null): never
Render a template (or just one of its named {block}s) and send the response.
Parameters (3)
| $uri | string | |
| $data | array = [] | |
| $block | ?string = null |
Returns never
phlat/src/App.php:726
renderFragment
exits$app->renderFragment(string $uri, array $data = []): never
Renders a template wrapped in fragment.latte : full shell on direct navigation, bare partial on an HTMX request.
Parameters (2)
| $uri | string | |
| $data | array = [] |
Returns never
phlat/src/App.php:741
send
exits$app->send(?Page $page = null, ?string $block = null, array $data = []): never
Render the current (or given) page and send the response.
Honors a :block URL suffix, same as a normal GET. $data is merged over the controllers', e.g. a form's fields as posted.
Parameters (3)
| $page | ?Page = null | |
| $block | ?string = null | |
| $data | array = [] |
Returns never
phlat/src/App.php:751
redirect
exits$app->redirect(string $url, int $code = 302): never
HTMX requests get HX-Redirect: a plain Location would be followed by the XHR and swapped into the boosted target.
Parameters (2)
| $url | string | |
| $code | int = 302 |
Returns never
phlat/src/App.php:758
location
exits$app->location(string $url): never
HX-Location for HTMX requests (no full reload); a direct request gets a real redirect.
Parameters (1)
| $url | string |
Returns never
phlat/src/App.php:767
refresh
exits$app->refresh(): never
HX-Refresh for HTMX requests; a direct request redirects to its own URL for a fresh load.
Returns never
phlat/src/App.php:776
$app->trigger(string ...$events): void
Sets HX-Trigger on the response the route sends next; does not exit.
Parameters (1)
| ...$events | string |
phlat/src/App.php:785
$app->execute(): void
Handles the current request: resolves the page, runs its router and sends the response.
phlat/src/App.php:791
$app->isCacheable(): bool
A GET/HEAD from an anonymous visitor with no option cookie, outside debug: a logged-in response can carry drafts and flash messages, and a cached debug page replays a stale X-Clockwork-Id.
Returns bool
phlat/src/App.php:912
Container
$app->bind(string $name, mixed $service): void
Registers a shared service under $name; a second bind of the same name throws.
Parameters (2)
| $name | string | |
| $service | mixed |
phlat/src/App.php:978
$app->make(string $name): mixed
The service bound under $name, or null.
Parameters (1)
| $name | string |
Returns mixed
phlat/src/App.php:990
Locks
$app->lock(string $key, callable $fn, float $timeout = 10): mixed
Runs $fn under the named lock (re-entrant, single host); a wait past $timeout seconds throws a 503.
Parameters (3)
| $key | string | |
| $fn | callable | |
| $timeout | float = 10 |
Returns mixed
phlat/src/App.php:1003
Events
$app->on(string $event, callable $listener): void
Listens for an event: `$app->on('page.save:after', fn(Page $page) => ...)`.
Parameters (2)
| $event | string | |
| $listener | callable |
phlat/src/App.php:1062
$app->onEmit(callable $listener): void
Registers an observer notified after every hook listener runs, with (event, source, duration in ms).
Observational only - never for control flow.
Parameters (1)
| $listener | callable |
phlat/src/App.php:1068
$app->emit(string $event, mixed ...$args): void
Core's emit: site code and addons use `$page->emit()` or `$app->addon()->emit()`, so they can't spell a core or another addon's event.
Parameters (2)
| $event | string | |
| ...$args | mixed |
phlat/src/App.php:1074