Skip to content

Internals Vfs Transient TransientStorageEntry

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

vfs\transient\TransientStorageEntry

Framework Internals · Subsystem overview · Developer guide

Source: awt_src/classes/vfs/transient/TransientStorageEntry.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\ITransientStorageEntry;

TransientStorageEntry

Declaration and architectural role

class TransientStorageEntry implements ITransientStorageEntry

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
$name public string $name; Used by __construct(), getName().
$path public string $path; Used by __construct(), refresh(), loadContent(), write(), delete(), getPath(), __toString().
$content public string|array|null $content = null; Used by refresh(), loadContent(), write().
$lastModified public int $lastModified = 0; Used by refresh(), getLastModified().
$type public ETransientType $type = ETransientType::FILE; Used by refresh(), loadContent().
$size public int $size = 0; Used by refresh().
Constructor-promoted public function __construct(string $name Initialized from the constructor argument; default expression is evaluated when the argument is omitted.

Method index

Method Signature
__construct public function __construct(string $name, string $path)
refresh public function refresh(): self
loadContent public function loadContent(): self
write public function write(string|array $content): self
delete public function delete(): bool
getName public function getName(): string
getPath public function getPath(): string
getLastModified public function getLastModified(): int
__toString public function __toString(): string

__construct

Source line 17

public function __construct(string $name, string $path)

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.
$path string $path Filesystem or route path as defined by the owning component; no universal path normalization is implied.

State writes: $this->name, $this->path.

Implementation, validation guards and interaction order
public function __construct(string $name, string $path)
    {
        $this->name = $name;
        $this->path = $path;

        $this->refresh();
    }

refresh

Source line 25

public function refresh(): self

State writes: $this->size, $this->lastModified, $this->content, $this->type.

Return expressions (including local callbacks): $this.

Implementation, validation guards and interaction order
public function refresh(): self
    {
        clearstatcache(true, $this->path);
        if (!is_file($this->path)) {
            $this->size = 0;
            $this->lastModified = 0;
            $this->content = null;
            return $this;
        }

        $this->type = ETransientType::fromPath($this->path);
        $this->size = filesize($this->path);
        $this->lastModified = filemtime($this->path);

        return $this;
    }

loadContent

Source line 42

public function loadContent(): self

State writes: $this->content.

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 include.

Implementation, validation guards and interaction order
public function loadContent(): self
    {
        $this->refresh();
        if (!is_file($this->path)) return $this;

        if (
            $this->type === ETransientType::FILE ||
            $this->type === ETransientType::TXT ||
            $this->type === ETransientType::HTML ||
            $this->type === ETransientType::JSON ||
            $this->type === ETransientType::XML ||
            $this->type === ETransientType::JS
        ) {
            $content = @file_get_contents($this->path);
            if ($content === false) throw new \RuntimeException("Cannot read transient file: {$this->path}");
            $this->content = $content;
            return $this;
        }

        if (
            $this->type === ETransientType::CACHE ||
            $this->type === ETransientType::PHP
        ) {
            $this->content = include $this->path;
        }

        return $this;
    }

write

Source line 71

public function write(string|array $content): self

Parameters

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

State writes: $this->content.

Return expressions (including local callbacks): " . var_export($content, true) . "; $this->refresh().

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, unlink.

Implementation, validation guards and interaction order
public function write(string|array $content): self
    {
        $data = is_array($content)
            ? (ETransientType::fromPath($this->path) === ETransientType::JSON
                ? json_encode($content, JSON_THROW_ON_ERROR) : "<?php return " . var_export($content, true) . ";")
            : $content;
        $directory = dirname($this->path);
        $temporary = $directory . DIRECTORY_SEPARATOR . '.write-' . bin2hex(random_bytes(16));
        $handle = @fopen($temporary, 'xb');
        if ($handle === false) throw new \RuntimeException("Cannot create temporary file in {$directory}");
        try {
            $offset = 0;
            $length = strlen($data);
            while ($offset < $length) {
                $written = @fwrite($handle, substr($data, $offset));
                if ($written === false || $written === 0) throw new \RuntimeException("Cannot write file: {$this->path}");
                $offset += $written;
            }
            if (!@fflush($handle)) throw new \RuntimeException("Cannot flush file: {$this->path}");
            fclose($handle);
            $handle = null;
            if (!@rename($temporary, $this->path)) throw new \RuntimeException("Cannot replace file: {$this->path}");
            if (function_exists('opcache_invalidate')) opcache_invalidate($this->path, true);
        } finally {
            if (is_resource($handle)) fclose($handle);
            if (is_file($temporary)) unlink($temporary);
        }
        $this->content = $content;

        return $this->refresh();
    }

delete

Source line 103

public function delete(): bool

Return expressions (including local callbacks): $deleted.

External effects include unlink.

Implementation, validation guards and interaction order
public function delete(): bool
    {
        clearstatcache(true, $this->path);
        $deleted = (file_exists($this->path) || is_link($this->path)) && @unlink($this->path);
        if ($deleted && function_exists('opcache_invalidate')) opcache_invalidate($this->path, true);
        return $deleted;
    }

getName

Source line 111

public function getName(): string

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

Implementation, validation guards and interaction order
public function getName(): string
    {
        return $this->name;
    }

getPath

Source line 116

public function getPath(): string

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

Implementation, validation guards and interaction order
public function getPath(): string
    {
        return $this->path;
    }

getLastModified

Source line 121

public function getLastModified(): int

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

Implementation, validation guards and interaction order
public function getLastModified(): int
    {
        return $this->lastModified;
    }

__toString

Source line 126

public function __toString(): string

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

Implementation, validation guards and interaction order
public function __toString(): string
    {
        return $this->path;
    }

Related types

Clone this wiki locally