Repository navigation
Internals Vfs Resource Resource
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/vfs/resource/Resource.php · Snapshot 8411f4287706.
VFS includes package resource lookup, database-backed file metadata, filesystem collaborators, transient pools and persistent PHP-array caches.
use vfs\resource\event\ContextRequestEvent;
use vfs\resource\exceptions\ResourceException;class ResourceDeclarations 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 |
|---|---|---|
| $context | public string $context; |
Used by __construct(), parseAlias(). |
| $map | private array $map = []; |
Used by buildResourceMap(), getResourceMap(), get(). |
| $path | private string $path; |
Used by __construct(), buildResourceMap(), get(). |
| Constructor-promoted | public function __construct(string $context = '' |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct(string $context = '', string $path = PACKAGES) |
| buildResourceMap | public function buildResourceMap(): self |
| getResourceMap | public function getResourceMap(): array |
| get | public function get(string $alias, bool $must = false): ?string |
| findInArray | private function findInArray(array $array, string $name): ?string |
| parseAlias | private function parseAlias(string $alias): ?array |
public function __construct(string $context = '', string $path = PACKAGES)| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$context |
string $context = '' |
Package context object or package name according to the declared type. |
$path |
string $path = PACKAGES |
Filesystem or route path as defined by the owning component; no universal path normalization is implied. |
State writes: $this->context, $this->path.
Explicit exceptions: ResourceException. 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 __construct(string $context = '', string $path = PACKAGES)
{
if ($context === '') {
global $eventDispatcher;
if (!isset($eventDispatcher)) throw new ResourceException('No resource context dispatcher is available.');
$event = new ContextRequestEvent();
$eventDispatcher->dispatch($event);
$context = $event->context ?? '';
if ($context === '') throw new ResourceException('No resource context was supplied.');
}
$this->context = $context;
$this->path = rtrim($path, DIRECTORY_SEPARATOR);
}public function buildResourceMap(): selfState writes: $this->map, $this->map[$package].
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function buildResourceMap(): self
{
$this->map = [];
foreach (ResourceBuilder::directoryIterator($this->path) as $package) {
$directory = $this->path . DIRECTORY_SEPARATOR . $package;
if (!is_dir($directory)) continue;
$map = [$package => (new ResourceBuilder($directory))->build()];
$this->map[$package] = $map[$package];
ResourceCache::cache($package, [$directory], $map, $this->path);
}
return $this;
}public function getResourceMap(): arrayReturn expressions (including local callbacks): $this->map.
Implementation, validation guards and interaction order
public function getResourceMap(): array { return $this->map; }public function get(string $alias, bool $must = false): ?string| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$alias |
string $alias |
Resource alias or route metadata alias according to this component. |
$must |
bool $must = false |
When true, a missing required resource is raised as a failure instead of a nullable result. |
Resolve filename, relative/path, or Package:relative/path. Required resources throw when missing.
State writes: $this->map.
Return expressions (including local callbacks): $found.
Explicit exceptions: ResourceException. The guards in the implementation below show when each is raised; exceptions from collaborators also propagate unless caught.
Implementation, validation guards and interaction order
/** Resolve filename, relative/path, or Package:relative/path. Required resources throw when missing. */
public function get(string $alias, bool $must = false): ?string
{
$parts = $this->parseAlias($alias);
$found = null;
if ($parts !== null) {
[$package, $relative] = $parts;
$cached = ResourceCache::get($package, $this->path);
if (is_array($cached)) $this->map = $cached;
else $this->buildResourceMap();
$map = $this->map[$package] ?? [];
if (!str_contains($relative, '/')) $found = $this->findInArray($map, $relative);
else {
$node = $map;
foreach (explode('/', $relative) as $segment) {
if (!is_array($node) || !array_key_exists($segment, $node)) { $node = null; break; }
$node = $node[$segment];
}
if (is_string($node)) $found = $node;
}
if ($found !== null && !is_file($found)) $found = null;
}
if ($found === null && $must) throw new ResourceException("Resource not found: {$alias}");
return $found;
}private function findInArray(array $array, string $name): ?string| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$array |
array $array |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$name |
string $name |
Named key/label selected by this API; its exact scope is shown by the implementation trace. |
Return expressions (including local callbacks): $array[$name]; $found; null.
Implementation, validation guards and interaction order
private function findInArray(array $array, string $name): ?string
{
if (isset($array[$name]) && is_string($array[$name])) return $array[$name];
foreach ($array as $item) {
if (is_array($item)) {
$found = $this->findInArray($item, $name);
if ($found !== null) return $found;
}
}
return null;
}private function parseAlias(string $alias): ?array| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$alias |
string $alias |
Resource alias or route metadata alias according to this component. |
Return expressions (including local callbacks): null; [$package, $alias].
Implementation, validation guards and interaction order
private function parseAlias(string $alias): ?array
{
$package = $this->context;
if (str_contains($alias, ':')) {
[$package, $alias] = explode(':', $alias, 2);
$alias = ltrim($alias, '/');
}
if ($package === '' || str_contains($package, '/') || str_contains($package, '\\')
|| $package === '.' || $package === '..' || str_contains($package, "\0")) return null;
if ($alias === '' || str_contains($alias, '\\') || str_contains($alias, "\0")) return null;
foreach (explode('/', $alias) as $segment) {
if ($segment === '' || $segment === '.' || $segment === '..') return null;
}
return [$package, $alias];
}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