Build Cross‑Platform Desktop Apps with Boson: PHP‑Powered WebView Runtime
Boson is a cross‑platform desktop‑application platform that embeds a Chromium‑based WebView engine and a modern PHP interpreter, letting developers create native‑like apps with familiar web technologies while avoiding heavy dependencies, separate GUI frameworks, or custom HTTP servers.
Introduction
Boson is a cross‑platform desktop‑application development platform that embeds a Chromium‑based WebView engine and a PHP interpreter directly into an executable, allowing developers to use familiar web stack (HTML, CSS, JavaScript, PHP) without learning platform‑specific languages.
Familiar stack – build UI with HTML/CSS and logic with PHP (and JavaScript) without learning a new language.
Stable rendering via Chromium on Windows, macOS and Linux.
Single‑code‑base changes sync automatically across platforms.
Self‑contained binaries simplify distribution; no extra runtimes required.
What Boson Is Not
It is not a GUI framework that dictates the look and feel of your app; you can use any front‑end stack such as React, Angular, Vue, Svelte, jQuery, or plain HTML/CSS. It does not start an HTTP server, nor does it rely on Node.js or heavyweight dependencies like Electron. Boson uses the system‑provided tools and keeps the binary size in the kilobyte range instead of hundreds of megabytes.
Boson also does not fork or reinvent PHP – it works with standard modern PHP without surprises.
Installation
Runtime
The runtime library is distributed as a Composer package. Install it with a single command: composer require boson-php/runtime After installation, include the Composer autoloader and create the application instance:
<?php
require __DIR__ . '/vendor/autoload.php';
$app = new Boson\Application();Compiler
The compiler is needed only during development to package the final executable. Install it as a development dependency: composer require boson-php/compiler --dev Environment requirements: PHP 8.4+ with the ext-ffi extension enabled.
Example: Using Twig Components
This example shows how to integrate Twig templates into a Boson WebComponent.
Install Twig: composer require twig/twig Create a Twig component class that extends WebComponent and implements a renderTwig method returning a Twig template string.
Implement an instantiator that injects the Twig environment when the component extends the base Twig component.
use Boson\WebView\Api\WebComponents\Instantiator\WebComponentInstantiatorInterface;
use Boson\WebView\Api\WebComponents\ReactiveContext;
use Boson\WebView\Api\WebView;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
final class TwigComponentInstantiator implements WebComponentInstantiatorInterface {
private Environment $twig;
public function __construct() {
$this->twig = new Environment(new ArrayLoader());
}
private function isTwigComponent(string $component): bool {
return \is_subclass_of($component, TwigComponent::class);
}
public function create(WebView $webview, ReactiveContext $context): object {
$component = $context->component;
if ($this->isTwigComponent($component)) {
return new $component($this->twig, $context, $webview);
}
return new $component($context, $webview);
}
}Register the instantiator in the WebView configuration:
$webComponentsConfig = new WebComponentsCreateInfo(
instantiator: new TwigComponentInstantiator(),
);
$applicationConfig = new ApplicationCreateInfo(
window: new WindowCreateInfo(
webview: new WebViewCreateInfo(
webComponents: $webComponentsConfig,
),
),
);
$app = new Boson\Application($applicationConfig);Define and render the Twig component:
class MyTwigComponent extends TwigComponent {
protected array $items = [1, 2, 3];
protected function renderTwig(): string {
return <<<'twig'
<ul>
{% for item in items %}
<li>{{ item }}</li>
{% endfor %}
</ul>
twig;
}
}
$app->webview->defineComponent('my-list', MyTwigComponent::class);
$app->webview->html = '<my-list />';The component renders a simple list generated by Twig.
The resulting UI looks like the following screenshot:
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
