Repository navigation
Internals 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.
use vfs\transient\enums\ETransientType;
use vfs\transient\interfaces\ITransientStorage;
use vfs\transient\interfaces\ITransientStorageEntry;class TransientStorage implements ITransientStorageDeclarations 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 | 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 |
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;
}public function setPool(string $pool): self| 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;
}public function setSubPool(string $subPool): self| 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;
}public function getFile(string $name): ?ITransientStorageEntry| 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);
}public function createFile(
string $name,
ETransientType $type,
string|array $content
): ITransientStorageEntry| 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;
}public function deleteFile(ITransientStorageEntry $file): bool| 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();
}public function renameFile(
ITransientStorageEntry $file,
string $newName
): ITransientStorageEntry| 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);
}public function moveFile(
ITransientStorageEntry $file,
string $newPool
): ITransientStorageEntry| 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);
}public function copyFile(
ITransientStorageEntry $file,
string $newName
): ITransientStorageEntry| 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);
}public function getFiles(): arrayReturn expressions (including local callbacks): $this->scan($this->currentPool).
Implementation, validation guards and interaction order
public function getFiles(): array
{
return $this->scan($this->currentPool);
}private function scan(string $path): array| 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;
}private function assertRelativePath(string $name, bool $allowEmpty = false): void| 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.');
}
}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