Skip to content

Internals Vfs Transient TransientStorage

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

vfs\transient\TransientStorage

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/vfs/transient/TransientStorage.php · Snapshot 8411f4287706.

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

Imports and dependencies

use vfs\transient\enums\ETransientType;
use vfs\transient\interfaces\ITransientStorage;
use vfs\transient\interfaces\ITransientStorageEntry;

TransientStorage

Declaration and architectural role

class TransientStorage implements ITransientStorage

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
$currentPool private string $currentPool; Used by __construct(), setPool(), setSubPool(), getFile(), createFile(), copyFile(), getFiles().
$subPool private string $subPool; Used by __construct(), setPool(), setSubPool().
$basePool private string $basePool; Used by __construct(), setPool(), setSubPool().
$pools private readonly array $pools; Used by __construct(), setPool(), moveFile().

Method index

Method Signature
__construct public function __construct()
setPool public function setPool(string $pool): self
setSubPool public function setSubPool(string $subPool): self
getFile public function getFile(string $name): ?ITransientStorageEntry
createFile public function createFile( string $name, ETransientType $type, string|array $content ): ITransientStorageEntry
deleteFile public function deleteFile(ITransientStorageEntry $file): bool
renameFile public function renameFile( ITransientStorageEntry $file, string $newName ): ITransientStorageEntry
moveFile public function moveFile( ITransientStorageEntry $file, string $newPool ): ITransientStorageEntry
copyFile public function copyFile( ITransientStorageEntry $file, string $newName ): ITransientStorageEntry
getFiles public function getFiles(): array
scan private function scan(string $path): array
assertRelativePath private function assertRelativePath(string $name, bool $allowEmpty = false): void

__construct

Source line 16

public function __construct()

State writes: $this->pools, $this->subPool, $this->basePool, $this->currentPool.

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

External effects include mkdir.

Implementation, validation guards and interaction order
public function __construct()
    {
        $this->pools = [
            "cache" => DATA . "storage/framework/cache",
            "temp" => DATA . "storage/framework/temp",
        ];

        foreach ($this->pools as $pool) {
            if (!is_dir($pool) && !mkdir($pool, 0755, true) && !is_dir($pool)) {
                throw new \RuntimeException(sprintf('Directory "%s" was not created', $pool));
            }
        }

        $this->subPool = DIRECTORY_SEPARATOR;
        $this->basePool = $this->pools["cache"];
        $this->currentPool = $this->basePool . DIRECTORY_SEPARATOR;
    }

setPool

Source line 34

public function setPool(string $pool): self

Parameters

Parameter Type, modifiers and default Purpose
$pool string $pool Operation input; the exact use, validation and propagation are shown in the implementation trace.

State writes: $this->basePool, $this->currentPool, $this->subPool.

Return expressions (including local callbacks): $this.

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

Implementation, validation guards and interaction order
public function setPool(string $pool): self
    {
        if (!isset($this->pools[$pool])) throw new \InvalidArgumentException("Unknown transient pool: {$pool}");
        $this->basePool = $this->pools[$pool];
        $this->currentPool = $this->basePool . DIRECTORY_SEPARATOR;
        $this->subPool = '';
        return $this;
    }

setSubPool

Source line 43

public function setSubPool(string $subPool): self

Parameters

Parameter Type, modifiers and default Purpose
$subPool string $subPool Operation input; the exact use, validation and propagation are shown in the implementation trace.

State writes: $this->subPool, $this->currentPool.

Return expressions (including local callbacks): $this.

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

External effects include mkdir.

Implementation, validation guards and interaction order
public function setSubPool(string $subPool): self
    {
        $this->assertRelativePath($subPool, true);
        $this->subPool = DIRECTORY_SEPARATOR . trim($subPool, DIRECTORY_SEPARATOR);

        $path = $this->basePool . $this->subPool;

        if (!is_dir($path) && !mkdir($path, 0755, true) && !is_dir($path)) {
            throw new \RuntimeException(sprintf('Directory "%s" was not created', $path));
        }

        $this->currentPool = $path . DIRECTORY_SEPARATOR;

        return $this;
    }

getFile

Source line 59

public function getFile(string $name): ?ITransientStorageEntry

Parameters

Parameter Type, modifiers and default Purpose
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.

Return expressions (including local callbacks): null; new TransientStorageEntry($name, $path).

Implementation, validation guards and interaction order
public function getFile(string $name): ?ITransientStorageEntry
    {
        $this->assertRelativePath($name);
        $path = $this->currentPool . $name;

        if (!is_file($path)) {
            return null;
        }

        return new TransientStorageEntry($name, $path);
    }

createFile

Source line 71

public function createFile(
        string $name,
        ETransientType $type,
        string|array $content
    ): ITransientStorageEntry

Parameters

Parameter Type, modifiers and default Purpose
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.
$type ETransientType $type Expected class/type or enum selection according to the signature.
$content string|array $content Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): $entry.

Implementation, validation guards and interaction order
public function createFile(
        string $name,
        ETransientType $type,
        string|array $content
    ): ITransientStorageEntry {

        $this->assertRelativePath($name);
        $path = $this->currentPool . $name . "." . $type->value;

        $entry = new TransientStorageEntry($name, $path);
        $entry->write($content);

        return $entry;
    }

