objects

PageFiles

Manages every file owned by a page/item/user - identified by owner UUID + filename - including its index, public mirror, and image variants.

A user has no page-tree URL of its own, so its files nest under the admin users page - see ResolvesUserUrl/usersPageUrl().

$pageFiles Phlat\Files\PageFiles 33 methods
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.
Show

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 6

  • variant Generates a registry-recorded image variant and serves it.
  • withdraw Deletes the public mirrors under a page URL ('' for the whole site) but keeps their rows, so each is served through PHP, behind the page's gate, until the page is public again.
  • 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 4

  • clearVariants Wipes the variant cache for a specific file, forcing fresh generation on next request.
  • clearPublic Forgets every image variant under a page URL ("blog/post" and everything below it): their recorded rows and their public mirrors.
  • clearOwner Forgets every URL an owner's files were exposed at and wipes their public mirrors - for an owner that is going away.
  • clearMirror Deletes the public mirror file and any mirrored variants for a file.

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.

A file is public exactly when a row names it, so this is the one place a file gains public visibility. $pageUuid is the same owner identity variant() resolves against, stored so PageFiles::rebuild() can validate/sweep variants against their real source file without parsing the path. Skips the write (and its fsync) when nothing changed, since transform() calls this on every render.

Parameters (4)
$path string
$original string
$options array
$pageUuid string
phlat/src/Files/PageFiles.php:74
$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:93
$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:109

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:145

own

$pageFiles->own(Page $page): void

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.

Page::virtual() calls it; nothing is stored.

Parameters (1)
$page Page
phlat/src/Files/PageFiles.php:152
$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:183
$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:189
$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.

A page is its own URL. A user has no page-tree URL, so its files nest under the admin users page as {user-uuid} (the framework's one shipped exception to "every routable URL is a page the site author created"), uuid-keyed so they survive a rename or move.

Parameters (1)
$pageUuid string

Returns ?string

phlat/src/Files/PageFiles.php:208
$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:222

Files

get

$pageFiles->get(string $pageUuid, string $filename): ?PageFile

Returns the PageFile/PageImage for a page UUID + filename, or null if its metadata does not exist

Parameters (2)
$pageUuid string
$filename string

Returns ?PageFile

phlat/src/Files/PageFiles.php:231

metaPath

static
PageFiles::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:240
$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:246
$pageFiles->build(string $actualPath, string $pageUuid, string $filename): PageFile

Builds the PageFile, PageImage or PageSvg the file's mime calls for.

Parameters (3)
$actualPath string
$pageUuid string
$filename string

Returns PageFile

phlat/src/Files/PageFiles.php:257
$pageFiles->buildImage(string $actualPath, string $pageUuid, string $filename): PageImage

Builds a PageImage, rejecting anything that isn't a resizable image.

Parameters (3)
$actualPath string
$pageUuid string
$filename string

Returns PageImage

phlat/src/Files/PageFiles.php:263
$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:272
$pageFiles->upload(string $tmpPath, string $name, string $pageUuid, array $options = []): PageFile

Stores file upload in page directory and writes metadata.

Parameters (4)
$tmpPath string
$name string
$pageUuid string
$options array = []

Returns PageFile

phlat/src/Files/PageFiles.php:278
$pageFiles->update(string $pageUuid, string $filename, array $changes): PageFile

Merges $changes into a file's metadata and returns the file.

Parameters (3)
$pageUuid string
$filename string
$changes array

Returns PageFile

phlat/src/Files/PageFiles.php:317
$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:349
$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:367
$pageFiles->makePrivate(string $pageUuid, string $filename): void

Withdraws a file: forgets every URL it was exposed at and wipes its mirrored and cached variants.

It is public again the next time a template asks for it.

Parameters (2)
$pageUuid string
$filename string
phlat/src/Files/PageFiles.php:373
$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:381

Serving

variant

exits
$pageFiles->variant(string $pageUuid, string $requestPath, string $original, array $options): never

Generates a registry-recorded image variant and serves it.

One anyone may open is written to its public path, so later requests hit it as a static file and never reach this method again; any other is kept in the owner's cache and served from here every time, behind the page's gate.

Parameters (4)
$pageUuid string
$requestPath string
$original string
$options array

Returns never

phlat/src/Files/PageFiles.php:406
$pageFiles->withdraw(string $url): void

Deletes the public mirrors under a page URL ('' for the whole site) but keeps their rows, so each is served through PHP, behind the page's gate, until the page is public again.

Parameters (1)
$url string
phlat/src/Files/PageFiles.php:433
$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.

A private file 404s here even if it physically exists, since only a URL a template asked for (url()/transform()) has a row to serve.

Parameters (2)
$page Page
$remainder string
phlat/src/Files/PageFiles.php:443
$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:450

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:466

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:477

Clearing

$pageFiles->clearVariants(string $pageUuid, string $filename): void

Wipes the variant cache for a specific file, forcing fresh generation on next request.

Parameters (2)
$pageUuid string
$filename string
phlat/src/Files/PageFiles.php:493
$pageFiles->clearPublic(string $url): void

Forgets every image variant under a page URL ("blog/post" and everything below it): their recorded rows and their public mirrors.

For a page that moved or went away - the mirrors would otherwise keep being served at the old URL, and rebuild() would keep whitelisting them because their source files are still public.

Parameters (1)
$url string
phlat/src/Files/PageFiles.php:511
$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.

Indexed by owner, unlike clearPublic()'s scan of a URL prefix.

Parameters (1)
$owner string
phlat/src/Files/PageFiles.php:530
$pageFiles->clearMirror(string $pageUuid, string $filename): void

Deletes the public mirror file and any mirrored variants for a file.

Parameters (2)
$pageUuid string
$filename string
phlat/src/Files/PageFiles.php:540

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:558
$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.

This is what actually catches debris left behind by removed code (e.g. the pre-variants-table eager-mirroring PageFile::url() used to do): it has no record anywhere, so it's never whitelisted, so it's swept the same as any orphan.

phlat/src/Files/PageFiles.php:591