PageFiles
Manages every file owned by a page/item/user - identified by owner UUID + filename - including its index, public mirror, and image variants.
Properties (2)
| $pageFiles->cachePath | string | readonly | Where the admin's thumbnails are kept - disposable, in data/cache, made again on the next request. |
| $pageFiles->image | Image | readonly | Turns option strings into options and renders image variants; PageFiles records and serves what it makes. |
Variants 3
- setVariant Records a URL a template has asked for, keyed by its public request path: a lazily-rendered image variant, or - with empty $options - the file itself.
- getVariant Returns ['original' => string, 'options' => array, 'pageUuid' => string] for a variant's public request path, or null.
- allVariants Returns every recorded image variant, keyed by public request path - used by PageFiles::rebuild() to validate the public mirror against live source files instead of trusting whatever's on disk.
Paths 6
- actualPath Absolute path to the original file in its page directory, or null if the page is unresolvable.
- own Makes a virtual page the owner of its files for the rest of this request, so a file can be stored, listed and served by its uuid like any page's.
- variantDir Returns the thumbnail cache directory for a page UUID.
- publicPath Returns the public-mirror path for a file, or null if the owner is unresolvable.
- ownerUrl The URL folder (trimmed, '' for the root page) an owner's public files nest under, or null if the owner is unresolvable.
- usersPageUrl Resolves the admin users page's current URL (trimmed), or null if the admin addon isn't mounted - the fixed "parent" every user-owned file nests under.
Files 12
- get Returns the PageFile/PageImage for a page UUID + filename, or null if its metadata does not exist
- metaPath A file's metadata sits beside it as `_{name}.json`; a leading `_` is never a name an author can give, so it can't be a file.
- meta A file's metadata from its `_{filename}.json`, with `created` filled in from the file when missing.
- build Builds the PageFile, PageImage or PageSvg the file's mime calls for.
- buildImage Builds a PageImage, rejecting anything that isn't a resizable image.
- store Stores a file on disk in its page directory and writes metadata.
- upload Stores file upload in page directory and writes metadata.
- update Merges $changes into a file's metadata and returns the file.
- delete Deletes the file, its metadata, and any cached variants.
- isPublic True when a template has exposed the file, or any variant of it.
- makePrivate Withdraws a file: forgets every URL it was exposed at and wipes its mirrored and cached variants.
- forPage Returns all PageFiles for a page by scanning its page directory for files with a `_{name}.json` beside them.
Serving 5
- variant Generates a registry-recorded image variant and serves it.
- serveRequest Serves whatever the request's trailing path points at as one of $page's own files, exiting if it does and returning otherwise.
- serveFrom Serves what the request path was recorded as for one owner - a rendered image variant, or the stored file itself when the row has no options - and returns if nothing was.
- serve Serves a public generic (non-image) file - Cache-Control depends on size, so one oversized file can't crowd out a client's cache with something huge.
- sendFile Shared streaming primitive - variant(), serve(), and the admin preview route all send through this.
Clearing 3
- clearVariants Wipes every variant of a specific file, the cached renders and the public mirrors, forcing fresh generation on next request.
- clearPublic Deletes the public mirrors under a page URL ("blog/post" and everything below it, '' for the whole site) and, unless $rows is false, forgets the rows recorded for them; the whole site's rows are never forgotten.
- clearOwner Forgets every URL an owner's files were exposed at and wipes their public mirrors - for an owner that is going away.
Maintenance 2
- rebuildIndexes Writes an index file for any real file missing one, across every page directory - $subtree scopes the scan to one page and its descendants.
- rebuild Sweeps the public mirror, deleting anything that isn't a still-current image variant - the only kind of file PageFiles ever writes into public/ (see PageImage::transform()/PageFiles::variant()); a plain PageFile/PageImage url() has no physical mirror at all and is always served live through PHP. public/ is exclusively CMS-managed territory - the build pipeline writes into real page folders (site/pages/assets/, phlat/addons/admin/pages/assets/), not here - so index.php aside, anything found in public/ that isn't a validated, current variant is deleted outright, regardless of where it lives.
Variants
$pageFiles->setVariant(string $path, string $original, array $options, string $pageUuid): void
Records a URL a template has asked for, keyed by its public request path: a lazily-rendered image variant, or - with empty $options - the file itself.
Parameters (4)
| $path | string | |
| $original | string | |
| $options | array | |
| $pageUuid | string |
phlat/src/Files/PageFiles.php:77
$pageFiles->getVariant(string $path): ?array
Returns ['original' => string, 'options' => array, 'pageUuid' => string] for a variant's public request path, or null.
Parameters (1)
| $path | string |
Returns ?array
phlat/src/Files/PageFiles.php:96
$pageFiles->allVariants(): array
Returns every recorded image variant, keyed by public request path - used by PageFiles::rebuild() to validate the public mirror against live source files instead of trusting whatever's on disk.
Returns array
phlat/src/Files/PageFiles.php:112
Paths
$pageFiles->actualPath(string $pageUuid, string $filename): ?string
Absolute path to the original file in its page directory, or null if the page is unresolvable.
Parameters (2)
| $pageUuid | string | |
| $filename | string |
Returns ?string
phlat/src/Files/PageFiles.php:148
$pageFiles->variantDir(string $pageUuid): string
Returns the thumbnail cache directory for a page UUID.
Parameters (1)
| $pageUuid | string |
Returns string
phlat/src/Files/PageFiles.php:186
$pageFiles->publicPath(string $pageUuid, string $filename): ?string
Returns the public-mirror path for a file, or null if the owner is unresolvable.
Parameters (2)
| $pageUuid | string | |
| $filename | string |
Returns ?string
phlat/src/Files/PageFiles.php:192
$pageFiles->ownerUrl(string $pageUuid): ?string
The URL folder (trimmed, '' for the root page) an owner's public files nest under, or null if the owner is unresolvable.
Parameters (1)
| $pageUuid | string |
Returns ?string
phlat/src/Files/PageFiles.php:211
$pageFiles->usersPageUrl(): ?string
Resolves the admin users page's current URL (trimmed), or null if the admin addon isn't mounted - the fixed "parent" every user-owned file nests under.
Returns ?string
phlat/src/Files/PageFiles.php:225
Files
metaPath
staticPageFiles::metaPath(string $path): string
A file's metadata sits beside it as `_{name}.json`; a leading `_` is never a name an author can give, so it can't be a file.
Parameters (1)
| $path | string |
Returns string
phlat/src/Files/PageFiles.php:243
$pageFiles->meta(string $path): array
A file's metadata from its `_{filename}.json`, with `created` filled in from the file when missing.
Parameters (1)
| $path | string |
Returns array
phlat/src/Files/PageFiles.php:249
$pageFiles->store(string $sourcePath, string $name, string $pageUuid, array $options = []): PageFile
Stores a file on disk in its page directory and writes metadata.
Parameters (4)
| $sourcePath | string | |
| $name | string | |
| $pageUuid | string | |
| $options | array = [] |
Returns PageFile
phlat/src/Files/PageFiles.php:275
$pageFiles->delete(string $pageUuid, string $filename): void
Deletes the file, its metadata, and any cached variants.
Parameters (2)
| $pageUuid | string | |
| $filename | string |
phlat/src/Files/PageFiles.php:351
$pageFiles->isPublic(string $pageUuid, string $filename): bool
True when a template has exposed the file, or any variant of it.
Parameters (2)
| $pageUuid | string | |
| $filename | string |
Returns bool
phlat/src/Files/PageFiles.php:369
$pageFiles->makePrivate(string $pageUuid, string $filename): void
Withdraws a file: forgets every URL it was exposed at and wipes its mirrored and cached variants.
Parameters (2)
| $pageUuid | string | |
| $filename | string |
phlat/src/Files/PageFiles.php:375
$pageFiles->forPage(string $pageUuid): array
Returns all PageFiles for a page by scanning its page directory for files with a `_{name}.json` beside them.
Parameters (1)
| $pageUuid | string |
Returns array
phlat/src/Files/PageFiles.php:382
Serving
variant
exits$pageFiles->variant(string $pageUuid, string $requestPath, string $original, array $options): never
Generates a registry-recorded image variant and serves it.
Parameters (4)
| $pageUuid | string | |
| $requestPath | string | |
| $original | string | |
| $options | array |
Returns never
phlat/src/Files/PageFiles.php:407
$pageFiles->serveRequest(Page $page, string $remainder): void
Serves whatever the request's trailing path points at as one of $page's own files, exiting if it does and returning otherwise.
Parameters (2)
| $page | Page | |
| $remainder | string |
phlat/src/Files/PageFiles.php:438
$pageFiles->serveFrom(string $ownerUuid): void
Serves what the request path was recorded as for one owner - a rendered image variant, or the stored file itself when the row has no options - and returns if nothing was.
Parameters (1)
| $ownerUuid | string |
phlat/src/Files/PageFiles.php:445
serve
exits$pageFiles->serve(PageFile $file): never
Serves a public generic (non-image) file - Cache-Control depends on size, so one oversized file can't crowd out a client's cache with something huge.
Parameters (1)
| $file | PageFile |
Returns never
phlat/src/Files/PageFiles.php:461
sendFile
exits$pageFiles->sendFile(string $path, string $mime, string $cacheControl): never
Shared streaming primitive - variant(), serve(), and the admin preview route all send through this.
Parameters (3)
| $path | string | |
| $mime | string | |
| $cacheControl | string |
Returns never
phlat/src/Files/PageFiles.php:475
Clearing
$pageFiles->clearVariants(string $pageUuid, string $filename): void
Wipes every variant of a specific file, the cached renders and the public mirrors, forcing fresh generation on next request.
Parameters (2)
| $pageUuid | string | |
| $filename | string |
phlat/src/Files/PageFiles.php:512
$pageFiles->clearPublic(string $url, bool $rows = true): void
Deletes the public mirrors under a page URL ("blog/post" and everything below it, '' for the whole site) and, unless $rows is false, forgets the rows recorded for them; the whole site's rows are never forgotten.
Parameters (2)
| $url | string | |
| $rows | bool = true |
phlat/src/Files/PageFiles.php:537
$pageFiles->clearOwner(string $owner): void
Forgets every URL an owner's files were exposed at and wipes their public mirrors - for an owner that is going away.
Parameters (1)
| $owner | string |
phlat/src/Files/PageFiles.php:556
Maintenance
$pageFiles->rebuildIndexes(?string $subtree = null): void
Writes an index file for any real file missing one, across every page directory - $subtree scopes the scan to one page and its descendants.
Parameters (1)
| $subtree | ?string = null |
phlat/src/Files/PageFiles.php:568
$pageFiles->rebuild(): void
Sweeps the public mirror, deleting anything that isn't a still-current image variant - the only kind of file PageFiles ever writes into public/ (see PageImage::transform()/PageFiles::variant()); a plain PageFile/PageImage url() has no physical mirror at all and is always served live through PHP. public/ is exclusively CMS-managed territory - the build pipeline writes into real page folders (site/pages/assets/, phlat/addons/admin/pages/assets/), not here - so index.php aside, anything found in public/ that isn't a validated, current variant is deleted outright, regardless of where it lives.
phlat/src/Files/PageFiles.php:601