Skip to content

Internals Vfs Resource PublicResource

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

vfs\resource\PublicResource

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/vfs/resource/PublicResource.php · Snapshot 8411f4287706.

VFS includes package resource lookup, database-backed file metadata, filesystem collaborators, transient pools and persistent PHP-array caches.

PublicResource

Declaration and architectural role

final class PublicResource

Source description (behavioral corrections are recorded in Known discrepancies):

HTTP access policy; internal Resource lookup intentionally includes framework source files.

Constants, enum cases, traits and properties

Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.

Member Declaration Purpose or source contract
const EXTENSIONS private const EXTENSIONS = ['json', 'txt', 'xml', 'html', 'htm', 'css', 'js', 'mjs', 'png', 'jpg', 'jpeg', 'gif', 'webp', 'svg', 'ico', 'bmp', 'avif', 'tiff', 'mp4', 'webm', 'ogv', 'mov', 'mp3', 'wav', 'ogg', 'oga', 'aac', 'flac', 'm4a', 'weba', 'woff', 'woff2', 'ttf', 'otf', 'eot', 'pdf']; State or definition consumed by the methods below; reads and writes are preserved in their implementation traces.
const DIRECTORIES private const DIRECTORIES = ['assets', 'public', 'views/assets', 'data', 'css', 'js', 'images', 'fonts', 'videos', 'audio']; State or definition consumed by the methods below; reads and writes are preserved in their implementation traces.

Method index

Method Signature
allows public static function allows(string $package, string $path, string $root = PACKAGES): bool

allows

Source line 13

public static function allows(string $package, string $path, string $root = PACKAGES): bool

Parameters

Parameter Type, modifiers and default Purpose
$package string $package Package identifier or InstalledPackage metadata as indicated by the declared type.
$path string $path Filesystem or route path as defined by the owning component; no universal path normalization is implied.
$root string $root = PACKAGES Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): false; true.

Implementation, validation guards and interaction order
public static function allows(string $package, string $path, string $root = PACKAGES): bool
    {
        $directory = realpath(rtrim($root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $package);
        $file = realpath($path);
        if ($directory === false || $file === false || !is_file($file) || !is_readable($file)
            || !str_starts_with($file, $directory . DIRECTORY_SEPARATOR)) return false;
        $relative = str_replace(DIRECTORY_SEPARATOR, '/', substr($file, strlen($directory) + 1));
        foreach (explode('/', $relative) as $segment) if (str_starts_with($segment, '.')) return false;
        if (!in_array(strtolower(pathinfo($file, PATHINFO_EXTENSION)), self::EXTENSIONS, true)) return false;
        foreach (self::DIRECTORIES as $allowed) {
            if (str_starts_with($relative, $allowed . '/')) return true;
        }
        return false;
    }

Clone this wiki locally