Repository navigation
Internals Vfs Storage Strategies PackageOwnerStorageStrategy
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/vfs/storage/strategies/PackageOwnerStorageStrategy.php · Snapshot 8411f4287706.
VFS includes package resource lookup, database-backed file metadata, filesystem collaborators, transient pools and persistent PHP-array caches.
use database\DatabaseManager;
use vfs\storage\interfaces\IFileSystemService;
use vfs\storage\interfaces\IOwnerStorageStrategy;
use vfs\storage\interfaces\IStorageRepository;
use vfs\storage\enums\EOwnerType;
use vfs\storage\StorageEntry;class PackageOwnerStorageStrategy implements IOwnerStorageStrategySource description (behavioral corrections are recorded in Known discrepancies):
Class PackageOwnerStorageStrategy
Handles file registration for the PACKAGE owner type (OCP). Adding new EOwnerType strategies never requires touching StorageManager.
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 |
|---|---|---|
| const PACKAGES_DIR | private const PACKAGES_DIR = 'packages'; |
State or definition consumed by the methods below; reads and writes are preserved in their implementation traces. |
| Constructor-promoted | private readonly IFileSystemService $fileSystem |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Constructor-promoted | private readonly IStorageRepository $repository |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Constructor-promoted | private readonly string $storageBasePath |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct( private readonly IFileSystemService $fileSystem, private readonly IStorageRepository $repository, private readonly string $storageBasePath ) |
| supports | public function supports(): EOwnerType |
| register | public function register(StorageEntry $entry, string $ownerName): bool |
public function __construct(
private readonly IFileSystemService $fileSystem,
private readonly IStorageRepository $repository,
private readonly string $storageBasePath
);| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$fileSystem |
private readonly IFileSystemService $fileSystem |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$repository |
private readonly IStorageRepository $repository |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$storageBasePath |
private readonly string $storageBasePath |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Concrete no-op/default hook: this method performs no work. Override it where the lifecycle or extension contract calls for behavior.
public function supports(): EOwnerTypeReturn expressions (including local callbacks): EOwnerType::PACKAGE.
Implementation, validation guards and interaction order
public function supports(): EOwnerType
{
return EOwnerType::PACKAGE;
}public function register(StorageEntry $entry, string $ownerName): 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 |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): true.
Explicit exceptions: \InvalidArgumentException, \OutOfBoundsException, \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 register(StorageEntry $entry, string $ownerName): bool
{
if ($ownerName === '' || $ownerName === '.' || $ownerName === '..' || preg_match('/[\\\\\/\x00]/', $ownerName)) {
throw new \InvalidArgumentException('Owner name must be a single directory name.');
}
if ($entry->getOwnerId() === null) {
$rows = (new DatabaseManager())->table('awt_package')->select(['id'])->where(['name' => $ownerName])->get(1);
if ($rows === []) throw new \OutOfBoundsException("Package not found: {$ownerName}");
$entry->setOwnerId($rows[0]['id']);
}
$directory = rtrim($this->storageBasePath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR
. self::PACKAGES_DIR . DIRECTORY_SEPARATOR . $ownerName;
if (!$this->fileSystem->makeDirectory($directory)) throw new \RuntimeException("Could not create directory: {$directory}");
$oldPath = $entry->getPath();
$oldUrl = $entry->url;
$destination = \vfs\storage\FileName::unique($directory, $oldPath);
if (!$this->fileSystem->move($oldPath, $destination)) throw new \RuntimeException('Could not move storage file.');
try {
$entry->setPath($destination)->setSize($this->fileSystem->fileSize($destination))
->setLastModified($this->fileSystem->lastModified($destination));
$created = $this->repository->create($entry);
if ($created->id === null) throw new \RuntimeException('Failed to register storage entry.');
return true;
} catch (\Throwable $e) {
if (!$this->fileSystem->move($destination, $oldPath)) {
throw new \RuntimeException("Could not restore failed registration; file remains at {$destination}.", previous: $e);
}
$entry->setPath($oldPath);
$entry->url = $oldUrl;
throw $e;
}
}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