Skip to content

Internals Vfs Resource ResourceBuilder

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

vfs\resource\ResourceBuilder

Framework Internals · Subsystem overview · Developer guide

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

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

ResourceBuilder

Declaration and architectural role

class ResourceBuilder

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
Constructor-promoted public function __construct(private string $path = PACKAGES) Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(private string $path = PACKAGES)
build public function build(): array
directoryIterator public static function directoryIterator(string $path, bool $recursive = false): array
scan private static function scan(string $path, bool $recursive, array $ancestors): array

__construct

Source line 7

public function __construct(private string $path = PACKAGES);

Parameters

Parameter Type, modifiers and default Purpose
$path private string $path = PACKAGES Filesystem or route path as defined by the owning component; no universal path normalization is implied.

Concrete no-op/default hook: this method performs no work. Override it where the lifecycle or extension contract calls for behavior.

build

Source line 8

public function build(): array

Return expressions (including local callbacks): self::directoryIterator($this->path, true).

Implementation, validation guards and interaction order
public function build(): array { return self::directoryIterator($this->path, true); }

directoryIterator

Source line 10

public static function directoryIterator(string $path, bool $recursive = false): array

Parameters

Parameter Type, modifiers and default Purpose
$path string $path Filesystem or route path as defined by the owning component; no universal path normalization is implied.
$recursive bool $recursive = false Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): self::scan($path, $recursive, []).

Implementation, validation guards and interaction order
public static function directoryIterator(string $path, bool $recursive = false): array
    {
        return self::scan($path, $recursive, []);
    }

scan

Source line 15

private static function scan(string $path, bool $recursive, array $ancestors): array

Parameters

Parameter Type, modifiers and default Purpose
$path string $path Filesystem or route path as defined by the owning component; no universal path normalization is implied.
$recursive bool $recursive Operation input; the exact use, validation and propagation are shown in the implementation trace.
$ancestors array $ancestors Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): []; $names; $result.

Explicit exceptions: exceptions\ResourceException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.

Implementation, validation guards and interaction order
private static function scan(string $path, bool $recursive, array $ancestors): array
    {
        if (!is_dir($path)) return [];
        $real = realpath($path);
        if ($real === false || isset($ancestors[$real])) return [];
        $ancestors[$real] = true;
        $names = @scandir($path);
        if ($names === false) throw new exceptions\ResourceException("Cannot scan resource directory: {$path}");
        $names = array_values(array_diff($names, ['.', '..']));
        if (!$recursive) return $names;
        $result = [];
        foreach ($names as $name) {
            $file = $path . DIRECTORY_SEPARATOR . $name;
            if (is_dir($file)) {
                // Descendant directory links are excluded from maps and cache watches.
                if (!is_link($file)) $result[$name] = self::scan($file, true, $ancestors);
            } elseif (is_file($file)) $result[$name] = $file;
        }
        return $result;
    }

Clone this wiki locally