App
The application core.
Properties (12)
| $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 | |
| $app->kept | Kept | 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 at `data/cache/app.{name}.db`, kept apart from the pages cache (see Page::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 the field's definition, null 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's child: when $uri is not a stored page, its direct parent is asked through child() if it is a PageSource.
- users Users matching a query, by username unless it sorts otherwise: `$app->users('role=admin,sort=-created')`.
- 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 12
- 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.
- origin The site origin with no trailing slash: config `url` when set, else the request's scheme and host.
- 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.
- cacheDisabled Whether `"cache": false` in config turns every cache off: the stores, the page cache and the headers that let a browser keep a response.
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
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:171
Services
$app->history(): History
The git history of `pages/`: commits, revisions and sync.
Returns History
phlat/src/App.php:196
$app->cache(string $name = 'app'): Cache
A named key-value cache at `data/cache/app.{name}.db`, kept apart from the pages cache (see Page::cache()).
Parameters (1)
| $name | string = 'app' |
Returns Cache
phlat/src/App.php:202
$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:211
Addons
$app->addons(): array
Enabled addons as alias => root path, in config-declaration order.
Returns array
phlat/src/App.php:224
$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`.
Parameters (1)
| $alias | string |
Returns ?string
phlat/src/App.php:230
$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:236
$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:242
$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:250
$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:258
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`.
Returns array
phlat/src/App.php:279
$app->roleNames(): array
All user role names available - site roles/ merged with phlat's built-ins (admin, guest).
Returns array
phlat/src/App.php:288
$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.
Parameters (1)
| $ref | string |
Returns PageView
phlat/src/App.php:298
$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:316
$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:335
$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:344
$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:357
$app->resolveField(string $key, mixed $value, ?Field $def, array $context): FieldValue
$def is the field's definition, null 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 | ?Field | |
| $context | array |
Returns FieldValue
phlat/src/App.php:402
$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:414
$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:420
$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:435
$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:456
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:501
$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:507
$app->page(?string $uri = null, array $index = []): Page
The page at $uri, or the current request's page when $uri is null.
Parameters (2)
| $uri | ?string = null | |
| $index | array = [] |
Returns Page
phlat/src/App.php:526
$app->resolve(string $uri): ?Page
A page() that also finds a source's child: when $uri is not a stored page, its direct parent is asked through child() if it is a PageSource.
Parameters (1)
| $uri | string |
Returns ?Page
phlat/src/App.php:556
$app->users(string $query = ''): UserCollection
Users matching a query, by username unless it sorts otherwise: `$app->users('role=admin,sort=-created')`.
Parameters (1)
| $query | string = '' |
Returns UserCollection
phlat/src/App.php:662
$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:669
$app->collections(): array
Every collection that exists, by field name: a database in data/collections.
Returns array
phlat/src/App.php:675
$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.
Returns array
phlat/src/App.php:689
Responses
$app->latte(): Engine
The Latte engine, with PhlatPage's tags, filters and template loader.
Returns Engine
phlat/src/App.php:725
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:731
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:746
send
exits$app->send(?Page $page = null, ?string $block = null, array $data = []): never
Render the current (or given) page and send the response.
Parameters (3)
| $page | ?Page = null | |
| $block | ?string = null | |
| $data | array = [] |
Returns never
phlat/src/App.php:756
$app->origin(): string
The site origin with no trailing slash: config `url` when set, else the request's scheme and host.
Returns string
phlat/src/App.php:763
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:772
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:781
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:790
$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:799
$app->execute(): void
Handles the current request: resolves the page, runs its router and sends the response.
phlat/src/App.php:805
$app->isCacheable(): bool
A GET/HEAD.
Returns bool
phlat/src/App.php:956
$app->cacheDisabled(): bool
Whether `"cache": false` in config turns every cache off: the stores, the page cache and the headers that let a browser keep a response.
Returns bool
phlat/src/App.php:962
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:1016
$app->make(string $name): mixed
The service bound under $name, or null.
Parameters (1)
| $name | string |
Returns mixed
phlat/src/App.php:1028
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:1041
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:1100
$app->onEmit(callable $listener): void
Registers an observer notified after every hook listener runs, with (event, source, duration in ms).
Parameters (1)
| $listener | callable |
phlat/src/App.php:1106
$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:1112