deleteFile

Source line 86

public function deleteFile(ITransientStorageEntry $file): bool

Parameters

Parameter Type, modifiers and default Purpose
$file ITransientStorageEntry $file Uploaded file array, file object or path according to the declared contract.

Return expressions (including local callbacks): $file->delete().

Implementation, validation guards and interaction order
public function deleteFile(ITransientStorageEntry $file): bool
    {
        return $file->delete();
    }

renameFile

Source line 91

public function renameFile(
        ITransientStorageEntry $file,
        string $newName
    ): ITransientStorageEntry

Parameters

Parameter Type, modifiers and default Purpose
$file ITransientStorageEntry $file Uploaded file array, file object or path according to the declared contract.
$newName string $newName Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): new TransientStorageEntry($newName, $newPath).

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

External effects include rename.

Implementation, validation guards and interaction order
public function renameFile(
        ITransientStorageEntry $file,
        string $newName
    ): ITransientStorageEntry {

        $this->assertRelativePath($newName);
        $newPath = dirname($file->getPath()) . DIRECTORY_SEPARATOR . $newName;

        if (!(new \vfs\storage\services\LocalFileSystemService())->move($file->getPath(), $newPath)) throw new \RuntimeException('Could not rename transient file.');

        return new TransientStorageEntry($newName, $newPath);
    }

moveFile

Source line 104

public function moveFile(
        ITransientStorageEntry $file,
        string $newPool
    ): ITransientStorageEntry

Parameters

Parameter Type, modifiers and default Purpose
$file ITransientStorageEntry $file Uploaded file array, file object or path according to the declared contract.
$newPool string $newPool Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): new TransientStorageEntry(basename($target), $target).

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

Implementation, validation guards and interaction order
public function moveFile(
        ITransientStorageEntry $file,
        string $newPool
    ): ITransientStorageEntry {

        if (!isset($this->pools[$newPool])) throw new \InvalidArgumentException("Unknown transient pool: {$newPool}");
        $target = $this->pools[$newPool] . DIRECTORY_SEPARATOR . basename($file->getPath());

        if (!(new \vfs\storage\services\LocalFileSystemService())->move($file->getPath(), $target)) throw new \RuntimeException('Could not move transient file.');

        return new TransientStorageEntry(basename($target), $target);
    }

copyFile

Source line 117

public function copyFile(
        ITransientStorageEntry $file,
        string $newName
    ): ITransientStorageEntry

Parameters

Parameter Type, modifiers and default Purpose
$file ITransientStorageEntry $file Uploaded file array, file object or path according to the declared contract.
$newName string $newName Operation input; the exact use, validation and propagation are shown in the implementation trace.

Return expressions (including local callbacks): new TransientStorageEntry($newName, $target).

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

External effects include copy.

Implementation, validation guards and interaction order
public function copyFile(
        ITransientStorageEntry $file,
        string $newName
    ): ITransientStorageEntry {

        $this->assertRelativePath($newName);
        $target = $this->currentPool . $newName;

        if (!(new \vfs\storage\services\LocalFileSystemService())->copy($file->getPath(), $target)) throw new \RuntimeException('Could not copy transient file.');

        return new TransientStorageEntry($newName, $target);
    }

getFiles

Source line 130

public function getFiles(): array

Return expressions (including local callbacks): $this->scan($this->currentPool).

Implementation, validation guards and interaction order
public function getFiles(): array
    {
        return $this->scan($this->currentPool);
    }

scan

Source line 135

private function scan(string $path): 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.

Return expressions (including local callbacks): $scannedFiles.

Explicit exceptions: \RuntimeException. 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 function scan(string $path): array
    {
        $scannedFiles = [];

        $names = scandir($path);
        if ($names === false) throw new \RuntimeException("Cannot scan transient directory: {$path}");
        $files = array_diff($names, ['.', '..']);

        foreach ($files as $file) {

            $full = $path . DIRECTORY_SEPARATOR . $file;

            if (is_dir($full) && !is_link($full)) {
                $scannedFiles = array_merge($scannedFiles, $this->scan($full));
            } elseif (is_file($full)) {
                $scannedFiles[] =
                    new TransientStorageEntry($file, $full);
            }
        }

        return $scannedFiles;
    }

assertRelativePath

Source line 158

private function assertRelativePath(string $name, bool $allowEmpty = false): void

Parameters

Parameter Type, modifiers and default Purpose
$name string $name Named key/label selected by this API; its exact scope is shown by the implementation trace.
$allowEmpty bool $allowEmpty = false Operation input; the exact use, validation and propagation are shown in the implementation trace.

Explicit exceptions: \InvalidArgumentException. 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 function assertRelativePath(string $name, bool $allowEmpty = false): void
    {
        if (($name === '' && !$allowEmpty) || str_contains($name, "\0") || str_contains($name, '\\')
            || str_starts_with($name, '/') || preg_match('/^[a-z]:/i', $name)) {
            throw new \InvalidArgumentException('Transient paths must be relative.');
        }
        foreach (explode('/', $name) as $part) {
            if ($part === '..' || $part === '.') throw new \InvalidArgumentException('Transient paths cannot contain traversal segments.');
        }
    }

Related types

Clone this wiki locally