HTTP Static Provider
Static provider exist to serve files without execution of application code.
Installation
Requirements:
PHP ^8.4
Usage
Static adapters exist to serve files without execution of application code.
Filesystem
To return static files from the filesystem, you can use specific Boson\Component\Http\Static\FilesystemStaticProvider
static adapter.
use Boson\Application;
use Boson\ApplicationCreateInfo;
use Boson\Component\Http\Static\FilesystemStaticProvider;
use Boson\WebView\Api\Schemes\Event\SchemeRequestReceived;
// Create an application
$app = new Application(new ApplicationCreateInfo(
schemes: ['static'],
));
// Create static files adapter
$static = new FilesystemStaticProvider([__DIR__ . '/public']);
$app->on(function (SchemeRequestReceived $e) use ($static): void {
// Lookup static file and create response in
// case of given file is available.
$e->response = $static->findFileByRequest($e->request);
if ($e->response !== null) {
return;
}
// Do something else...
});
$app->webview->url = 'static://localhost/example/image.png';
13 June 2025