Repository navigation
Internals Bootstrap Controllers StorageController
Framework Internals · Subsystem overview · Developer guide
Source: bootstrap/controllers/StorageController.php · Snapshot 8411f4287706.
Controllers extend View and receive package context, paths and the dispatcher from their runtime or object factory. Route execution selects an action method.
use controller\Controller;
use response\Response;
use vfs\resource\PublicResource;
use vfs\storage\StorageAccess;
use vfs\storage\StorageAccessDenied;
use vfs\storage\StorageRepository;class StorageController extends ControllerDeclarations 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 |
|---|---|---|
| $controllerName | public string $controllerName = 'DefaultStorageController'; |
Declared extension/state field; no own method directly consumes it in this source file. |
| Method | Signature |
|---|---|
| index | public function index(array|string $params): Response |
| Resource | public function Resource(array|string $params): Response |
| fileResponse | private function fileResponse(string $path): Response |
public function index(array|string $params): Response| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$params |
array|string $params |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): Response::make(404); Response::make(403); $this->fileResponse($path).
Failure handling catches \OutOfBoundsException, StorageAccessDenied.
Implementation, validation guards and interaction order
public function index(array|string $params): Response
{
if (!is_array($params) || !isset($params['id']) || !ctype_digit((string) $params['id'])) return Response::make(404);
try {
// Always hydrate current metadata and authorize before serving, including database cache hits.
$entry = (new StorageRepository())->fetchById((int) $params['id']);
StorageAccess::authorize($entry);
} catch (\OutOfBoundsException $e) {
return Response::make(404);
} catch (StorageAccessDenied $e) {
return Response::make(403);
}
$path = $entry->getPath();
if (!is_file($path) || !is_readable($path)) return Response::make(404);
return $this->fileResponse($path);
}public function Resource(array|string $params): Response| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$params |
array|string $params |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): Response::make(404); $this->fileResponse($path).
Implementation, validation guards and interaction order
public function Resource(array|string $params): Response
{
if (!is_array($params)) return Response::make(404);
$package = $params['package'] ?? 'System';
if (!is_string($package) || !preg_match('/^[a-zA-Z0-9_.-]+$/D', $package) || $package === '.' || $package === '..') return Response::make(404);
$segments = [];
for ($i = 0; isset($params['resource' . $i]); $i++) $segments[] = rawurldecode($params['resource' . $i]);
$segments[] = rawurldecode($params['file'] ?? '');
$relative = implode('/', $segments);
// Resolve the exact URL path; filename-only recursive lookup is reserved for internal callers.
$directory = rtrim(PACKAGES, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $package;
$path = $directory . DIRECTORY_SEPARATOR . $relative;
foreach (explode('/', $relative) as $segment) {
if ($segment === '' || $segment === '.' || $segment === '..' || str_contains($segment, '\\') || str_contains($segment, "\0")) return Response::make(404);
}
if (!PublicResource::allows($package, $path)) return Response::make(404);
return $this->fileResponse($path);
}private function fileResponse(string $path): Response| 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): $response.
External effects include header.
Implementation, validation guards and interaction order
private function fileResponse(string $path): Response
{
$response = Response::make(200)->file($path)->header('X-Content-Type-Options', 'nosniff');
// Unknown extensions are binary files, regardless of the request Accept header.
if ((new \response\resolvers\MimeResolver())->fromPath($path) === null) $response->asFile();
return $response;
}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