Bindings API
You can register custom PHP functions to call them from the client.
The API is available in the WebView::$bindings
property.
$app = new Boson\Application();
$app->webview->bindings; // Access to Bindings API
Binding
You can create a function that can be called directly from WebView.
$app = new Boson\Application();
$app->webview->bindings->bind('foo', function () {
var_dump('Executed!');
});
Also, don't forget that PHP has a simple way to pass functions using first class callable syntax. Thus, a simple registration of the var_dump()
function looks like this:
$app = new Boson\Application();
$app->webview->bind('var_dump', var_dump(...));
Custom Context
You may have noticed that functions are registered globally, which is not always convenient.
To register functions in a context, you can use the dot-syntax, which allows you to register a function in a specific JavaScript context.
$app = new Boson\Application();
$app->webview->bind('example.some', $example->some(...));
$app->webview->bind('example.any', $example->any(...));
Access to such functions from the client side is also done through a dot.
example.some('hello');
example.any('world');
14 May 2025