Repository navigation
Internals 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.
use vfs\transient\enums\ETransientType;
use vfs\transient\interfaces\ITransientStorageEntry;class TransientStorageEntry implements ITransientStorageEntryDeclarations 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 | 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 |
public function __construct(string $name, string $path)| 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();
}public function refresh(): selfState 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;
}public function loadContent(): selfState 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;
}public function write(string|array $content): self| 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();
}public function delete(): boolReturn 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;
}public function getName(): stringReturn expressions (including local callbacks): $this->name.
Implementation, validation guards and interaction order
public function getName(): string
{
return $this->name;
}public function getPath(): stringReturn expressions (including local callbacks): $this->path.
Implementation, validation guards and interaction order
public function getPath(): string
{
return $this->path;
}public function getLastModified(): intReturn expressions (including local callbacks): $this->lastModified.
Implementation, validation guards and interaction order
public function getLastModified(): int
{
return $this->lastModified;
}public function __toString(): stringReturn expressions (including local callbacks): $this->path.
Implementation, validation guards and interaction order
public function __toString(): string
{
return $this->path;
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes