Repository navigation
Internals Vfs Storage StorageManager
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/vfs/storage/StorageManager.php · Snapshot 8411f4287706.
VFS includes package resource lookup, database-backed file metadata, filesystem collaborators, transient pools and persistent PHP-array caches.
use context\events\GetContextEvent;
use vfs\storage\interfaces\IFileSystemService;
use vfs\storage\interfaces\IOwnerStorageStrategy;
use vfs\storage\interfaces\IStorageManager;
use vfs\storage\interfaces\IStorageRepository;class StorageManager implements IStorageManagerDeclarations 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 |
|---|---|---|
| $strategies | private array $strategies = []; |
Used by registerStrategy(), registerLocal(). |
| Constructor-promoted | private readonly IStorageRepository $repository |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Constructor-promoted | private readonly IFileSystemService $fileSystem |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct( private readonly IStorageRepository $repository, private readonly IFileSystemService $fileSystem, array $strategies = [] ) |
| registerStrategy | public function registerStrategy(IOwnerStorageStrategy $strategy): void |
| get | public function get(int $id): StorageEntry |
| move | public function move(int $id, string $location): bool |
| rename | public function rename(int $id, string $name): bool |
| relocate | private function relocate(StorageEntry $entry, string $destination, ?string $name = null): bool |
| restore | private function restore(string $source, string $destination): void |
| delete | public function delete(int $id): bool |
| copy | public function copy(int $id): StorageEntry |
| registerLocal | public function registerLocal(StorageEntry $entry, ?string $ownerName = null): bool |
public function __construct(
private readonly IStorageRepository $repository,
private readonly IFileSystemService $fileSystem,
array $strategies = []
)| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$repository |
private readonly IStorageRepository $repository |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$fileSystem |
private readonly IFileSystemService $fileSystem |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$strategies |
array $strategies = [] |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Delegates to registerStrategy().
Implementation, validation guards and interaction order
public function __construct(
private readonly IStorageRepository $repository,
private readonly IFileSystemService $fileSystem,
array $strategies = []
) {
foreach ($strategies as $strategy) $this->registerStrategy($strategy);
}public function registerStrategy(IOwnerStorageStrategy $strategy): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$strategy |
IOwnerStorageStrategy $strategy |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->strategies[$strategy->supports()->value].
Implementation, validation guards and interaction order
public function registerStrategy(IOwnerStorageStrategy $strategy): void
{
$this->strategies[$strategy->supports()->value] = $strategy;
}public function get(int $id): StorageEntry| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$id |
int $id |
Record or runtime identifier selected by this operation. |
Return expressions (including local callbacks): $this->repository->fetchById($id).
Implementation, validation guards and interaction order
public function get(int $id): StorageEntry { return $this->repository->fetchById($id); }public function move(int $id, string $location): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$id |
int $id |
Record or runtime identifier selected by this operation. |
$location |
string $location |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): false; $this->relocate($entry, FileName::unique($location, $entry->getPath())).
Implementation, validation guards and interaction order
public function move(int $id, string $location): bool
{
$entry = $this->get($id);
if (!$this->fileSystem->makeDirectory($location)) return false;
return $this->relocate($entry, FileName::unique($location, $entry->getPath()));
}public function rename(int $id, string $name): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$id |
int $id |
Record or runtime identifier selected by this operation. |
$name |
string $name |
Named key/label selected by this API; its exact scope is shown by the implementation trace. |
Return expressions (including local callbacks): $this->relocate($entry, FileName::unique(dirname($entry->getPath()), $entry->getPath()), $name).
Implementation, validation guards and interaction order
public function rename(int $id, string $name): bool
{
$entry = $this->get($id);
return $this->relocate($entry, FileName::unique(dirname($entry->getPath()), $entry->getPath()), $name);
}private function relocate(StorageEntry $entry, string $destination, ?string $name = null): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$entry |
StorageEntry $entry |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$destination |
string $destination |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$name |
?string $name = null |
Named key/label selected by this API; its exact scope is shown by the implementation trace. |
Return expressions (including local callbacks): false; true.
Failure handling catches \Throwable.
Implementation, validation guards and interaction order
private function relocate(StorageEntry $entry, string $destination, ?string $name = null): bool
{
$oldPath = $entry->getPath();
$oldName = $entry->getName();
$oldUrl = $entry->url;
if (!$this->fileSystem->move($oldPath, $destination)) return false;
try {
$entry->setPath($destination);
if ($name !== null) {
$entry->setName($name);
if ($oldUrl === null || $oldUrl === '/storage/' . $entry->id . '/' . rawurlencode($oldName)
|| $oldUrl === '/storage/' . $entry->id . '/' . $oldName) $entry->setUrl();
}
if ($this->repository->update($entry)) return true;
} catch (\Throwable $e) {
$this->restore($destination, $oldPath);
$entry->setPath($oldPath)->setName($oldName);
$entry->url = $oldUrl;
throw $e;
}
$this->restore($destination, $oldPath);
$entry->setPath($oldPath)->setName($oldName);
$entry->url = $oldUrl;
return false;
}private function restore(string $source, string $destination): void| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$source |
string $source |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$destination |
string $destination |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
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 restore(string $source, string $destination): void
{
if (!$this->fileSystem->move($source, $destination)) {
throw new \RuntimeException("Could not restore file to {$destination}; file remains at {$source}.");
}
}public function delete(int $id): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$id |
int $id |
Record or runtime identifier selected by this operation. |
Return expressions (including local callbacks): false; true.
Explicit exceptions: \RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.
Failure handling catches \Throwable.
Implementation, validation guards and interaction order
public function delete(int $id): bool
{
$entry = $this->get($id);
$path = $entry->getPath();
$backup = FileName::unique(dirname($path), $path);
if (!$this->fileSystem->move($path, $backup)) return false;
try {
$deleted = $this->repository->delete($entry);
} catch (\Throwable $e) {
$this->restore($backup, $path);
throw $e;
}
if (!$deleted) { $this->restore($backup, $path); return false; }
if (!$this->fileSystem->delete($backup)) {
throw new \RuntimeException("Storage record deleted, but file cleanup failed: {$backup}");
}
return true;
}public function copy(int $id): StorageEntry| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$id |
int $id |
Record or runtime identifier selected by this operation. |
Return expressions (including local callbacks): $this->repository->create($copy).
Explicit exceptions: \RuntimeException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.
Failure handling catches \Throwable.
External effects include copy.
Implementation, validation guards and interaction order
public function copy(int $id): StorageEntry
{
$entry = $this->get($id);
$path = FileName::unique(dirname($entry->getPath()), $entry->getPath());
if (!$this->fileSystem->copy($entry->getPath(), $path)) throw new \RuntimeException('Could not copy storage file.');
try {
$copy = (new StorageEntry())->setPath($path)->setName('copy_' . $entry->getName())
->setSize($this->fileSystem->fileSize($path))->setLastModified($this->fileSystem->lastModified($path))
->setOwnerType($entry->getOwnerType())->setOwnerId($entry->getOwnerId())
->setMiddleware($entry->getMiddleware());
return $this->repository->create($copy);
} catch (\Throwable $e) {
if (!$this->fileSystem->delete($path)) throw new \RuntimeException("Could not clean up failed copy: {$path}", previous: $e);
throw $e;
}
}public function registerLocal(StorageEntry $entry, ?string $ownerName = null): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$entry |
StorageEntry $entry |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$ownerName |
?string $ownerName = null |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): $this->strategies[$ownerType->value]->register($entry, $ownerName).
Explicit exceptions: \RuntimeException, \LogicException. 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 registerLocal(StorageEntry $entry, ?string $ownerName = null): bool
{
$ownerType = $entry->getOwnerType();
if ($ownerType === null || !isset($this->strategies[$ownerType->value])) {
throw new \RuntimeException('No storage strategy registered for owner type: ' . ($ownerType?->value ?? 'null'));
}
if ($ownerName === null) {
global $eventDispatcher;
if (!isset($eventDispatcher)) throw new \LogicException('Supply an owner name when no context dispatcher is available.');
$event = new GetContextEvent();
$eventDispatcher->dispatch($event);
$context = $event->getContext();
$ownerName = $context->contextName;
if ($entry->getOwnerId() === null) $entry->setOwnerId($context->contextId);
}
return $this->strategies[$ownerType->value]->register($entry, $ownerName);
}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